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/b730b04dc521ca40f83ea13b9e1fbcf3 to your computer and use it in GitHub Desktop.
Save andrewgordstewart/b730b04dc521ca40f83ea13b9e1fbcf3 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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