Skip to content

Instantly share code, notes, and snippets.

@mtvbrianking
Last active December 19, 2022 19:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mtvbrianking/b18f91a0748f1ecf4cf7441da722aa99 to your computer and use it in GitHub Desktop.
Save mtvbrianking/b18f91a0748f1ecf4cf7441da722aa99 to your computer and use it in GitHub Desktop.
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;
}
}
}
);
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;
}
}
}
);
@mtvbrianking
Copy link
Author

mtvbrianking commented Dec 19, 2022

image
Machine v1

@mtvbrianking
Copy link
Author

image
Machine v2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment