Skip to content

Instantly share code, notes, and snippets.

@ryardley
Last active April 19, 2021 13:07
Show Gist options
  • Save ryardley/b36f24600793e61dcdaa4a0eacde2d41 to your computer and use it in GitHub Desktop.
Save ryardley/b36f24600793e61dcdaa4a0eacde2d41 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const fns = {
}
async function attemptConnection() {
return "Thanks!"
}
async function attemptPayment() {
throw new Error('Crapp!!')
}
const metamaskFlowMachine = Machine({
id: 'metamaskFlow',
initial: 'disconnected',
context: {
error: undefined
},
states: {
disconnected: {
on: {
CONNECT_CLICKED: 'connecting'
}
},
connecting: {
invoke: {
id: 'attemptConnection',
src: attemptConnection,
onDone: "active",
onError: {target: "disconnected", actions: assign({error: (ctx,event) => event.data})},
}
},
active: {
on:{
PAY_CLICKED: "paying",
CLOSE_CLICKED: "done",
}
},
paying: {
invoke: {
id: 'attemptPayment',
src: attemptPayment,
onDone: "thankyou",
onError: {target: "active", actions: assign({error: (ctx,event) => event.data})},
}
},
thankyou: {
on: {
CLOSE_CLICKED: "active"
}
},
done: {
type: 'final'
}
}
}, fns);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment