Skip to content

Instantly share code, notes, and snippets.

@korshunad
Last active April 1, 2022 23:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save korshunad/9f553ba94417af309c04547d7819c008 to your computer and use it in GitHub Desktop.
Save korshunad/9f553ba94417af309c04547d7819c008 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// 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