@xyo-network/react-connected-accounts 2.66.3
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +165 -0
- package/README.md +13 -0
- package/dist/browser/components/ConnectedAccountsFlexbox.d.cts +4 -0
- package/dist/browser/components/ConnectedAccountsFlexbox.d.cts.map +1 -0
- package/dist/browser/components/ConnectedAccountsFlexbox.d.mts +4 -0
- package/dist/browser/components/ConnectedAccountsFlexbox.d.mts.map +1 -0
- package/dist/browser/components/ConnectedAccountsFlexbox.d.ts +4 -0
- package/dist/browser/components/ConnectedAccountsFlexbox.d.ts.map +1 -0
- package/dist/browser/components/index.d.cts +3 -0
- package/dist/browser/components/index.d.cts.map +1 -0
- package/dist/browser/components/index.d.mts +3 -0
- package/dist/browser/components/index.d.mts.map +1 -0
- package/dist/browser/components/index.d.ts +3 -0
- package/dist/browser/components/index.d.ts.map +1 -0
- package/dist/browser/components/wallet/index.d.cts +2 -0
- package/dist/browser/components/wallet/index.d.cts.map +1 -0
- package/dist/browser/components/wallet/index.d.mts +2 -0
- package/dist/browser/components/wallet/index.d.mts.map +1 -0
- package/dist/browser/components/wallet/index.d.ts +2 -0
- package/dist/browser/components/wallet/index.d.ts.map +1 -0
- package/dist/browser/components/wallet/lib/TableHeadData.d.cts +3 -0
- package/dist/browser/components/wallet/lib/TableHeadData.d.cts.map +1 -0
- package/dist/browser/components/wallet/lib/TableHeadData.d.mts +3 -0
- package/dist/browser/components/wallet/lib/TableHeadData.d.mts.map +1 -0
- package/dist/browser/components/wallet/lib/TableHeadData.d.ts +3 -0
- package/dist/browser/components/wallet/lib/TableHeadData.d.ts.map +1 -0
- package/dist/browser/components/wallet/lib/index.d.cts +2 -0
- package/dist/browser/components/wallet/lib/index.d.cts.map +1 -0
- package/dist/browser/components/wallet/lib/index.d.mts +2 -0
- package/dist/browser/components/wallet/lib/index.d.mts.map +1 -0
- package/dist/browser/components/wallet/lib/index.d.ts +2 -0
- package/dist/browser/components/wallet/lib/index.d.ts.map +1 -0
- package/dist/browser/components/wallet/table/ConnectedWalletsTable.d.cts +8 -0
- package/dist/browser/components/wallet/table/ConnectedWalletsTable.d.cts.map +1 -0
- package/dist/browser/components/wallet/table/ConnectedWalletsTable.d.mts +8 -0
- package/dist/browser/components/wallet/table/ConnectedWalletsTable.d.mts.map +1 -0
- package/dist/browser/components/wallet/table/ConnectedWalletsTable.d.ts +8 -0
- package/dist/browser/components/wallet/table/ConnectedWalletsTable.d.ts.map +1 -0
- package/dist/browser/components/wallet/table/ConnectedWalletsTableRow.d.cts +16 -0
- package/dist/browser/components/wallet/table/ConnectedWalletsTableRow.d.cts.map +1 -0
- package/dist/browser/components/wallet/table/ConnectedWalletsTableRow.d.mts +16 -0
- package/dist/browser/components/wallet/table/ConnectedWalletsTableRow.d.mts.map +1 -0
- package/dist/browser/components/wallet/table/ConnectedWalletsTableRow.d.ts +16 -0
- package/dist/browser/components/wallet/table/ConnectedWalletsTableRow.d.ts.map +1 -0
- package/dist/browser/components/wallet/table/index.d.cts +3 -0
- package/dist/browser/components/wallet/table/index.d.cts.map +1 -0
- package/dist/browser/components/wallet/table/index.d.mts +3 -0
- package/dist/browser/components/wallet/table/index.d.mts.map +1 -0
- package/dist/browser/components/wallet/table/index.d.ts +3 -0
- package/dist/browser/components/wallet/table/index.d.ts.map +1 -0
- package/dist/browser/hooks/index.d.cts +2 -0
- package/dist/browser/hooks/index.d.cts.map +1 -0
- package/dist/browser/hooks/index.d.mts +2 -0
- package/dist/browser/hooks/index.d.mts.map +1 -0
- package/dist/browser/hooks/index.d.ts +2 -0
- package/dist/browser/hooks/index.d.ts.map +1 -0
- package/dist/browser/hooks/useDetectWallets.d.cts +6 -0
- package/dist/browser/hooks/useDetectWallets.d.cts.map +1 -0
- package/dist/browser/hooks/useDetectWallets.d.mts +6 -0
- package/dist/browser/hooks/useDetectWallets.d.mts.map +1 -0
- package/dist/browser/hooks/useDetectWallets.d.ts +6 -0
- package/dist/browser/hooks/useDetectWallets.d.ts.map +1 -0
- package/dist/browser/index.cjs +188 -0
- package/dist/browser/index.cjs.map +1 -0
- package/dist/browser/index.d.cts +3 -0
- package/dist/browser/index.d.cts.map +1 -0
- package/dist/browser/index.d.mts +3 -0
- package/dist/browser/index.d.mts.map +1 -0
- package/dist/browser/index.d.ts +3 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +165 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/node/components/ConnectedAccountsFlexbox.d.cts +4 -0
- package/dist/node/components/ConnectedAccountsFlexbox.d.cts.map +1 -0
- package/dist/node/components/ConnectedAccountsFlexbox.d.mts +4 -0
- package/dist/node/components/ConnectedAccountsFlexbox.d.mts.map +1 -0
- package/dist/node/components/ConnectedAccountsFlexbox.d.ts +4 -0
- package/dist/node/components/ConnectedAccountsFlexbox.d.ts.map +1 -0
- package/dist/node/components/index.d.cts +3 -0
- package/dist/node/components/index.d.cts.map +1 -0
- package/dist/node/components/index.d.mts +3 -0
- package/dist/node/components/index.d.mts.map +1 -0
- package/dist/node/components/index.d.ts +3 -0
- package/dist/node/components/index.d.ts.map +1 -0
- package/dist/node/components/wallet/index.d.cts +2 -0
- package/dist/node/components/wallet/index.d.cts.map +1 -0
- package/dist/node/components/wallet/index.d.mts +2 -0
- package/dist/node/components/wallet/index.d.mts.map +1 -0
- package/dist/node/components/wallet/index.d.ts +2 -0
- package/dist/node/components/wallet/index.d.ts.map +1 -0
- package/dist/node/components/wallet/lib/TableHeadData.d.cts +3 -0
- package/dist/node/components/wallet/lib/TableHeadData.d.cts.map +1 -0
- package/dist/node/components/wallet/lib/TableHeadData.d.mts +3 -0
- package/dist/node/components/wallet/lib/TableHeadData.d.mts.map +1 -0
- package/dist/node/components/wallet/lib/TableHeadData.d.ts +3 -0
- package/dist/node/components/wallet/lib/TableHeadData.d.ts.map +1 -0
- package/dist/node/components/wallet/lib/index.d.cts +2 -0
- package/dist/node/components/wallet/lib/index.d.cts.map +1 -0
- package/dist/node/components/wallet/lib/index.d.mts +2 -0
- package/dist/node/components/wallet/lib/index.d.mts.map +1 -0
- package/dist/node/components/wallet/lib/index.d.ts +2 -0
- package/dist/node/components/wallet/lib/index.d.ts.map +1 -0
- package/dist/node/components/wallet/table/ConnectedWalletsTable.d.cts +8 -0
- package/dist/node/components/wallet/table/ConnectedWalletsTable.d.cts.map +1 -0
- package/dist/node/components/wallet/table/ConnectedWalletsTable.d.mts +8 -0
- package/dist/node/components/wallet/table/ConnectedWalletsTable.d.mts.map +1 -0
- package/dist/node/components/wallet/table/ConnectedWalletsTable.d.ts +8 -0
- package/dist/node/components/wallet/table/ConnectedWalletsTable.d.ts.map +1 -0
- package/dist/node/components/wallet/table/ConnectedWalletsTableRow.d.cts +16 -0
- package/dist/node/components/wallet/table/ConnectedWalletsTableRow.d.cts.map +1 -0
- package/dist/node/components/wallet/table/ConnectedWalletsTableRow.d.mts +16 -0
- package/dist/node/components/wallet/table/ConnectedWalletsTableRow.d.mts.map +1 -0
- package/dist/node/components/wallet/table/ConnectedWalletsTableRow.d.ts +16 -0
- package/dist/node/components/wallet/table/ConnectedWalletsTableRow.d.ts.map +1 -0
- package/dist/node/components/wallet/table/index.d.cts +3 -0
- package/dist/node/components/wallet/table/index.d.cts.map +1 -0
- package/dist/node/components/wallet/table/index.d.mts +3 -0
- package/dist/node/components/wallet/table/index.d.mts.map +1 -0
- package/dist/node/components/wallet/table/index.d.ts +3 -0
- package/dist/node/components/wallet/table/index.d.ts.map +1 -0
- package/dist/node/hooks/index.d.cts +2 -0
- package/dist/node/hooks/index.d.cts.map +1 -0
- package/dist/node/hooks/index.d.mts +2 -0
- package/dist/node/hooks/index.d.mts.map +1 -0
- package/dist/node/hooks/index.d.ts +2 -0
- package/dist/node/hooks/index.d.ts.map +1 -0
- package/dist/node/hooks/useDetectWallets.d.cts +6 -0
- package/dist/node/hooks/useDetectWallets.d.cts.map +1 -0
- package/dist/node/hooks/useDetectWallets.d.mts +6 -0
- package/dist/node/hooks/useDetectWallets.d.mts.map +1 -0
- package/dist/node/hooks/useDetectWallets.d.ts +6 -0
- package/dist/node/hooks/useDetectWallets.d.ts.map +1 -0
- package/dist/node/index.cjs +199 -0
- package/dist/node/index.cjs.map +1 -0
- package/dist/node/index.d.cts +3 -0
- package/dist/node/index.d.cts.map +1 -0
- package/dist/node/index.d.mts +3 -0
- package/dist/node/index.d.mts.map +1 -0
- package/dist/node/index.d.ts +3 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +168 -0
- package/dist/node/index.js.map +1 -0
- package/package.json +83 -0
- package/src/components/ConnectedAccountsFlexbox.stories.tsx +26 -0
- package/src/components/ConnectedAccountsFlexbox.tsx +27 -0
- package/src/components/index.ts +2 -0
- package/src/components/wallet/index.ts +1 -0
- package/src/components/wallet/lib/TableHeadData.ts +32 -0
- package/src/components/wallet/lib/index.ts +1 -0
- package/src/components/wallet/table/ConnectedWalletsTable.tsx +30 -0
- package/src/components/wallet/table/ConnectedWalletsTableRow.tsx +95 -0
- package/src/components/wallet/table/index.ts +2 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useDetectWallets.tsx +40 -0
- package/src/index.ts +2 -0
- package/typedoc.json +5 -0
package/package.json
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
{
|
2
|
+
"name": "@xyo-network/react-connected-accounts",
|
3
|
+
"author": {
|
4
|
+
"email": "support@xyo.network",
|
5
|
+
"name": "XYO Development Team",
|
6
|
+
"url": "https://xyo.network"
|
7
|
+
},
|
8
|
+
"bugs": {
|
9
|
+
"email": "support@xyo.network",
|
10
|
+
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/issues"
|
11
|
+
},
|
12
|
+
"dependencies": {
|
13
|
+
"@xylabs/react-crypto": "^3.0.33",
|
14
|
+
"@xylabs/react-flexbox": "3.0.33",
|
15
|
+
"@xyo-network/react-table": "~2.66.3"
|
16
|
+
},
|
17
|
+
"devDependencies": {
|
18
|
+
"@storybook/react": "^7.6.3",
|
19
|
+
"@xylabs/ts-scripts-yarn3": "^3.2.10",
|
20
|
+
"@xylabs/tsconfig-react": "^3.2.10",
|
21
|
+
"typescript": "^5.3.2"
|
22
|
+
},
|
23
|
+
"peerDependencies": {
|
24
|
+
"@mui/icons-material": "^5",
|
25
|
+
"@mui/material": "^5",
|
26
|
+
"@mui/styles": "^5",
|
27
|
+
"react": "^18.2.0",
|
28
|
+
"react-dom": "^18.2.0"
|
29
|
+
},
|
30
|
+
"description": "Common React library for all XYO projects that use React",
|
31
|
+
"docs": "dist/docs.json",
|
32
|
+
"exports": {
|
33
|
+
".": {
|
34
|
+
"node": {
|
35
|
+
"import": {
|
36
|
+
"types": "./dist/node/index.d.mts",
|
37
|
+
"default": "./dist/node/index.js"
|
38
|
+
},
|
39
|
+
"require": {
|
40
|
+
"types": "./dist/node/index.d.cts",
|
41
|
+
"default": "./dist/node/index.cjs"
|
42
|
+
}
|
43
|
+
},
|
44
|
+
"browser": {
|
45
|
+
"import": {
|
46
|
+
"types": "./dist/browser/index.d.mts",
|
47
|
+
"default": "./dist/browser/index.js"
|
48
|
+
},
|
49
|
+
"require": {
|
50
|
+
"types": "./dist/browser/index.d.cts",
|
51
|
+
"default": "./dist/browser/index.cjs"
|
52
|
+
}
|
53
|
+
},
|
54
|
+
"default": "./dist/browser/index.js"
|
55
|
+
},
|
56
|
+
"./package.json": "./package.json"
|
57
|
+
},
|
58
|
+
"main": "dist/browser/index.cjs",
|
59
|
+
"module": "dist/browser/index.js",
|
60
|
+
"homepage": "https://xyo.network",
|
61
|
+
"keywords": [
|
62
|
+
"xyo",
|
63
|
+
"utility",
|
64
|
+
"typescript",
|
65
|
+
"react"
|
66
|
+
],
|
67
|
+
"license": "LGPL-3.0-only",
|
68
|
+
"publishConfig": {
|
69
|
+
"access": "public"
|
70
|
+
},
|
71
|
+
"repository": {
|
72
|
+
"type": "git",
|
73
|
+
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js.git"
|
74
|
+
},
|
75
|
+
"scripts": {
|
76
|
+
"lint-pkg": "npmPkgJsonLint .",
|
77
|
+
"license": "yarn license-checker --exclude \"MIT, ISC, Apache-2.0, BSD, BSD-2-Clause, CC-BY-4.0, Unlicense, CC-BY-3.0, CC0-1.0\""
|
78
|
+
},
|
79
|
+
"sideEffects": false,
|
80
|
+
"types": "dist/browser/index.d.ts",
|
81
|
+
"version": "2.66.3",
|
82
|
+
"type": "module"
|
83
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
/* eslint-disable import/no-internal-modules */
|
2
|
+
import { Meta, StoryFn } from '@storybook/react'
|
3
|
+
|
4
|
+
import { ConnectedAccountsFlexbox } from './ConnectedAccountsFlexbox'
|
5
|
+
|
6
|
+
const StorybookEntry: Meta = {
|
7
|
+
argTypes: {},
|
8
|
+
component: ConnectedAccountsFlexbox,
|
9
|
+
parameters: {
|
10
|
+
docs: {
|
11
|
+
page: null,
|
12
|
+
},
|
13
|
+
},
|
14
|
+
title: 'connectedAccounts/Flexbox',
|
15
|
+
}
|
16
|
+
|
17
|
+
const Template: StoryFn<typeof ConnectedAccountsFlexbox> = (props) => {
|
18
|
+
return <ConnectedAccountsFlexbox {...props} />
|
19
|
+
}
|
20
|
+
|
21
|
+
const Default = Template.bind({})
|
22
|
+
|
23
|
+
export { Default }
|
24
|
+
|
25
|
+
// eslint-disable-next-line import/no-default-export
|
26
|
+
export default StorybookEntry
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { Typography, useTheme } from '@mui/material'
|
2
|
+
import { FlexBoxProps, FlexCol } from '@xylabs/react-flexbox'
|
3
|
+
|
4
|
+
import { useDetectedWallets } from '../hooks'
|
5
|
+
import { ConnectedWalletsTable } from './wallet'
|
6
|
+
|
7
|
+
export const ConnectedAccountsFlexbox: React.FC<FlexBoxProps> = (props) => {
|
8
|
+
const theme = useTheme()
|
9
|
+
|
10
|
+
const { totalConnectedAccounts, sortedWallets } = useDetectedWallets()
|
11
|
+
|
12
|
+
return (
|
13
|
+
<FlexCol alignItems="stretch" justifyContent="start" gap={2} {...props}>
|
14
|
+
<FlexCol alignItems="start">
|
15
|
+
<Typography variant={'h2'} sx={{ mb: 0.5 }}>
|
16
|
+
Detected Web3 Wallets
|
17
|
+
</Typography>
|
18
|
+
{totalConnectedAccounts ? (
|
19
|
+
<Typography variant={'subtitle1'} color={theme.palette.secondary.main} sx={{ opacity: 0.5 }}>
|
20
|
+
Total Connected Accounts: {totalConnectedAccounts}
|
21
|
+
</Typography>
|
22
|
+
) : null}
|
23
|
+
</FlexCol>
|
24
|
+
<ConnectedWalletsTable wallets={sortedWallets} />
|
25
|
+
</FlexCol>
|
26
|
+
)
|
27
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './table'
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import { TableHeadCell } from '@xyo-network/react-table'
|
2
|
+
|
3
|
+
export const WalletsTableHeadCells: TableHeadCell[] = [
|
4
|
+
{
|
5
|
+
disablePadding: false,
|
6
|
+
id: 'wallet',
|
7
|
+
label: 'Wallet',
|
8
|
+
numeric: false,
|
9
|
+
showOnMobile: true,
|
10
|
+
},
|
11
|
+
{
|
12
|
+
disablePadding: false,
|
13
|
+
id: 'chain',
|
14
|
+
label: 'Chain',
|
15
|
+
numeric: false,
|
16
|
+
showOnMobile: true,
|
17
|
+
},
|
18
|
+
{
|
19
|
+
disablePadding: false,
|
20
|
+
id: 'accounts',
|
21
|
+
label: 'Accounts',
|
22
|
+
numeric: true,
|
23
|
+
showOnMobile: true,
|
24
|
+
},
|
25
|
+
{
|
26
|
+
disablePadding: false,
|
27
|
+
id: 'actions',
|
28
|
+
label: 'Actions',
|
29
|
+
numeric: false,
|
30
|
+
showOnMobile: true,
|
31
|
+
},
|
32
|
+
]
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './TableHeadData'
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import { Table, TableBody, TableCell, TableHead, TableProps, TableRow } from '@mui/material'
|
2
|
+
import { EIP6963Connector } from '@xylabs/react-crypto'
|
3
|
+
|
4
|
+
import { WalletsTableHeadCells } from '../lib'
|
5
|
+
import { WalletConnectionsTableRow } from './ConnectedWalletsTableRow'
|
6
|
+
|
7
|
+
export interface ConnectedWalletsTableProps extends TableProps {
|
8
|
+
wallets?: EIP6963Connector[]
|
9
|
+
}
|
10
|
+
|
11
|
+
export const ConnectedWalletsTable: React.FC<ConnectedWalletsTableProps> = ({ wallets, ...props }) => {
|
12
|
+
return (
|
13
|
+
<Table {...props}>
|
14
|
+
<TableHead>
|
15
|
+
<TableRow>
|
16
|
+
{WalletsTableHeadCells.map(({ disablePadding, id, label, align, width }) => (
|
17
|
+
<TableCell align={align} key={id} padding={disablePadding ? 'none' : 'normal'} width={width ?? 'auto'}>
|
18
|
+
{label}
|
19
|
+
</TableCell>
|
20
|
+
))}
|
21
|
+
</TableRow>
|
22
|
+
</TableHead>
|
23
|
+
<TableBody>
|
24
|
+
{(wallets ?? []).map((wallet) => (
|
25
|
+
<WalletConnectionsTableRow wallet={wallet} key={wallet.providerInfo?.rdns} />
|
26
|
+
))}
|
27
|
+
</TableBody>
|
28
|
+
</Table>
|
29
|
+
)
|
30
|
+
}
|
@@ -0,0 +1,95 @@
|
|
1
|
+
import { Check } from '@mui/icons-material'
|
2
|
+
import { Button, TableCell, TableRow, TableRowProps, Tooltip, Typography, useTheme } from '@mui/material'
|
3
|
+
import { ConstrainedImage, EthWalletConnectorBase, useEthWallet } from '@xylabs/react-crypto'
|
4
|
+
import { FlexRow } from '@xylabs/react-flexbox'
|
5
|
+
import { ReactNode, useMemo } from 'react'
|
6
|
+
|
7
|
+
export interface WalletConnectionsTableRowInnerProps extends TableRowProps {
|
8
|
+
additionalAccounts?: string[]
|
9
|
+
chainName?: string
|
10
|
+
currentAccount?: string[]
|
11
|
+
icon?: string
|
12
|
+
name?: string
|
13
|
+
}
|
14
|
+
|
15
|
+
export const WalletConnectionsTableRowInner: React.FC<WalletConnectionsTableRowInnerProps> = ({
|
16
|
+
additionalAccounts,
|
17
|
+
currentAccount,
|
18
|
+
chainName,
|
19
|
+
icon,
|
20
|
+
name,
|
21
|
+
...props
|
22
|
+
}) => {
|
23
|
+
const theme = useTheme()
|
24
|
+
|
25
|
+
const totalAccounts = (additionalAccounts?.length ?? 0) + (currentAccount?.length ?? 0)
|
26
|
+
const connected = currentAccount?.length ?? 0 > 0
|
27
|
+
|
28
|
+
const Cells = useMemo(() => {
|
29
|
+
const TableCells: Record<string, ReactNode> = {
|
30
|
+
wallet: (
|
31
|
+
<TableCell key={1}>
|
32
|
+
<FlexRow gap={2} justifyContent="start">
|
33
|
+
<ConstrainedImage constrainedValue={theme.spacing(4)} src={icon} />
|
34
|
+
{name}
|
35
|
+
</FlexRow>
|
36
|
+
</TableCell>
|
37
|
+
),
|
38
|
+
// eslint-disable-next-line sort-keys-fix/sort-keys-fix
|
39
|
+
chain: <TableCell key={2}>{chainName}</TableCell>,
|
40
|
+
// eslint-disable-next-line sort-keys-fix/sort-keys-fix
|
41
|
+
accounts: (
|
42
|
+
<TableCell key={3}>
|
43
|
+
<Tooltip
|
44
|
+
sx={{ cursor: totalAccounts > 0 ? 'pointer' : 'auto' }}
|
45
|
+
title={[...(currentAccount ?? []), ...(additionalAccounts ?? [])].map((address, index) => (
|
46
|
+
<p key={index}>{address}</p>
|
47
|
+
))}
|
48
|
+
>
|
49
|
+
<Typography>{totalAccounts}</Typography>
|
50
|
+
</Tooltip>
|
51
|
+
</TableCell>
|
52
|
+
),
|
53
|
+
actions: (
|
54
|
+
<TableCell key={4}>
|
55
|
+
<FlexRow gap={2} justifyContent="start">
|
56
|
+
{connected ? (
|
57
|
+
<Typography sx={{ display: 'inline-flex', gap: 0.5 }}>
|
58
|
+
<Check />
|
59
|
+
Connected
|
60
|
+
</Typography>
|
61
|
+
) : (
|
62
|
+
<Button variant={'contained'}>Connect</Button>
|
63
|
+
)}
|
64
|
+
{connected ? (
|
65
|
+
<Button variant={'outlined'} color={'error'}>
|
66
|
+
Revoke
|
67
|
+
</Button>
|
68
|
+
) : null}
|
69
|
+
</FlexRow>
|
70
|
+
</TableCell>
|
71
|
+
),
|
72
|
+
}
|
73
|
+
return TableCells
|
74
|
+
}, [additionalAccounts, chainName, connected, currentAccount, icon, name, theme, totalAccounts])
|
75
|
+
|
76
|
+
return <TableRow {...props}>{Object.values(Cells).map((cell) => cell)}</TableRow>
|
77
|
+
}
|
78
|
+
|
79
|
+
export interface WalletConnectionsTableRow extends TableRowProps {
|
80
|
+
wallet: EthWalletConnectorBase
|
81
|
+
}
|
82
|
+
export const WalletConnectionsTableRow: React.FC<WalletConnectionsTableRow> = ({ wallet, ...props }) => {
|
83
|
+
const { currentAccount, additionalAccounts, chainName, providerInfo, providerName } = useEthWallet(wallet)
|
84
|
+
const currentAccountString = currentAccount?.toString()
|
85
|
+
return (
|
86
|
+
<WalletConnectionsTableRowInner
|
87
|
+
additionalAccounts={additionalAccounts}
|
88
|
+
currentAccount={currentAccountString ? [currentAccountString] : []}
|
89
|
+
chainName={chainName}
|
90
|
+
icon={providerInfo?.icon}
|
91
|
+
name={providerName}
|
92
|
+
{...props}
|
93
|
+
/>
|
94
|
+
)
|
95
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './useDetectWallets'
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import { AccountsChangedEventName, DiscoveredWallets, EIP6963Connector, useWalletDiscovery } from '@xylabs/react-crypto'
|
2
|
+
import { useEffect, useMemo, useState } from 'react'
|
3
|
+
|
4
|
+
const sortWallets = (wallets: DiscoveredWallets) =>
|
5
|
+
Object.values(wallets).reduce((acc, wallet) => {
|
6
|
+
wallet.allowedAccounts.length > 0 ? acc.unshift(wallet) : acc.push(wallet)
|
7
|
+
return acc
|
8
|
+
}, [] as EIP6963Connector[])
|
9
|
+
|
10
|
+
export const useDetectedWallets = () => {
|
11
|
+
const wallets = useWalletDiscovery()
|
12
|
+
const [refresh, setRefresh] = useState(0)
|
13
|
+
const [sortedWallets, setSortedWallets] = useState<EIP6963Connector[]>([])
|
14
|
+
|
15
|
+
useEffect(() => {
|
16
|
+
setSortedWallets(sortWallets(wallets))
|
17
|
+
}, [wallets, refresh])
|
18
|
+
|
19
|
+
/**
|
20
|
+
* Rely on custom events from the wallet base class to know when accounts are changed.
|
21
|
+
* This approach prevents the need to loop through all wallets and set up individual listeners.
|
22
|
+
*/
|
23
|
+
useEffect(() => {
|
24
|
+
const listener: (event: CustomEventInit) => void = () => {
|
25
|
+
setRefresh((refresh) => refresh + 1)
|
26
|
+
}
|
27
|
+
window.addEventListener(AccountsChangedEventName, listener)
|
28
|
+
|
29
|
+
return () => {
|
30
|
+
window.removeEventListener(AccountsChangedEventName, listener)
|
31
|
+
}
|
32
|
+
}, [wallets])
|
33
|
+
|
34
|
+
const totalConnectedAccounts = useMemo(
|
35
|
+
() => Object.values(sortedWallets).reduce((acc, wallet) => acc + wallet.allowedAccounts.length, 0),
|
36
|
+
[sortedWallets],
|
37
|
+
)
|
38
|
+
|
39
|
+
return { sortedWallets, totalConnectedAccounts }
|
40
|
+
}
|
package/src/index.ts
ADDED