Last active
March 4, 2020 20:34
-
-
Save andrewgordstewart/b730b04dc521ca40f83ea13b9e1fbcf3 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-hub', | |
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: { | |
type: 'parallel', | |
entry: ['watchObjectives', 'assignDeductions'], | |
states: { | |
fundGuarantorAH: { | |
initial: 'waitForObjective', | |
states: { | |
waitForObjective: {on: {FundGuarantorWithA: 'runObjective'}}, | |
runObjective: { | |
invoke: { | |
src: 'ledgerFunding', | |
data: (ctx, {data}) => { | |
return { | |
targetChannelId: data.guarantorId, | |
ledgerChannelId: data.ledgerId, | |
deductions: ctx.deductions[role] | |
}; | |
}, | |
onDone: 'done' | |
} | |
}, | |
done: {type: 'final'} | |
} | |
}, | |
fundGuarantorBH: { | |
initial: 'waitForObjective', | |
states: { | |
waitForObjective: {on: {FundGuarantorWithB: 'runObjective'}}, | |
runObjective: { | |
invoke: { | |
src: 'ledgerFunding', | |
data: (ctx, {data}) => { | |
return { | |
targetChannelId: data.guarantorId, | |
ledgerChannelId: data.ledgerId, | |
deductions: ctx.deductions[role] | |
}; | |
}, | |
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