-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move Idena bot banner to Profile Made idena bot banner self-containing * Do not shrink banner * Add key to the list * Move to useIdenaBot hook
- Loading branch information
Showing
5 changed files
with
222 additions
and
174 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import {useMachine} from '@xstate/react' | ||
import {assign, createMachine} from 'xstate' | ||
|
||
export function useIdenaBot() { | ||
const [current, send] = useMachine( | ||
createMachine({ | ||
context: { | ||
connected: undefined, | ||
}, | ||
initial: 'loading', | ||
states: { | ||
loading: { | ||
invoke: { | ||
src: 'loadConnectionStatus', | ||
}, | ||
on: { | ||
CONNECTED: 'connected', | ||
DISCONNECTED: 'disconnected', | ||
}, | ||
}, | ||
connected: { | ||
entry: [assign({connected: true}), 'persist'], | ||
}, | ||
disconnected: { | ||
on: {CONNECT: 'connected'}, | ||
}, | ||
}, | ||
}), | ||
{ | ||
services: { | ||
loadConnectionStatus: () => cb => { | ||
try { | ||
cb( | ||
JSON.parse(localStorage.getItem('connectIdenaBot')) | ||
? 'CONNECTED' | ||
: 'DISCONNECTED' | ||
) | ||
} catch (e) { | ||
console.error(e) | ||
cb('DISCONNECTED') | ||
} | ||
}, | ||
}, | ||
actions: { | ||
persist: ({connected}) => { | ||
localStorage.setItem('connectIdenaBot', connected) | ||
}, | ||
}, | ||
} | ||
) | ||
|
||
return [current.context.connected, () => send('CONNECT')] | ||
} |
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
Oops, something went wrong.