Last active
July 26, 2021 17:18
-
-
Save marschhuynh/4eb2ed63afe0bfeae2a6f10d8184e088 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
const depositAction = () => {} | |
const paymentMachine = Machine({ | |
id: 'engagement', | |
initial: 'initial', | |
context: { | |
buyer: null, | |
seller: null, | |
buyer_confirmed: false, | |
seller_confirmed: false, | |
}, | |
states: { | |
initial: { | |
on: { | |
ENGAGE: 'engaged' | |
} | |
}, | |
engaged: { | |
initial: 'reviewing', | |
states: { | |
reviewing: { | |
on: { | |
SELLER_DEPOSIT: 'depositing', | |
SELLER_REFUSE: '#engagement.refused', | |
} | |
}, | |
depositing: { | |
on: { | |
DEPOSIT_ERROR: 'deposit_failure', | |
DEPOSIT_SUCCESS: 'deposit_success', | |
} | |
}, | |
deposit_failure: { | |
on: { | |
RETRY_DEPOSIT: 'reviewing', | |
} | |
}, | |
deposit_success: { | |
on: { | |
'OPEN_CHAT': '#engagement.preparing' | |
} | |
} | |
} | |
}, | |
refused: { | |
type: 'final' | |
}, | |
preparing: { | |
initial: 'doc_preparing', | |
states: { | |
doc_preparing: { | |
on: { | |
SUBMIT_APPLICATION:'submited' | |
} | |
}, | |
submited: { | |
on: { | |
CONFIRM_TRANSFER:'#engagement.transfering' | |
} | |
} | |
} | |
}, | |
transfering: { | |
initial: 'ship_preparing', | |
states: { | |
ship_preparing: { | |
on: { | |
SHIP_CONFIRM: 'shipping' | |
} | |
}, | |
shipping: { | |
on: { | |
BUYER_CONFIRM: { | |
actions: assign({ buyer_confirmed: true }) | |
}, | |
SELLER_CONFIRM: { | |
actions: assign({ seller_confirmed: true }) | |
}, | |
'': { | |
target: '#engagement.completed', cond: 'isBothConfirm', | |
} | |
} | |
}, | |
} | |
}, | |
completed: { | |
type: 'final' | |
} | |
} | |
}, { | |
guards: { | |
isBothConfirm: (context) => context.buyer_confirmed && context.seller_confirmed | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment