Created
May 22, 2021 03:46
-
-
Save ilyavf/f33fb9a2eb08fbe115affbab68e203d7 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
// 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