Skip to content

Instantly share code, notes, and snippets.

@sedzd
Last active June 22, 2020 17:02
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 sedzd/cb2f547badf926f992c0a6e7f74d7cb3 to your computer and use it in GitHub Desktop.
Save sedzd/cb2f547badf926f992c0a6e7f74d7cb3 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const otpIsValid = (context, event) => {
return context.otpSent && event.otp && event.otp.length === 6;
}
const otpIsNotValid = (context, event) => {
return !context.otpSent || !event.otp || event.otp.length !== 6;
}
const CardStatusMachine = Machine(
{
id: "Card Status" ,
initial: 'inactive',
context: {
otpSent: false
},
states: {
inactive: {
on: {
KEYINOTP: [
{
target: 'active',
cond: otpIsValid
},
{
target: 'inactive',
cond: otpIsNotValid,
actions: assign({otpSent: false})
}
],
REQOTP: {
target: 'inactive',
actions: assign({otpSent: true})
}
}
},
active: {
id:"active",
on: {
BLOCK: 'blocked',
CANCEL: 'canceled'
}
},
canceled: {
type: 'final'
},
blocked: {
on: {
UNBLOCK: "active"
}
}
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment