Skip to content

Instantly share code, notes, and snippets.

@palra
Created November 17, 2020 15:16
Show Gist options
  • Save palra/7a2914e6c5c8971dcc93e313ca364460 to your computer and use it in GitHub Desktop.
Save palra/7a2914e6c5c8971dcc93e313ca364460 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 paymentIntent = {
id: 'payment_intent',
initial: 'requires_payment_method',
states: {
requires_payment_method: {
on: {
STRIPE_PAYMENT_METHOD_SENT: 'processing',
STRIPE_PAYMENT_CANCELLED: 'cancelled',
}
},
processing: {
on: {
STRIPE_PAYMENT_AUTHORIZED: 'authorized',
STRIPE_PAYMENT_DECLINED: 'requires_payment_method',
STRIPE_PAYMENT_CANCELLED: 'cancelled',
}
},
authorized: {
entry: send('PAYMENT_AUTHORIZED'),
on: {
STRIPE_PAYMENT_CONFIRMED: 'confirmed',
STRIPE_PAYMENT_CANCELLED: 'cancelled',
}
},
confirmed: {
type: 'final',
entry: sendParent('PAYMENT_CONFIRMED'),
},
cancelled: {
type: 'final',
entry: sendParent('PAYMENT_CANCELLED'),
},
}
}
const bid = Machine({
id: 'bid',
initial: 'waiting_authorization',
states: {
waiting_authorization: {
on: {
PAYMENT_AUTHORIZED: 'placed'
},
...paymentIntent,
},
placed: {
on: {
BID_OUTDATED: 'outdated',
},
},
outdated: {
type: 'final',
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment