Created
August 28, 2020 20:26
-
-
Save gabrocheleau/062b231831de25a51b655befe83e8743 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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