-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add recovery mode page to examples
- Loading branch information
Showing
4 changed files
with
95 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { Backend, ConsoleBackend } from '@estkme-group/notccid' | ||
import { FC, useCallback, useMemo, useState } from 'react' | ||
import { Button, Col, Container, Form, Row, Stack } from 'react-bootstrap' | ||
import { useManagedNotCCID } from 'src/ManagedNotCCID' | ||
import { MutexBackend } from 'src/MutexBackend' | ||
import { Connect } from './Connect' | ||
|
||
export const Entry: FC = () => { | ||
const [backend, setBackend] = useState<Backend>() | ||
const wrappedBackend = useMemo(() => { | ||
if (!backend) return undefined | ||
let _backend = backend | ||
_backend = new ConsoleBackend(_backend, ConsoleBackend.buildOptions(printInfo, [])) | ||
_backend = new MutexBackend(_backend) | ||
return _backend | ||
}, [backend]) | ||
const managed = useManagedNotCCID(wrappedBackend) | ||
const handleRecoveryMode = useCallback(async () => { | ||
if (!managed) return | ||
await managed.enterRecoveryMode() | ||
}, [managed]) | ||
return ( | ||
<Container fluid> | ||
<Form className='mt-3'> | ||
<Form.Group as={Row} className='mt-3'> | ||
<Form.Label column sm={1}> | ||
Connect | ||
</Form.Label> | ||
<Col sm={11}> | ||
<Connect backend={backend} onChange={setBackend} /> | ||
</Col> | ||
</Form.Group> | ||
<Form.Group as={Row} className='mt-3'> | ||
<Form.Label column sm={1}> | ||
Functionally | ||
</Form.Label> | ||
<Col sm={11}> | ||
<Stack gap={3} direction='horizontal'> | ||
<Button onClick={handleRecoveryMode}>Enter Recovery Mode</Button> | ||
</Stack> | ||
</Col> | ||
</Form.Group> | ||
</Form> | ||
</Container> | ||
) | ||
} | ||
|
||
function printInfo() { | ||
const args: unknown[] = Array.from(arguments) | ||
let argument: unknown | ||
for (let index = 0; index < args.length; index++) { | ||
argument = args[index] | ||
if (argument instanceof Uint8Array) { | ||
args[index] = toHexString(argument) | ||
} | ||
} | ||
console.info.apply(console, args) | ||
} | ||
|
||
function toHexString(data: Uint8Array): string { | ||
let result = '' | ||
for (const b of data) { | ||
result += b.toString(16).padStart(2, '0') | ||
} | ||
return result.toUpperCase() | ||
} |
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,15 @@ | ||
import 'bootstrap/dist/css/bootstrap.min.css' | ||
import ready from 'domready' | ||
import { createRoot } from 'react-dom/client' | ||
import { Entry } from './components/RecoveryEntry' | ||
|
||
document.documentElement.translate = false | ||
document.documentElement.classList.add('notranslate') | ||
|
||
const container = document.createElement('main') | ||
createRoot(container).render(<Entry />) | ||
|
||
ready(() => { | ||
document.body = document.createElement('body') | ||
document.body.appendChild(container) | ||
}) |
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