Last active
September 10, 2021 15:44
-
-
Save austinsamsel/115d45faaec679ed78d97784bdb64ba0 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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const FS = { | |
IDLE: 'IDLE', | |
CONNECT_WALLET: 'CONNECT_WALLET', | |
TRANSACTION: 'TRANSACTION', | |
POLLING: 'POLLING', | |
SUCCESS: 'SUCCESS', | |
ERROR: 'ERROR', | |
}; | |
const EVENTS = { | |
AUTHORIZE: 'AUTHORIZE', | |
} | |
const MAX_POLL_DURATION = 10000; | |
const definition = { | |
id: 'sell', | |
initial: FS.IDLE, | |
context: { | |
FS, | |
ix: undefined, | |
ixArgs: undefined, | |
error: undefined, | |
}, | |
states: { | |
[FS.IDLE]: {}, | |
[FS.CONNECT_WALLET]: { | |
invoke: { | |
src: 'fclAuth', | |
onDone: [ | |
{ | |
target: FS.TRANSACTION, | |
}, | |
], | |
onError: { | |
target: FS.ERROR, | |
actions: 'assignError', | |
}, | |
}, | |
}, | |
[FS.TRANSACTION]: { | |
invoke: { | |
src: 'txMachine', | |
data: { | |
FS: () => txFS, | |
client: (context) => context.client, | |
ix: (context) => context.ix, | |
ixArgs: (context) => context.ixArgs, | |
isAuthorized: () => true, | |
}, | |
onDone: { | |
target: FS.POLLING, | |
}, | |
}, | |
}, | |
[FS.POLLING]: { | |
after: { | |
[MAX_POLL_DURATION]: { | |
actions: send('STOP', { to: 'poll' }), | |
}, | |
}, | |
invoke: { | |
id: 'poll', | |
src: 'pollOfferStatus', | |
onError: { | |
target: FS.ERROR, | |
actions: 'assignError', | |
}, | |
}, | |
on: { | |
POLL_ERROR: { | |
target: FS.ERROR, | |
actions: 'assignError', | |
}, | |
POLL_SUCCESS: { | |
target: FS.SUCCESS, | |
}, | |
}, | |
}, | |
[FS.SUCCESS]: {}, | |
[FS.ERROR]: {}, | |
}, | |
on: { | |
[EVENTS.AUTHORIZE]: [ | |
{ | |
target: FS.CONNECT_WALLET, | |
actions: 'assignInteraction', | |
cond: 'isConnectingWallet', | |
}, | |
{ | |
target: FS.TRANSACTION, | |
actions: 'assignInteraction', | |
}, | |
], | |
}, | |
}; | |
const services = {}; | |
const guards = { | |
isConnectingWallet: () => true, | |
}; | |
Machine(definition, { | |
actions, | |
services, | |
guards, | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment