Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor and DRYer code #821

Merged
merged 15 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions src/components/Jam.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ import ToggleSwitch from './ToggleSwitch'
import Sprite from './Sprite'
import Balance from './Balance'
import ScheduleProgress from './ScheduleProgress'
import { ConfirmModal, ConfirmModalProps } from './Modal'
import FeeConfigModal from './settings/FeeConfigModal'

import styles from './Jam.module.css'
import { useFeeConfigValues } from '../hooks/Fees'
import SchedulerConfirmationModal from './SchedulerConfirmationModal'
import styles from './Jam.module.css'

const DEST_ADDRESS_COUNT_PROD = 3
const DEST_ADDRESS_COUNT_TEST = 1
Expand Down Expand Up @@ -144,6 +143,17 @@ function SchedulerSuccessMessage({ schedule, onConfirm }: SchedulerSuccessMessag
)
}

type ScheduleConfirmModalProps = Omit<ConfirmModalProps, 'title'>

function ScheduleConfirmModal(props: ScheduleConfirmModalProps) {
const { t } = useTranslation()
return (
<ConfirmModal title={t('scheduler.confirm_modal.title')} {...props}>
{t('scheduler.confirm_modal.body')}
</ConfirmModal>
)
}

interface JamProps {
wallet: CurrentWallet
}
Expand All @@ -165,6 +175,7 @@ export default function Jam({ wallet }: JamProps) {
const [lastKnownSchedule, resetLastKnownSchedule] = useLatestTruthy(currentSchedule ?? undefined)
const [isShowSuccessMessage, setIsShowSuccessMessage] = useState(false)
const [feeConfigValues, reloadFeeConfigValues] = useFeeConfigValues()
const [showScheduleConfirmModal, setShowScheduleConfirmModal] = useState(false)
const maxFeesConfigMissing = useMemo(
() =>
feeConfigValues && (feeConfigValues.max_cj_fee_abs === undefined || feeConfigValues.max_cj_fee_rel === undefined),
Expand Down Expand Up @@ -283,6 +294,7 @@ export default function Jam({ wallet }: JamProps) {
}

setAlert(undefined)
setShowScheduleConfirmModal(false)
setIsWaitingSchedulerStart(true)

const destinations = addressValueKeys(addressCount).map((key) => values[key])
Expand Down Expand Up @@ -536,7 +548,21 @@ export default function Jam({ wallet }: JamProps) {
})}

<p className="text-secondary mb-4">{t('scheduler.description_fees')}</p>
<SchedulerConfirmationModal
<rb.Button
className="w-100 mb-4"
variant="dark"
size="lg"
disabled={isOperationDisabled || isSubmitting || !isValid}
onClick={() => setShowScheduleConfirmModal(true)}
>
<div className="d-flex justify-content-center align-items-center">
{t('scheduler.button_start')}
<Sprite symbol="caret-right" width="24" height="24" className="ms-1" />
</div>
</rb.Button>
<ScheduleConfirmModal
isShown={showScheduleConfirmModal}
onCancel={() => setShowScheduleConfirmModal(false)}
onConfirm={handleSubmit}
disabled={isOperationDisabled || isSubmitting || !isValid}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const InfoModal = ({
)
}

export type ConfirmModalProps = BaseModalProps & {
export type ConfirmModalProps = Omit<BaseModalProps, 'closeButton'> & {
onConfirm: () => void
disabled?: boolean
}
Expand Down
21 changes: 0 additions & 21 deletions src/components/SchedulerConfirmationModal.module.css

This file was deleted.

43 changes: 0 additions & 43 deletions src/components/SchedulerConfirmationModal.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@
},
"confirm_modal": {
"title": "Start Scheduled Sweep",
"body": "Are you sure you want to start the scheduled sweep?"
"body": "Are you sure you want to start a scheduled sweep?"
}
},
"modal": {
Expand Down