Skip to content

Instantly share code, notes, and snippets.

@ilyavf
Created May 22, 2021 03:46
Show Gist options
  • Save ilyavf/f33fb9a2eb08fbe115affbab68e203d7 to your computer and use it in GitHub Desktop.
Save ilyavf/f33fb9a2eb08fbe115affbab68e203d7 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// import { createMachine, assign, interpret } from 'xstate';
// const Machine = createMachine
const genSeed = () => {
return new Promise((resolve, reject) => {
resolve([1,2,3,4,5])
})
}
const initWallet = () => {
return new Promise((resolve, reject) => {
resolve(true)
})
}
const unlockWallet = () => {
return new Promise((resolve, reject) => {
resolve(true)
})
}
const machine = Machine({
id: 'lnd',
initial: 'idle',
states: {
idle: {
on: {
WW_LOADED_UTILS: 'loading'
}
},
loading: {
on: {
UNLOCKER_READY: 'unlockerReady',
}
},
unlockerReady: {
initial: 'ready',
states: {
ready: {
on: {
GEN_SEED: 'pendingSeed',
INIT: 'pendingInit',
UNLOCK: 'pendingUnlock'
},
},
pendingSeed: {
invoke: {
src: genSeed,
onDone: 'ready'
}
},
pendingInit: {
invoke: {
src: initWallet,
onDone: '#lnd.unlocked'
}
},
pendingUnlock: {
invoke: {
src: unlockWallet,
onDone: '#lnd.unlocked'
}
}
}
},
unlocked: {
initial: 'loading',
states: {
loading: {},
restReady: {}
}
}
}
})
// const service = interpret(machine);
// service.onTransition((state) => {
// elBox.dataset.state = state.toStrings().join(' ');
// console.log(state);
// });
// service.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment