Skip to content

Instantly share code, notes, and snippets.

@andrewgordstewart
Last active March 4, 2020 20:34
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 andrewgordstewart/02bdbdedc9a541127175c5767331b374 to your computer and use it in GitHub Desktop.
Save andrewgordstewart/02bdbdedc9a541127175c5767331b374 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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