Last active
March 4, 2020 20:34
-
-
Save andrewgordstewart/02bdbdedc9a541127175c5767331b374 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains 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 config = { | |
key: 'virtual-funding-as-leaf', | |
id: 'workflow', | |
initial: 'setupJointChannel', | |
states: { | |
setupJointChannel: { | |
initial: 'waitForFirstJointState', | |
states: { | |
waitForFirstJointState: { | |
invoke: { | |
src: 'waitForFirstJointState', | |
onDone: 'supportState', | |
onError: '#workflow.failure' | |
} | |
}, | |
supportState: { | |
invoke: {id: undefined, src: 'supportState', data: (_, {data}) => data, onDone: 'done'} | |
}, | |
done: {type: 'final'} | |
}, | |
onDone: 'determineDeductions' | |
}, | |
determineDeductions: { | |
invoke: {src: 'getDeductions', data: ctx => ctx, onDone: 'fundJointChannel'}, | |
exit: 'assignDeductions' | |
}, | |
fundJointChannel: { | |
initial: 'getObjective', | |
states: { | |
getObjective: {invoke: {src: 'fundGuarantor', onDone: 'runObjective'}}, | |
runObjective: { | |
entry: 'triggerGuarantorObjective', | |
invoke: { | |
src: 'ledgerFunding', | |
data: (ctx, {data}) => { | |
if (ctx.role === 1) throw 'Incorrect role'; | |
return { | |
targetChannelId: data.data.guarantorId, | |
ledgerChannelId: data.data.ledgerId, | |
deductions: ctx.deductions | |
}; | |
}, | |
onDone: 'done' | |
} | |
}, | |
done: {type: 'final'} | |
}, | |
onDone: 'fundTargetChannel' | |
}, | |
fundTargetChannel: { | |
initial: 'jointChannelUpdate', | |
states: { | |
jointChannelUpdate: { | |
invoke: {src: 'jointChannelUpdate', onDone: 'supportState', onError: undefined} | |
}, | |
supportState: { | |
invoke: {id: undefined, src: 'supportState', data: (_, {data}) => data, onDone: 'done'} | |
}, | |
done: {type: 'final'} | |
}, | |
onDone: 'success' | |
}, | |
success: {type: 'final'}, | |
failure: {} | |
} | |
}; | |
const guards = {}; | |
const customActions = {}; | |
const machine = Machine(config, {guards, actions: customActions}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment