Last active
June 16, 2021 17:44
-
-
Save austinsamsel/4c0590bf4da00963f473dee5c32bf708 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const MAX_POLL_DURATION = 1000 * 60; | |
const FS = { | |
IDLE: 'IDLE', | |
AUTHORIZING: 'AUTHORIZING', | |
SEALING: 'SEALING', | |
SEALED: 'SEALED', | |
TX_ERROR: 'TX_ERROR', | |
}; | |
const definition = { | |
id: 'transaction', | |
initial: FS.IDLE, | |
context: { | |
FS, | |
ix: undefined, | |
txId: undefined, | |
txStatus: undefined, | |
error: undefined, | |
}, | |
states: { | |
[FS.IDLE]: { | |
always: [ | |
{ | |
target: FS.AUTHORIZING, | |
cond: 'isAuthorized', | |
}, | |
], | |
}, | |
[FS.AUTHORIZING]: { | |
entry: 'reset', | |
invoke: { | |
src: 'fclSend', | |
onDone: { | |
target: FS.SEALING, | |
actions: 'assignTxId', | |
}, | |
onError: { | |
target: FS.TX_ERROR, | |
actions: 'assignError', | |
}, | |
}, | |
}, | |
[FS.SEALING]: { | |
invoke: { | |
src: 'fclOnceSealed', | |
onDone: [ | |
{ | |
target: FS.SEALED, | |
actions: 'assignTxStatus', | |
}, | |
], | |
onError: { | |
target: FS.TX_ERROR, | |
actions: 'assignError', | |
}, | |
}, | |
}, | |
[FS.SEALED]: { | |
type: 'final', | |
}, | |
[FS.TX_ERROR]: {}, | |
}, | |
on: { | |
authorize: { | |
target: FS.AUTHORIZING, | |
actions: 'assignAuthorizeData', | |
}, | |
}, | |
}; | |
const services = { | |
fclSend: () => {}, | |
fclOnceSealed: () => {}, | |
}; | |
const guards = { | |
isAuthorized: (ctx) => true, | |
}; | |
const machine = Machine(definition, | |
{ | |
actions, | |
services, | |
guards, | |
delays: { MAX_POLL_DURATION }, | |
}, | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment