Skip to content

Instantly share code, notes, and snippets.

@paulrberg

paulrberg/machine.js

Last active Sep 28, 2020
Embed
What would you like to do?
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const setFundedContext = assign({
alice: 50,
bob: 50,
dai: 100,
});
const setFundedAndRewardedContext = assign({
alice: 50,
bob: 50,
dai: 0,
eth: 1,
});
const fetchMachine = Machine({
id: 'guarantorPool',
initial: 'pristine',
context: {
alice: 0,
bob: 0,
dai: 0,
eth: 0,
},
states: {
pristine: {
on: {
FUND: {
target: 'funded',
actions: setFundedContext,
},
},
},
funded: {
on: {
REWARD: {
target: 'fundedAndRewarded',
actions: setFundedAndRewardedContext,
},
},
},
fundedAndRewarded: {
on: {
EXIT: 'pristine',
WITHDRAW: 'funded',
},
},
},
},
{
actions: {
setFundedContext,
setFundedAndRewardedContext,
},
},
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.