Skip to content

Commit

Permalink
Refactor on DeleteThreadModal
Browse files Browse the repository at this point in the history
  • Loading branch information
WRadoslaw authored and thesan committed Apr 26, 2022
1 parent 6a40045 commit e467429
Showing 1 changed file with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const DeleteThreadModal = () => {
hideModal,
} = useModal<DeleteThreadModalCall>()

const [state, send] = useMachine(defaultTransactionModalMachine)
const [state, send] = useMachine(defaultTransactionModalMachine, { context: { validateBeforeTransaction: true } })
const { api, connectionState } = useApi()
const { active: activeMember } = useMyMemberships()
const { allAccounts } = useMyAccounts()
Expand All @@ -46,21 +46,24 @@ export const DeleteThreadModal = () => {
const feeInfo = useTransactionFee(activeMember?.controllerAccount, transaction)

useEffect(() => {
if (!state.matches('requirementsVerification')) {
return
if (state.matches('requirementsVerification')) {
if (!activeMember) {
return showModal<SwitchMemberModalCall>({
modal: 'SwitchMember',
data: {
originalModalName: 'DeleteThreadModal',
originalModalData: { thread },
},
})
}
if (transaction && feeInfo) {
feeInfo.canAfford && send('PASS')
!feeInfo.canAfford && send('FAIL')
}
}
if (!activeMember) {
return showModal<SwitchMemberModalCall>({
modal: 'SwitchMember',
data: {
originalModalName: 'DeleteThreadModal',
originalModalData: { thread },
},
})
}
if (transaction && feeInfo) {
feeInfo.canAfford && send('PASS')
!feeInfo.canAfford && send('FAIL')

if (state.matches('beforeTransaction')) {
send(feeInfo?.canAfford ? 'PASS' : 'FAIL')
}
}, [state.value, activeMember, transaction, feeInfo?.canAfford])

Expand Down

0 comments on commit e467429

Please sign in to comment.