Skip to content

Commit 446205a

Browse files
committed
update sample component with new components
1 parent 22cdfcf commit 446205a

1 file changed

Lines changed: 11 additions & 26 deletions

File tree

src/Sample.tsx

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,27 @@
11
import {
2-
Alert, Button, Container, Stack, Typography,
2+
Alert,
3+
Container, Stack
34
} from '@mui/material'
45
import { assertEx } from '@xylabs/assert'
5-
import { type Hash, isHash } from '@xylabs/hex'
6-
import { isDefined, isUndefined } from '@xylabs/typeof'
7-
import type { Id } from '@xyo-network/id-payload-plugin'
8-
import { PayloadBuilder } from '@xyo-network/payload-builder'
9-
import { type HashPayload } from '@xyo-network/xl1-protocol'
6+
import type { Hash } from '@xylabs/hex'
7+
import { isHash } from '@xylabs/hex'
8+
import { isUndefined } from '@xylabs/typeof'
109
import { useState } from 'react'
1110

12-
import { Onboarding, TxConfirmedAlert, WelcomeStack } from './components/index.ts'
13-
import { useDefaultGateway, useOnBoarding } from './hooks/index.ts'
14-
15-
// Data to store off-chain
16-
const offChainPayloads: Id[] = [0, 1].map(index => ({
17-
schema: 'network.xyo.id',
18-
salt: `Hello from Sample ${index} - ${new Date().toISOString()}`,
19-
}))
11+
import { Onboarding, SubmitTransactionButton, TxConfirmedAlert, WelcomeStack } from './components/index.ts'
12+
import { buildSamplePayloads } from './helpers/index.ts'
13+
import { useDefaultGateway } from './hooks/index.ts'
2014

2115
export const XL1BrowserSample = () => {
2216
const [error, setError] = useState<Error>()
2317
const [confirmed, setConfirmed] = useState<Hash>()
2418
const { gateway, error: gatewayError } = useDefaultGateway()
25-
const { showSubmitTransaction } = useOnBoarding()
2619

2720
const submitTransaction = async () => {
2821
setError(undefined)
2922
try {
3023
const assertedGateway = assertEx(gateway, () => 'Gateway is not defined')
31-
// build a hash payload with the hash of the off-chain payload
32-
const hashPayloads: HashPayload[] = await Promise.all([0, 1].map(async index => ({
33-
schema: 'network.xyo.hash',
34-
hash: await PayloadBuilder.hash(offChainPayloads[index]),
35-
})))
24+
const { offChainPayloads, hashPayloads } = await buildSamplePayloads()
3625
const [txHash] = await assertedGateway.addPayloadsToChain?.(hashPayloads, offChainPayloads) ?? []
3726
if (isHash(txHash)) {
3827
setConfirmed(txHash)
@@ -55,12 +44,8 @@ export const XL1BrowserSample = () => {
5544
{error ? <Alert severity="error">{error.message}</Alert> : null}
5645
<WelcomeStack />
5746
<Onboarding />
58-
59-
{/* Transaction Submission */}
60-
{showSubmitTransaction === true && (
61-
<Button variant="contained" onClick={() => void submitTransaction()} disabled={isUndefined(gateway)} sx={{ alignSelf: 'start' }}>Submit Transaction</Button>
62-
)}
63-
{isDefined(confirmed) && <TxConfirmedAlert hash={confirmed} />}
47+
<SubmitTransactionButton onClick={() => void submitTransaction()} disabled={isUndefined(gateway)}>Submit Transaction</SubmitTransactionButton>
48+
<TxConfirmedAlert hash={confirmed} />
6449
</Stack>
6550

6651
</Container>

0 commit comments

Comments
 (0)