Skip to content

Instantly share code, notes, and snippets.

@wighawag
Last active June 22, 2020 15:49
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 wighawag/3274dd9dd84df8692db0c2169cfc3014 to your computer and use it in GitHub Desktop.
Save wighawag/3274dd9dd84df8692db0c2169cfc3014 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
Machine({
id: 'wallet',
type: "parallel",
context: {
address: undefined,
},
states: {
builtin: {
initial: 'unknown',
context: {
error: undefined,
},
states: {
unknown: {
on: {
PROBE: 'probing',
},
},
probing: {
on: {
ERROR: {
target: 'unknown',
actions: assign({
error: () => "failed to probe",
}),
},
FOUND: 'available',
NOT_FOUND: 'notAvailable',
}
},
available: {
type: 'final',
},
notAvailable: {
type: 'final',
},
}
},
account: {
initial: 'unknown',
states: {
unknown: {
on: {
SELECT: 'loading',
}
},
loading: {
entry: 'select',
on: {
FOUND: 'connecting',
ERROR: {
target: 'unknown',
actions: assign({
error: () => "failed to load wallet",
}),
},
},
},
connecting: {
on: {
CONNECTED: 'connected',
ERROR: {
target: 'unknown',
actions: assign({
error: () => "failed to connect to wallet",
}),
},
},
},
connected: {
initial: 'locked',
states: {
locked: {},
ready: {
activities: ['watch'],
}
}
}
}
}
}
},
{
actions: {
select: send('PROBE'),
// pure((context, event) => {
// if (!context.vendor) {
// return send('PROBE');
// }
// }),
probe: () => {
console.log('probe');
},
builtin_found: assign({
vendor: true
}),
builtin_not_found: assign({
vendor: true
})
},
activities: {
watch: () => {
const interval = setInterval(() => console.log('BEEP!'), 1000);
return () => clearInterval(interval);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment