Last active
December 19, 2022 19:31
-
-
Save mtvbrianking/b18f91a0748f1ecf4cf7441da722aa99 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz/?gist=b18f91a0748f1ecf4cf7441da722aa99
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const withdrawMachine = Machine( | |
{ | |
id: 'withdraw', | |
initial: 'created', | |
context: { | |
signatures: 0, | |
corum: 3 | |
}, | |
states: { | |
created: { | |
on: { | |
SUBMIT: { | |
target: 'pending', | |
cond: 'isApproved' | |
}, | |
SIGN: { | |
actions: ['approve'] | |
} | |
} | |
}, | |
pending: { | |
type: 'final' | |
} | |
} | |
}, | |
{ | |
actions: { | |
approve: assign({ | |
signatures: (context, event) => context.signatures + 1 | |
}) | |
}, | |
guards: { | |
isApproved: (context, event) => { | |
return context.signatures >= context.corum; | |
} | |
} | |
} | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const withdrawMachine = Machine( | |
{ | |
id: 'withdraw', | |
initial: 'created', | |
context: { | |
signatures: 0, | |
corum: 3 | |
}, | |
states: { | |
created: { | |
on: { | |
SIGN: 'signing' | |
} | |
}, | |
signing: { | |
entry: ['approve'], | |
on: { | |
'': [ | |
{ | |
target: 'pending', | |
cond: 'isApproved' | |
}, | |
{ | |
target: 'created' | |
} | |
] | |
} | |
}, | |
pending: { | |
type: 'final' | |
} | |
} | |
}, | |
{ | |
actions: { | |
approve: assign({ | |
signatures: (context, event) => context.signatures + 1 | |
}) | |
}, | |
guards: { | |
isApproved: (context, event) => { | |
return context.signatures >= context.corum; | |
} | |
} | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Machine v2