Last active
April 30, 2021 15:46
-
-
Save austinsamsel/48a7989542175697189dff4e33ac05c8 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 guards = { | |
isInitialized: (context, { data }) => { | |
return false; | |
}, | |
}; | |
const purchaseDefinition = { | |
initial: 'IDLE', | |
context: { | |
error: {}, | |
}, | |
states: { | |
IDLE: { | |
on: { | |
PURCHASE: { | |
target: 'VALIDATING', | |
}, | |
}, | |
}, | |
// @TODO: some states might conditionally send to error or idle based on the | |
// type of error that occurs | |
ERROR: { | |
type: 'final', | |
}, | |
VALIDATING: { | |
invoke: { | |
src: 'validate', // recaptcha, not owned by current user, etc. | |
onDone: 'CHECK_INITIALIZATION', | |
onError: 'ERROR', | |
}, | |
}, | |
CHECK_INITIALIZATION: { | |
invoke: { | |
src: 'checkPurchaseInitialization', | |
onDone: [ | |
{ | |
cond: 'isInitialized', | |
target: 'FINAL_CHECKS', | |
}, | |
{ | |
target: 'INITIALIZING', | |
}, | |
], | |
onError: 'IDLE', | |
}, | |
}, | |
INITIALIZING: { | |
invoke: { | |
src: 'initialize', // is NFT still for sale, etc. | |
onDone: 'PURCHASING', | |
onError: 'IDLE', | |
}, | |
}, | |
FINAL_CHECKS: { | |
invoke: { | |
src: 'runFinalChecks', // is NFT still for sale, etc. | |
onDone: 'PURCHASING', | |
onError: 'IDLE', | |
}, | |
}, | |
PURCHASING: { | |
invoke: { | |
src: 'purchaseNFT', // recaptcha, not owned by current user, etc. | |
onDone: 'TAIL_TX', | |
onError: 'IDLE', | |
}, | |
}, | |
TAIL_TX: { | |
invoke: { | |
src: 'tailPurchase', | |
onDone: 'POLL_API', | |
onError: 'IDLE', | |
}, | |
}, | |
POLL_API: { | |
invoke: { | |
src: 'getUserNFT', | |
onDone: 'SUCCESS', | |
onError: 'IDLE', | |
}, | |
}, | |
SUCCESS: { | |
type: 'final', | |
}, | |
}, | |
}; | |
Machine(purchaseDefinition, { guards }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment