11import {
2- Alert , Button , Container , Stack , Typography ,
2+ Alert ,
3+ Container , Stack
34} from '@mui/material'
45import { 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'
109import { 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
2115export 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