@xyo-network/react-chain-provider 1.20.15 → 1.20.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/README.md +9 -3302
  2. package/dist/browser/hooks/gateway/useNetwork.d.ts +1 -1
  3. package/dist/browser/hooks/gateway/useNetwork.d.ts.map +1 -1
  4. package/dist/browser/hooks/gateway/useRunner.d.ts +1 -1
  5. package/dist/browser/hooks/gateway/useRunner.d.ts.map +1 -1
  6. package/dist/browser/hooks/gateway/useViewer.d.ts +1 -1
  7. package/dist/browser/hooks/gateway/useViewer.d.ts.map +1 -1
  8. package/package.json +155 -45
  9. package/src/components/connected/ConnectAccountsStack.stories.tsx +0 -16
  10. package/src/components/connected/ConnectAccountsStack.tsx +0 -92
  11. package/src/components/connected/account/Connected.tsx +0 -19
  12. package/src/components/connected/account/index.ts +0 -1
  13. package/src/components/connected/index.ts +0 -2
  14. package/src/components/index.ts +0 -1
  15. package/src/contexts/current-block/Provider.stories.tsx +0 -38
  16. package/src/contexts/current-block/Provider.tsx +0 -36
  17. package/src/contexts/current-block/context.ts +0 -5
  18. package/src/contexts/current-block/index.ts +0 -5
  19. package/src/contexts/current-block/state.ts +0 -16
  20. package/src/contexts/current-block/use.ts +0 -5
  21. package/src/contexts/current-block/usePollCurrentBlock.ts +0 -61
  22. package/src/contexts/gateway/Provider.tsx +0 -81
  23. package/src/contexts/gateway/context.ts +0 -5
  24. package/src/contexts/gateway/index.ts +0 -4
  25. package/src/contexts/gateway/state.ts +0 -15
  26. package/src/contexts/gateway/story/GatewayStats.tsx +0 -33
  27. package/src/contexts/gateway/story/GatewayStatus.tsx +0 -53
  28. package/src/contexts/gateway/story/Provider.stories.tsx +0 -38
  29. package/src/contexts/gateway/story/ProviderWithWallet.stories.tsx +0 -43
  30. package/src/contexts/gateway/use.ts +0 -5
  31. package/src/contexts/in-page-gateways/Provider.tsx +0 -86
  32. package/src/contexts/in-page-gateways/context.ts +0 -5
  33. package/src/contexts/in-page-gateways/index.ts +0 -4
  34. package/src/contexts/in-page-gateways/state.ts +0 -12
  35. package/src/contexts/in-page-gateways/use.ts +0 -5
  36. package/src/contexts/index.ts +0 -3
  37. package/src/global.d.ts +0 -9
  38. package/src/hooks/account/BalanceHistoryItemFormatted.ts +0 -18
  39. package/src/hooks/account/helpers/formatAccountBalanceHistory.ts +0 -47
  40. package/src/hooks/account/helpers/index.ts +0 -1
  41. package/src/hooks/account/index.ts +0 -3
  42. package/src/hooks/account/useAccountBalanceHistory.ts +0 -51
  43. package/src/hooks/client/helpers/findCaveat.ts +0 -2
  44. package/src/hooks/client/helpers/index.ts +0 -1
  45. package/src/hooks/client/index.ts +0 -3
  46. package/src/hooks/client/permissions/index.ts +0 -2
  47. package/src/hooks/client/permissions/usePermissions.ts +0 -2
  48. package/src/hooks/client/permissions/usePermissionsAccounts.ts +0 -2
  49. package/src/hooks/client/useClientFromWallet.ts +0 -2
  50. package/src/hooks/client/useGatewayFromWallet.ts +0 -2
  51. package/src/hooks/gateway/index.ts +0 -3
  52. package/src/hooks/gateway/useNetwork.ts +0 -6
  53. package/src/hooks/gateway/useRunner.ts +0 -6
  54. package/src/hooks/gateway/useViewer.ts +0 -6
  55. package/src/hooks/helpers/getXyoClient.ts +0 -2
  56. package/src/hooks/helpers/index.ts +0 -2
  57. package/src/hooks/helpers/transaction/Confirmation.ts +0 -125
  58. package/src/hooks/helpers/transaction/index.ts +0 -1
  59. package/src/hooks/index.ts +0 -11
  60. package/src/hooks/useAddressBalance.ts +0 -86
  61. package/src/hooks/useConfirmTransactionBase.ts +0 -64
  62. package/src/hooks/useConnectAccount.ts +0 -36
  63. package/src/hooks/useCurrentBlock.ts +0 -27
  64. package/src/hooks/useNetwork.ts +0 -13
  65. package/src/hooks/useSigner.ts +0 -9
  66. package/src/hooks/viewer/UseStepRewardWeightTest.stories.tsx +0 -87
  67. package/src/hooks/viewer/ViewerWithDataLake.ts +0 -51
  68. package/src/hooks/viewer/index.ts +0 -2
  69. package/src/hooks/viewer/useCheckRpc.ts +0 -61
  70. package/src/index.ts +0 -5
  71. package/src/lib/balanceForRange.ts +0 -16
  72. package/src/lib/buildGateway.ts +0 -29
  73. package/src/lib/findMinimumBlock.ts +0 -9
  74. package/src/lib/index.ts +0 -3
  75. package/src/story/GatewayDecorator.tsx +0 -36
  76. package/src/story/index.ts +0 -1
  77. package/src/types/ContextGatewayType.ts +0 -4
  78. package/src/types/GatewayFromWallet.ts +0 -2
  79. package/src/types/index.ts +0 -2
@@ -1,81 +0,0 @@
1
- import { isDefinedNotNull, isNull } from '@xylabs/sdk-js'
2
- import { useGatewayFromWallet } from '@xyo-network/react-chain-client'
3
- import { ErrorRender } from '@xyo-network/react-error'
4
- import type { GatewayName } from '@xyo-network/xl1-sdk'
5
- import type { PropsWithChildren } from 'react'
6
- import React, { useMemo } from 'react'
7
-
8
- import { useProvidedInPageGateways } from '../in-page-gateways/index.ts'
9
- import { GatewayContext } from './context.ts'
10
- import type { GatewayState } from './state.ts'
11
-
12
- export interface GatewayProviderProps extends PropsWithChildren {
13
- gatewayName?: GatewayName
14
- }
15
-
16
- export const GatewayProvider: React.FC<GatewayProviderProps> = ({ gatewayName, children }) => {
17
- const {
18
- gateway: gatewayFromWallet,
19
- error: gatewayFromWalletError,
20
- } = useGatewayFromWallet(gatewayName)
21
-
22
- const {
23
- gateways: allGateways,
24
- errors: allGatewayErrors,
25
- clearAll,
26
- } = useProvidedInPageGateways(true)
27
-
28
- const gatewayFromConfig = gatewayName ? allGateways[gatewayName] : undefined
29
- const gatewayFromConfigError = gatewayName ? allGatewayErrors[gatewayName] : undefined
30
-
31
- const { defaultGateway, gateways } = useMemo(() => {
32
- if (isNull(gatewayFromWallet)) {
33
- return {
34
- defaultGateway: gatewayFromConfig,
35
- gateways: {
36
- inPageGateway: gatewayFromConfig,
37
- walletGateway: null,
38
- },
39
- }
40
- } else if (isDefinedNotNull(gatewayFromWallet)) {
41
- return {
42
- defaultGateway: gatewayFromWallet,
43
- gateways: {
44
- inPageGateway: gatewayFromConfig,
45
- walletGateway: gatewayFromWallet,
46
- },
47
- }
48
- }
49
- return {
50
- defaultGateway: undefined,
51
- gateways: {
52
- inPageGateway: undefined,
53
- walletGateway: undefined,
54
- },
55
- }
56
- }, [gatewayFromConfig, gatewayFromWallet])
57
-
58
- const value = useMemo(() => {
59
- const value: GatewayState = {
60
- defaultGateway,
61
- error: gatewayFromWalletError || gatewayFromConfigError,
62
- gateways,
63
- provided: true,
64
- resetGatewaysFromConfig: clearAll,
65
- }
66
- return value
67
- }, [
68
- defaultGateway,
69
- gatewayFromWalletError,
70
- gatewayFromConfigError,
71
- gateways,
72
- clearAll,
73
- ])
74
-
75
- return (
76
- <GatewayContext value={value}>
77
- <ErrorRender error={gatewayFromConfigError} />
78
- {children}
79
- </GatewayContext>
80
- )
81
- }
@@ -1,5 +0,0 @@
1
- import { createContextEx } from '@xylabs/react-shared'
2
-
3
- import type { GatewayState } from './state.ts'
4
-
5
- export const GatewayContext = createContextEx<GatewayState>()
@@ -1,4 +0,0 @@
1
- export * from './context.ts'
2
- export * from './Provider.tsx'
3
- export * from './state.ts'
4
- export * from './use.ts'
@@ -1,15 +0,0 @@
1
- import type { ContextExState } from '@xylabs/react-shared'
2
-
3
- import type { ContextGatewayType } from '../../types/index.ts'
4
-
5
- export interface GatewayStateFields {
6
- defaultGateway: ContextGatewayType | undefined | null
7
- error: Error | null | undefined
8
- gateways: {
9
- inPageGateway: ContextGatewayType | undefined | null
10
- walletGateway: ContextGatewayType | undefined | null
11
- }
12
- resetGatewaysFromConfig: () => void
13
- }
14
-
15
- export type GatewayState = ContextExState<GatewayStateFields>
@@ -1,33 +0,0 @@
1
- import { Stack, Typography } from '@mui/material'
2
- import type { AccountInstance } from '@xyo-network/sdk-js'
3
- import type { GatewayName } from '@xyo-network/xl1-sdk'
4
-
5
- import { InPageGatewaysProvider } from '../../in-page-gateways/index.ts'
6
- import { GatewayProvider } from '../Provider.tsx'
7
- import { GatewayStatus } from './GatewayStatus.tsx'
8
-
9
- export interface GatewayStatsProps {
10
- account?: AccountInstance
11
- id?: GatewayName
12
- url?: string
13
- }
14
-
15
- export const GatewayStats: React.FC<GatewayStatsProps> = ({
16
- account, id, url,
17
- }) => {
18
- return (
19
- <InPageGatewaysProvider account={account}>
20
- <GatewayProvider key={id} gatewayName={id}>
21
- <Stack gap={1}>
22
- <Typography variant="subtitle1">
23
- <strong>{id}</strong>
24
- </Typography>
25
- <Typography variant="caption" color="text.secondary">
26
- {url}
27
- </Typography>
28
- <GatewayStatus />
29
- </Stack>
30
- </GatewayProvider>
31
- </InPageGatewaysProvider>
32
- )
33
- }
@@ -1,53 +0,0 @@
1
- import {
2
- Alert, Chip, Stack, Typography,
3
- } from '@mui/material'
4
-
5
- import { useProvidedGateway } from '../use.ts'
6
-
7
- /** Inner component that consumes the GatewayContext to display load status */
8
- export const GatewayStatus: React.FC = () => {
9
- const { defaultGateway: gateway, error } = useProvidedGateway(false) ?? {}
10
-
11
- if (error) {
12
- return (
13
- <Alert severity="error">
14
- <Typography variant="body2">
15
- Failed to load gateway:
16
- {' '}
17
- {error.message}
18
- </Typography>
19
- </Alert>
20
- )
21
- }
22
-
23
- if (gateway === undefined) {
24
- return (
25
- <Alert severity="info">
26
- <Typography variant="body2">Gateway loading...</Typography>
27
- </Alert>
28
- )
29
- }
30
-
31
- if (gateway === null) {
32
- return (
33
- <Alert severity="warning">
34
- <Typography variant="body2">Gateway not available</Typography>
35
- </Alert>
36
- )
37
- }
38
-
39
- return (
40
- <Alert severity="success">
41
- <Stack direction="row" gap={1} alignItems="center">
42
- <Typography variant="body2">Gateway loaded</Typography>
43
- <Chip label="connected" color="success" size="small" />
44
- {gateway?.connection?.viewer && (
45
- <Chip label="viewer available" color="success" size="small" />
46
- )}
47
- {gateway?.connection.runner && (
48
- <Chip label="runner available" color="success" size="small" />
49
- )}
50
- </Stack>
51
- </Alert>
52
- )
53
- }
@@ -1,38 +0,0 @@
1
- import { Stack } from '@mui/material'
2
- import type { Meta, StoryObj } from '@storybook/react-vite'
3
- import { Account } from '@xyo-network/sdk-js'
4
- import { DefaultNetworks } from '@xyo-network/xl1-sdk'
5
-
6
- import type { GatewayProviderProps } from '../Provider.tsx'
7
- import { GatewayProvider } from '../Provider.tsx'
8
- import { GatewayStats } from './GatewayStats.tsx'
9
-
10
- const meta: Meta<GatewayProviderProps> = {
11
- title: 'provider/GatewayProvider',
12
- component: GatewayProvider,
13
-
14
- parameters: { docs: { description: { component: 'Wraps children with a `GatewayContext` populated from the given `gatewayName` and show the gateways from the default networks if available.' } } },
15
- }
16
-
17
- export default meta
18
-
19
- const account = await Account.random()
20
-
21
- /**
22
- * Convenience story that proves ALL default networks are represented.
23
- * Each row corresponds to one entry in DefaultNetworks.
24
- */
25
- const AllDefaultNetworks: StoryObj<GatewayProviderProps> = {
26
- name: 'All Default Networks',
27
- render: () => {
28
- return (
29
- <Stack gap={3} p={2}>
30
- {DefaultNetworks.map(network => (
31
- <GatewayStats key={network.id} id={network.id} url={network.url} account={account} />
32
- ))}
33
- </Stack>
34
- )
35
- },
36
- }
37
-
38
- export { AllDefaultNetworks }
@@ -1,43 +0,0 @@
1
- import { Alert, Stack } from '@mui/material'
2
- import type { Meta, StoryFn } from '@storybook/react-vite'
3
- import { isDefinedNotNull, isNull } from '@xylabs/sdk-js'
4
- import { IframeWalletWarningDecorator } from '@xyo-network/react-chain-shared'
5
- import type { GatewayName } from '@xyo-network/xl1-sdk'
6
-
7
- import { useClientFromWallet } from '../../../hooks/index.ts'
8
- import type { GatewayProviderProps } from '../Provider.tsx'
9
- import { GatewayProvider } from '../Provider.tsx'
10
- import { GatewayStats } from './GatewayStats.tsx'
11
-
12
- const meta: Meta<GatewayProviderProps> = {
13
- title: 'provider/GatewayProvider',
14
- component: GatewayProvider,
15
- decorators: [IframeWalletWarningDecorator],
16
-
17
- parameters: { docs: { description: { component: 'Wraps children with a `GatewayContext` populated from the given `gatewayName` and show the wallet-provided gateways if available.' } } },
18
- }
19
-
20
- export default meta
21
-
22
- const TestClientGateways: React.FC = () => {
23
- const { client } = useClientFromWallet()
24
- const foundClient = isDefinedNotNull(client)
25
- const notFoundClient = isNull(client)
26
- return (
27
- <Stack gap={3} p={2}>
28
- <Alert severity={foundClient ? 'success' : 'error'}>
29
- {foundClient ? 'Client found, displaying gateways:' : ''}
30
- {notFoundClient ? 'No client found. Please ensure your wallet is connected and has access to the current page.' : ''}
31
- </Alert>
32
- {Object.keys(client?.gateways || {}).map(id => (
33
- <GatewayStats key={id} id={id as GatewayName} />
34
- ))}
35
- </Stack>
36
- )
37
- }
38
-
39
- const Template: StoryFn = args => <TestClientGateways {...args} />
40
-
41
- const AllClientGateways = Template.bind({})
42
-
43
- export { AllClientGateways }
@@ -1,5 +0,0 @@
1
- import { useContextEx } from '@xylabs/react-shared'
2
-
3
- import { GatewayContext } from './context.ts'
4
-
5
- export const useProvidedGateway = (required = true) => useContextEx(GatewayContext, 'Gateway', required)
@@ -1,86 +0,0 @@
1
- import type { AccountInstance } from '@xyo-network/sdk-js'
2
- import type { GatewayName } from '@xyo-network/xl1-sdk'
3
- import { DefaultNetworks } from '@xyo-network/xl1-sdk'
4
- import type { PropsWithChildren } from 'react'
5
- import React, {
6
- startTransition,
7
- useCallback, useEffect, useMemo, useState,
8
- } from 'react'
9
-
10
- import { buildGateway } from '../../lib/index.ts'
11
- import type { ContextGatewayType } from '../../types/index.ts'
12
- import { InPageGatewaysContext } from './context.ts'
13
- import type { InPageGatewaysState } from './state.ts'
14
-
15
- export interface InPageGatewaysProviderProps extends PropsWithChildren {
16
- account?: AccountInstance
17
- }
18
-
19
- export const InPageGatewaysProvider: React.FC<InPageGatewaysProviderProps> = ({ account, children }) => {
20
- const [gateways, setGateways] = useState<Partial<Record<GatewayName, ContextGatewayType>>>({})
21
- const [errors, setErrors] = useState<Partial<Record<GatewayName, Error>>>({})
22
- const [previousAccount, setPreviousAccount] = useState<AccountInstance | undefined>(account)
23
-
24
- // This can come back once we homogenize the type for XyoGateway.
25
- // Right now, SimpleXyoClient takes XyoGatewayRunners but ideally it would take XyoGateway.
26
- // const clientInPage = useMemo(() => new SimpleXyoClient(gateways, {}), [gateways])
27
-
28
- const clearAll = useCallback(() => {
29
- setGateways({})
30
- setErrors({})
31
- }, [])
32
-
33
- if (previousAccount !== account) {
34
- clearAll()
35
- setPreviousAccount(account)
36
- }
37
-
38
- useEffect(() => {
39
- let cancelled = false
40
-
41
- const buildAll = async () => {
42
- const results = await Promise.allSettled(
43
- DefaultNetworks.map(async (network) => {
44
- const gateway = await buildGateway(network.id as GatewayName, account)
45
- return { id: network.id as GatewayName, gateway }
46
- }),
47
- )
48
-
49
- if (cancelled) return
50
-
51
- const nextGateways: Partial<Record<GatewayName, ContextGatewayType>> = {}
52
- const nextErrors: Partial<Record<GatewayName, Error>> = {}
53
-
54
- for (const [index, result] of results.entries()) {
55
- const networkId = DefaultNetworks[index].id as GatewayName
56
- if (result.status === 'fulfilled') {
57
- nextGateways[networkId] = result.value.gateway
58
- } else {
59
- nextErrors[networkId] = result.reason instanceof Error ? result.reason : new Error(String(result.reason))
60
- }
61
- }
62
-
63
- startTransition(() => {
64
- setGateways(nextGateways)
65
- setErrors(nextErrors)
66
- })
67
- }
68
-
69
- void buildAll()
70
- return () => {
71
- cancelled = true
72
- }
73
- }, [account])
74
-
75
- const value = useMemo(() => {
76
- const value: InPageGatewaysState = {
77
- clearAll,
78
- errors,
79
- gateways,
80
- provided: true,
81
- }
82
- return value
83
- }, [clearAll, errors, gateways])
84
-
85
- return <InPageGatewaysContext value={value}>{children}</InPageGatewaysContext>
86
- }
@@ -1,5 +0,0 @@
1
- import { createContextEx } from '@xylabs/react-shared'
2
-
3
- import type { InPageGatewaysState } from './state.ts'
4
-
5
- export const InPageGatewaysContext = createContextEx<InPageGatewaysState>()
@@ -1,4 +0,0 @@
1
- export * from './context.ts'
2
- export * from './Provider.tsx'
3
- export * from './state.ts'
4
- export * from './use.ts'
@@ -1,12 +0,0 @@
1
- import type { ContextExState } from '@xylabs/react-shared'
2
- import type { GatewayName } from '@xyo-network/xl1-sdk'
3
-
4
- import type { ContextGatewayType } from '../../types/index.ts'
5
-
6
- export interface InPageGatewaysStateFields {
7
- clearAll: () => void
8
- errors: Partial<Record<GatewayName, Error>>
9
- gateways: Partial<Record<GatewayName, ContextGatewayType>>
10
- }
11
-
12
- export type InPageGatewaysState = ContextExState<InPageGatewaysStateFields>
@@ -1,5 +0,0 @@
1
- import { useContextEx } from '@xylabs/react-shared'
2
-
3
- import { InPageGatewaysContext } from './context.ts'
4
-
5
- export const useProvidedInPageGateways = (required = true) => useContextEx(InPageGatewaysContext, 'InPageGateways', required)
@@ -1,3 +0,0 @@
1
- export * from './current-block/index.ts'
2
- export * from './gateway/index.ts'
3
- export * from './in-page-gateways/index.ts'
package/src/global.d.ts DELETED
@@ -1,9 +0,0 @@
1
- import type { XyoGlobal } from '@xyo-network/react-chain-model'
2
-
3
- export declare global {
4
- interface Window {
5
- xyo: XyoGlobal
6
- }
7
-
8
- var xyo: XyoGlobal
9
- }
@@ -1,18 +0,0 @@
1
- import type { Address, Hash } from '@xylabs/sdk-js'
2
- import type { AccountBalanceHistoryItem } from '@xyo-network/xl1-sdk'
3
-
4
- export type BalanceTransactionType = 'send' | 'receive'
5
-
6
- export interface AccountBalanceHistoryItemFormatted {
7
- amount: bigint
8
- blockHash: Hash
9
- blockNumber: number
10
- debug: AccountBalanceHistoryItem
11
- from: Address
12
- key: string
13
- timestamp: number
14
- to: Address
15
- transferHash: Hash
16
- txHash: Hash | undefined
17
- type: BalanceTransactionType
18
- }
@@ -1,47 +0,0 @@
1
- import type { Address, Hex } from '@xylabs/sdk-js'
2
- import { hexToBigInt } from '@xylabs/sdk-js'
3
- import { PayloadBuilder } from '@xyo-network/sdk-js'
4
- import type { AccountBalanceHistoryItem } from '@xyo-network/xl1-sdk'
5
-
6
- import type { AccountBalanceHistoryItemFormatted } from '../BalanceHistoryItemFormatted.ts'
7
-
8
- export const formatAccountBalanceHistory = async (address: Address, history: AccountBalanceHistoryItem[]): Promise<AccountBalanceHistoryItemFormatted[]> => {
9
- let results: AccountBalanceHistoryItemFormatted[] = []
10
- for (const item of history) {
11
- const [blockBw, txBw, transfer] = item
12
- const transferHash = await PayloadBuilder.hash(transfer)
13
- const blockHash = await PayloadBuilder.hash(blockBw)
14
- if (address === transfer.from) {
15
- for (const [to, amount] of Object.entries(transfer.transfers)) {
16
- results.push({
17
- amount: hexToBigInt(amount as Hex),
18
- blockHash,
19
- blockNumber: blockBw.block,
20
- from: transfer.from,
21
- timestamp: blockBw.$epoch,
22
- key: globalThis.crypto.randomUUID(),
23
- to: to as Address,
24
- transferHash,
25
- txHash: txBw?._hash,
26
- debug: item,
27
- type: 'send',
28
- })
29
- }
30
- } else {
31
- results.push({
32
- amount: hexToBigInt(transfer.transfers[address] as Hex),
33
- blockHash,
34
- blockNumber: blockBw.block,
35
- from: transfer.from,
36
- key: globalThis.crypto.randomUUID(),
37
- timestamp: blockBw.$epoch,
38
- to: address,
39
- transferHash,
40
- txHash: txBw?._hash,
41
- debug: item,
42
- type: 'receive',
43
- })
44
- }
45
- }
46
- return results
47
- }
@@ -1 +0,0 @@
1
- export * from './formatAccountBalanceHistory.ts'
@@ -1,3 +0,0 @@
1
- export * from './BalanceHistoryItemFormatted.ts'
2
- export * from './helpers/index.ts'
3
- export * from './useAccountBalanceHistory.ts'
@@ -1,51 +0,0 @@
1
- import { usePromise } from '@xylabs/react-promise'
2
- import {
3
- type Address,
4
- isUndefined,
5
- } from '@xylabs/sdk-js'
6
- import type {
7
- AccountBalanceHistoryItem, XL1BlockRange, XyoViewer,
8
- } from '@xyo-network/xl1-sdk'
9
-
10
- import { balanceForRange, findMinimumBlock } from '../../lib/index.ts'
11
- import { formatAccountBalanceHistory } from './helpers/index.ts'
12
-
13
- export const useAccountBalanceHistory = (address?: Address, viewer?: XyoViewer, maxPage = 10, blockRange?: XL1BlockRange, refresh?: number) => {
14
- return usePromise(async () => {
15
- if (isUndefined(viewer) || isUndefined(address)) return
16
-
17
- // Pagination Values
18
- let page = 1
19
- let lastBlock: number
20
- const pagedHistory: AccountBalanceHistoryItem[] = []
21
- const resolvedStartBlock = blockRange ? blockRange[0] : 0
22
-
23
- // Fetch first page to get starting lastBlock
24
- // If blockRange is provided, use that for the first fetch, otherwise the api will use [0, currentBlock]
25
- const history = await viewer.account.balance.accountBalanceHistory(address, blockRange ? { range: blockRange } : {})
26
- if (history.length > 0) {
27
- pagedHistory.push(...history)
28
- // Set lastBlock to one less than the lowest block in the first page
29
- lastBlock = findMinimumBlock(history)
30
- while (page < maxPage) {
31
- // Fetch next page
32
- const nextHistory = await viewer.account.balance.accountBalanceHistory(address, { range: [resolvedStartBlock, lastBlock] as XL1BlockRange })
33
- // Break if no more history
34
- if (nextHistory.length === 0) break
35
- // Update lastBlock and append to pagedHistory
36
- lastBlock = findMinimumBlock(nextHistory)
37
- pagedHistory.push(...nextHistory)
38
- // Increment page
39
- // Even if we are going to go over and break the loop, we still want to increment to show the answer was truncated
40
- page++
41
- }
42
- }
43
- const formattedHistory = await formatAccountBalanceHistory(address, pagedHistory)
44
-
45
- return {
46
- history: formattedHistory,
47
- balance: balanceForRange(address, pagedHistory),
48
- truncated: page >= maxPage,
49
- }
50
- }, [address, viewer, refresh, blockRange, maxPage])
51
- }
@@ -1,2 +0,0 @@
1
- /** @deprecated Import from `@xyo-network/react-chain-client` instead */
2
- export { findCaveat } from '@xyo-network/react-chain-client'
@@ -1 +0,0 @@
1
- export * from './findCaveat.ts'
@@ -1,3 +0,0 @@
1
- export * from './permissions/index.ts'
2
- export * from './useClientFromWallet.ts'
3
- export * from './useGatewayFromWallet.ts'
@@ -1,2 +0,0 @@
1
- export * from './usePermissions.ts'
2
- export * from './usePermissionsAccounts.ts'
@@ -1,2 +0,0 @@
1
- /** @deprecated Import from `@xyo-network/react-chain-client` instead */
2
- export { usePermissions } from '@xyo-network/react-chain-client'
@@ -1,2 +0,0 @@
1
- /** @deprecated Import from `@xyo-network/react-chain-client` instead */
2
- export { useAccountPermissions } from '@xyo-network/react-chain-client'
@@ -1,2 +0,0 @@
1
- /** @deprecated Import from `@xyo-network/react-chain-client` instead */
2
- export { useClient, useClientFromWallet } from '@xyo-network/react-chain-client'
@@ -1,2 +0,0 @@
1
- /** @deprecated Import from `@xyo-network/react-chain-client` instead */
2
- export { useGateway, useGatewayFromWallet } from '@xyo-network/react-chain-client'
@@ -1,3 +0,0 @@
1
- export * from './useNetwork.ts'
2
- export * from './useRunner.ts'
3
- export * from './useViewer.ts'
@@ -1,6 +0,0 @@
1
- import { useProvidedGateway } from '../../contexts/index.ts'
2
-
3
- export const useNetworkFromGateway = () => {
4
- const { defaultGateway } = useProvidedGateway()
5
- return defaultGateway?.connection?.network
6
- }
@@ -1,6 +0,0 @@
1
- import { useProvidedGateway } from '../../contexts/index.ts'
2
-
3
- export const useRunnerFromGateway = () => {
4
- const { defaultGateway } = useProvidedGateway()
5
- return defaultGateway?.connection?.runner
6
- }
@@ -1,6 +0,0 @@
1
- import { useProvidedGateway } from '../../contexts/index.ts'
2
-
3
- export const useViewerFromGateway = () => {
4
- const { defaultGateway } = useProvidedGateway()
5
- return defaultGateway?.connection?.viewer
6
- }
@@ -1,2 +0,0 @@
1
- /** @deprecated Import from `@xyo-network/react-chain-client` instead */
2
- export { getXyoClient, listenForClientInjection } from '@xyo-network/react-chain-client'
@@ -1,2 +0,0 @@
1
- export * from './getXyoClient.ts'
2
- export * from './transaction/index.ts'