Skip to content

Commit

Permalink
Refactor on CreateThreadModal
Browse files Browse the repository at this point in the history
  • Loading branch information
WRadoslaw authored and thesan committed Apr 26, 2022
1 parent e467429 commit 92dc4f0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ export const CreateThreadModal = () => {
canAfford || send('FAIL')
}
}

if (state.matches('beforeTransaction') && balance && minimumTransactionCost) {
const canAfford = balance.transferable.gte(minimumTransactionCost)
send(canAfford ? 'PASS' : 'FAIL')
}
}, [state.value, member?.id, minimumTransactionCost, balance])

if (state.matches('generalDetails') && member) {
Expand Down
7 changes: 7 additions & 0 deletions packages/ui/src/forum/modals/CreateThreadModal/machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type CreateThreadState =
| { value: 'requirementsVerification'; context: EmptyObject }
| { value: 'requirementsFailed'; context: EmptyObject }
| { value: 'generalDetails'; context: DetailsContext }
| { value: 'beforeTransaction'; context: TransactionContext }
| { value: 'transaction'; context: TransactionContext }
| { value: 'success'; context: Required<CreateThreadContext> }
| { value: 'error'; context: CreateThreadContext & { transactionEvents: EventRecord[] } }
Expand Down Expand Up @@ -78,6 +79,12 @@ export const createThreadMachine = createMachine<CreateThreadContext, CreateThre
},
},
},
beforeTransaction: {
on: {
NEXT: 'transaction',
FAIL: 'requirementsFailed',
},
},
transaction: {
invoke: {
id: 'transaction',
Expand Down

0 comments on commit 92dc4f0

Please sign in to comment.