Skip to content

Commit e866f52

Browse files
committed
decompose sample into smaller components
1 parent 07fdae2 commit e866f52

4 files changed

Lines changed: 43 additions & 27 deletions

File tree

src/Sample.tsx

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,8 @@ import { PayloadBuilder } from '@xyo-network/payload-builder'
99
import { type HashPayload } from '@xyo-network/xl1-protocol'
1010
import { useState } from 'react'
1111

12-
import {
13-
RunProducerAlerts, TxConfirmedAlert, WalletAlerts,
14-
} from './components/index.ts'
12+
import { Onboarding, TxConfirmedAlert, WelcomeStack } from './components/index.ts'
1513
import { useDefaultGateway, useOnBoarding } from './hooks/index.ts'
16-
// eslint-disable-next-line import-x/no-internal-modules
17-
import Xl13DLogo from './images/XL1_3D_Token_Mainnet.svg'
1814

1915
// Data to store off-chain
2016
const offChainPayloads: Id[] = [0, 1].map(index => ({
@@ -26,9 +22,7 @@ export const XL1BrowserSample = () => {
2622
const [error, setError] = useState<Error>()
2723
const [confirmed, setConfirmed] = useState<Hash>()
2824
const { gateway, error: gatewayError } = useDefaultGateway()
29-
const {
30-
producerIsReachable, walletIsInstalled, walletIsNotInstalled, showSubmitTransaction,
31-
} = useOnBoarding()
25+
const { showSubmitTransaction } = useOnBoarding()
3226

3327
const submitTransaction = async () => {
3428
setError(undefined)
@@ -57,29 +51,14 @@ export const XL1BrowserSample = () => {
5751
}}
5852
>
5953
<Stack width={{ xs: '100%', sm: '600px' }} gap={2} p={2}>
60-
<Stack gap={1}>
61-
{gatewayError ? <Alert severity="error">{gatewayError.message}</Alert> : null}
62-
<Typography variant="h4" sx={{ display: 'inline-flex' }}>
63-
<img src={Xl13DLogo} height={38} width={38} style={{ marginRight: '10px' }} />
64-
XL1 Browser Sample
65-
</Typography>
66-
<Typography variant="subtitle1">This is a sample page for adding payloads to the XL1 chain for the browser environment.</Typography>
67-
</Stack>
68-
69-
{/* Onboarding */}
70-
{producerIsReachable ? <RunProducerAlerts.Found /> : <RunProducerAlerts.NotFound />}
71-
{producerIsReachable && <RunProducerAlerts.CopyPhrase />}
72-
{walletIsNotInstalled === true && <WalletAlerts.NotInstalled />}
73-
{walletIsInstalled === true && <WalletAlerts.Installed />}
74-
{walletIsInstalled === true && <WalletAlerts.Setup />}
54+
{gatewayError ? <Alert severity="error">{gatewayError.message}</Alert> : null}
7555
{error ? <Alert severity="error">{error.message}</Alert> : null}
56+
<WelcomeStack />
57+
<Onboarding />
7658

7759
{/* Transaction Submission */}
7860
{showSubmitTransaction === true && (
79-
<Stack alignItems="start">
80-
{/* {gatewayError ? <Alert severity="error">{gatewayError.message}</Alert> : null} */}
81-
<Button variant="contained" onClick={() => void submitTransaction()} disabled={isUndefined(gateway)}>Submit Transaction</Button>
82-
</Stack>
61+
<Button variant="contained" onClick={() => void submitTransaction()} disabled={isUndefined(gateway)} sx={{ alignSelf: 'start' }}>Submit Transaction</Button>
8362
)}
8463
{isDefined(confirmed) && <TxConfirmedAlert hash={confirmed} />}
8564
</Stack>

src/components/Onboarding.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react'
2+
import { useOnBoarding } from '../hooks/index.ts'
3+
import { WalletAlerts } from './alerts/index.ts'
4+
import { RunProducerAlerts } from './alerts/index.ts'
5+
6+
export const Onboarding: React.FC = () => {
7+
const {
8+
producerIsReachable,
9+
walletIsInstalled,
10+
walletIsNotInstalled,
11+
} = useOnBoarding()
12+
13+
return <>
14+
{producerIsReachable ? <RunProducerAlerts.Found /> : <RunProducerAlerts.NotFound />}
15+
{producerIsReachable && <RunProducerAlerts.CopyPhrase />}
16+
{walletIsNotInstalled === true && <WalletAlerts.NotInstalled />}
17+
{walletIsInstalled === true && <WalletAlerts.Installed />}
18+
{walletIsInstalled === true && <WalletAlerts.Setup />}
19+
</>
20+
}

src/components/WelcomeStack.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Stack, StackProps, Typography } from "@mui/material";
2+
// eslint-disable-next-line import-x/no-internal-modules
3+
import Xl13DLogo from '../images/XL1_3D_Token_Mainnet.svg'
4+
5+
export const WelcomeStack: React.FC<StackProps> = (props) => {
6+
return (
7+
<Stack gap={1} {...props}>
8+
<Typography variant="h4" sx={{ display: 'inline-flex' }}>
9+
<img src={Xl13DLogo} height={38} width={38} style={{ marginRight: '10px' }} />
10+
XL1 Browser Sample
11+
</Typography>
12+
<Typography variant="subtitle1">This is a sample page for adding payloads to the XL1 chain for the browser environment.</Typography>
13+
</Stack>
14+
)
15+
}

src/components/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
export * from './alerts/index.ts'
2+
export * from './Onboarding.tsx'
3+
export * from './WelcomeStack.tsx'

0 commit comments

Comments
 (0)