Last active
April 1, 2022 23:52
-
-
Save korshunad/9f553ba94417af309c04547d7819c008 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 NFT_SALE_FLOW_MESSAGES = { | |
CREATING_NFT_SALE: 'NFTSaleFlow.status.creatingSale', | |
INVOCATION_REQUEST: 'NFTSaleFlow.status.gettingInvocation', | |
REDIRECTING_TO_DAPPER: 'NFTSaleFlow.status.redirectingToDapper', | |
}; | |
const IGNORE_ERRORS_DURATION = 3000; | |
const listMachine = Machine({ | |
id: 'listNFT', | |
initial: 'idle', | |
states: { | |
idle: { | |
initial: 'idle', | |
states: { | |
idle: { | |
id: 'idle', | |
}, | |
error: { id: 'error' }, | |
}, | |
on: { | |
LIST_NFT: [ | |
{ | |
cond: 'shouldConfirmLowPrice', | |
target: '#confirming_low_price', | |
actions: 'assignPrice', | |
}, | |
{ target: '#creating_nft_sale', actions: 'assignPrice' }, | |
], | |
}, | |
}, | |
confirming_low_price: { | |
id: 'confirming_low_price', | |
initial: 'initial', | |
states: { | |
initial: { | |
always: [ | |
{ | |
target: '#confirm_checkbox', | |
cond: 'priceRequiresCheck', | |
}, | |
{ | |
target: '#show_warning', | |
}, | |
], | |
}, | |
show_warning: { | |
id: 'show_warning', | |
}, | |
confirm_checkbox: { id: 'confirm_checkbox' }, | |
}, | |
on: { | |
CONFIRM: '#creating_nft_sale', | |
UPDATE_PRICE: '#idle', | |
}, | |
}, | |
creating_nft_sale: { | |
id: 'creating_nft_sale', | |
invoke: { | |
src: 'placeListingOrder', | |
onDone: '#polling_listing_for_invocation', | |
onError: { | |
target: '#error', | |
actions: 'setError', | |
}, | |
}, | |
meta: { | |
message: NFT_SALE_FLOW_MESSAGES.CREATING_NFT_SALE, | |
}, | |
}, | |
polling_listing_for_invocation: { | |
id: 'polling_listing_for_invocation', | |
after: { | |
[IGNORE_ERRORS_DURATION]: { | |
actions: send('STOP', { to: 'pollOrderService' }), | |
}, | |
}, | |
invoke: { | |
id: 'pollOrderService', | |
src: 'pollOrder', | |
onError: { | |
target: '#error', | |
actions: 'setError', | |
}, | |
}, | |
on: { | |
POLL_ORDER_SUCCESS: [{ target: '#redirecting_to_dapper' }], | |
POLL_ORDER_ERROR: [ | |
{ | |
target: '#error', | |
actions: 'setError', | |
}, | |
], | |
}, | |
meta: { | |
message: NFT_SALE_FLOW_MESSAGES.INVOCATION_REQUEST, | |
}, | |
}, | |
redirecting_to_dapper: { | |
id: 'redirecting_to_dapper', | |
type: 'final', | |
invoke: { | |
src: 'redirectToList', | |
}, | |
meta: { | |
message: NFT_SALE_FLOW_MESSAGES.REDIRECTING_TO_DAPPER, | |
}, | |
}, | |
}, | |
}, { | |
guards: { | |
shouldConfirmLowPrice: false, | |
priceRequiresCheck: false, | |
}, | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment