Skip to content

Instantly share code, notes, and snippets.

@gabrocheleau
Created August 28, 2020 20:26
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 gabrocheleau/062b231831de25a51b655befe83e8743 to your computer and use it in GitHub Desktop.
Save gabrocheleau/062b231831de25a51b655befe83e8743 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const parentWalletConnectionMachine = Machine(
{
id: 'walletConnector',
initial: 'disconnected',
context: {},
states: {
disconnected: {
entry: ['disconnect'],
on: {
CONNECT: 'connecting',
},
},
connecting: {
entry: ['connect'],
on: {
DISCONNECT: 'disconnected',
SUCCESS: 'connected',
ERROR: 'error',
},
},
connected: {
exit: ['disconnect'],
on: {
DISCONNECT: 'disconnected',
CONNECT: 'connecting',
ERROR: 'error',
},
},
error: {
entry: 'error',
exit: 'resolve',
on: {
CONNECT: 'connecting',
},
},
},
},
{
actions: {
error: assign({
error: (_, event) => event.message,
}),
resolve: assign({
error: undefined,
}),
connect: assign((_, event) => ({
machine: spawn(event.machine, event.machine.id),
})),
disconnect: assign({
accounts: undefined,
network: undefined,
provider: undefined,
machine: (context) => {
context.machine?.stop?.();
return undefined;
},
}),
},
},
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment