Last active
          April 19, 2021 13:07 
        
      - 
      
- 
        Save ryardley/b36f24600793e61dcdaa4a0eacde2d41 to your computer and use it in GitHub Desktop. 
    Generated by XState Viz: https://xstate.js.org/viz
  
        
  
    
      This file contains hidden or 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 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