Skip to content

Instantly share code, notes, and snippets.

@janek26
Last active August 5, 2021 14:12
Show Gist options
  • Save janek26/9c7db6c5acd719f81bde32c219592593 to your computer and use it in GitHub Desktop.
Save janek26/9c7db6c5acd719f81bde32c219592593 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 fetchMachine = Machine({
id: "send",
initial: "readyToPair",
context: {
amount: "",
contract: "0x0",
tokens: [],
approved: {},
},
states: {
readyToPair: {
on: { START_PAIR: "pairing" },
},
pairing: {
invoke: {
id: "pairing",
src: async () => {
},
onDone: "send",
onError: "readyToPair",
},
},
approve: {
on: {
SEND_APPROVE: "approving",
SKIP_APPROVE: "send",
APPROVE_STAY: "approve",
CHANGE_TOKENS: { target: "approve", actions: ["setContext"] },
CHANGE_CONTEXT: {
target: "approve",
actions: ["setContext", "checkApproveSkip"],
},
},
},
approving: {
invoke: {
id: "approving",
src: async (context) => {
return {}
},
onDone: {
target: "send",
actions: assign((context, { data }) => ({
approved: {
...context.approved,
[data.address]: data.amount,
},
})),
},
onError: "error",
},
},
send: {
on: {
SEND_TRANSACTION: "sending",
CHANGE_TOKENS: { target: "send", actions: ["setContext"] },
CHANGE_CONTEXT: {
target: "approve",
actions: ["setContext", "checkApproveSkip"],
},
},
},
sending: {
invoke: {
id: "sending",
src: async (context) => {
},
onDone: "success",
onError: "error",
},
},
success: {
type: "final",
},
error: {
type: "final",
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment