@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.
Files changed (156) hide show
  1. package/LICENSE +165 -0
  2. package/README.md +13 -0
  3. package/dist/browser/components/ConnectedAccountsFlexbox.d.cts +4 -0
  4. package/dist/browser/components/ConnectedAccountsFlexbox.d.cts.map +1 -0
  5. package/dist/browser/components/ConnectedAccountsFlexbox.d.mts +4 -0
  6. package/dist/browser/components/ConnectedAccountsFlexbox.d.mts.map +1 -0
  7. package/dist/browser/components/ConnectedAccountsFlexbox.d.ts +4 -0
  8. package/dist/browser/components/ConnectedAccountsFlexbox.d.ts.map +1 -0
  9. package/dist/browser/components/index.d.cts +3 -0
  10. package/dist/browser/components/index.d.cts.map +1 -0
  11. package/dist/browser/components/index.d.mts +3 -0
  12. package/dist/browser/components/index.d.mts.map +1 -0
  13. package/dist/browser/components/index.d.ts +3 -0
  14. package/dist/browser/components/index.d.ts.map +1 -0
  15. package/dist/browser/components/wallet/index.d.cts +2 -0
  16. package/dist/browser/components/wallet/index.d.cts.map +1 -0
  17. package/dist/browser/components/wallet/index.d.mts +2 -0
  18. package/dist/browser/components/wallet/index.d.mts.map +1 -0
  19. package/dist/browser/components/wallet/index.d.ts +2 -0
  20. package/dist/browser/components/wallet/index.d.ts.map +1 -0
  21. package/dist/browser/components/wallet/lib/TableHeadData.d.cts +3 -0
  22. package/dist/browser/components/wallet/lib/TableHeadData.d.cts.map +1 -0
  23. package/dist/browser/components/wallet/lib/TableHeadData.d.mts +3 -0
  24. package/dist/browser/components/wallet/lib/TableHeadData.d.mts.map +1 -0
  25. package/dist/browser/components/wallet/lib/TableHeadData.d.ts +3 -0
  26. package/dist/browser/components/wallet/lib/TableHeadData.d.ts.map +1 -0
  27. package/dist/browser/components/wallet/lib/index.d.cts +2 -0
  28. package/dist/browser/components/wallet/lib/index.d.cts.map +1 -0
  29. package/dist/browser/components/wallet/lib/index.d.mts +2 -0
  30. package/dist/browser/components/wallet/lib/index.d.mts.map +1 -0
  31. package/dist/browser/components/wallet/lib/index.d.ts +2 -0
  32. package/dist/browser/components/wallet/lib/index.d.ts.map +1 -0
  33. package/dist/browser/components/wallet/table/ConnectedWalletsTable.d.cts +8 -0
  34. package/dist/browser/components/wallet/table/ConnectedWalletsTable.d.cts.map +1 -0
  35. package/dist/browser/components/wallet/table/ConnectedWalletsTable.d.mts +8 -0
  36. package/dist/browser/components/wallet/table/ConnectedWalletsTable.d.mts.map +1 -0
  37. package/dist/browser/components/wallet/table/ConnectedWalletsTable.d.ts +8 -0
  38. package/dist/browser/components/wallet/table/ConnectedWalletsTable.d.ts.map +1 -0
  39. package/dist/browser/components/wallet/table/ConnectedWalletsTableRow.d.cts +16 -0
  40. package/dist/browser/components/wallet/table/ConnectedWalletsTableRow.d.cts.map +1 -0
  41. package/dist/browser/components/wallet/table/ConnectedWalletsTableRow.d.mts +16 -0
  42. package/dist/browser/components/wallet/table/ConnectedWalletsTableRow.d.mts.map +1 -0
  43. package/dist/browser/components/wallet/table/ConnectedWalletsTableRow.d.ts +16 -0
  44. package/dist/browser/components/wallet/table/ConnectedWalletsTableRow.d.ts.map +1 -0
  45. package/dist/browser/components/wallet/table/index.d.cts +3 -0
  46. package/dist/browser/components/wallet/table/index.d.cts.map +1 -0
  47. package/dist/browser/components/wallet/table/index.d.mts +3 -0
  48. package/dist/browser/components/wallet/table/index.d.mts.map +1 -0
  49. package/dist/browser/components/wallet/table/index.d.ts +3 -0
  50. package/dist/browser/components/wallet/table/index.d.ts.map +1 -0
  51. package/dist/browser/hooks/index.d.cts +2 -0
  52. package/dist/browser/hooks/index.d.cts.map +1 -0
  53. package/dist/browser/hooks/index.d.mts +2 -0
  54. package/dist/browser/hooks/index.d.mts.map +1 -0
  55. package/dist/browser/hooks/index.d.ts +2 -0
  56. package/dist/browser/hooks/index.d.ts.map +1 -0
  57. package/dist/browser/hooks/useDetectWallets.d.cts +6 -0
  58. package/dist/browser/hooks/useDetectWallets.d.cts.map +1 -0
  59. package/dist/browser/hooks/useDetectWallets.d.mts +6 -0
  60. package/dist/browser/hooks/useDetectWallets.d.mts.map +1 -0
  61. package/dist/browser/hooks/useDetectWallets.d.ts +6 -0
  62. package/dist/browser/hooks/useDetectWallets.d.ts.map +1 -0
  63. package/dist/browser/index.cjs +188 -0
  64. package/dist/browser/index.cjs.map +1 -0
  65. package/dist/browser/index.d.cts +3 -0
  66. package/dist/browser/index.d.cts.map +1 -0
  67. package/dist/browser/index.d.mts +3 -0
  68. package/dist/browser/index.d.mts.map +1 -0
  69. package/dist/browser/index.d.ts +3 -0
  70. package/dist/browser/index.d.ts.map +1 -0
  71. package/dist/browser/index.js +165 -0
  72. package/dist/browser/index.js.map +1 -0
  73. package/dist/node/components/ConnectedAccountsFlexbox.d.cts +4 -0
  74. package/dist/node/components/ConnectedAccountsFlexbox.d.cts.map +1 -0
  75. package/dist/node/components/ConnectedAccountsFlexbox.d.mts +4 -0
  76. package/dist/node/components/ConnectedAccountsFlexbox.d.mts.map +1 -0
  77. package/dist/node/components/ConnectedAccountsFlexbox.d.ts +4 -0
  78. package/dist/node/components/ConnectedAccountsFlexbox.d.ts.map +1 -0
  79. package/dist/node/components/index.d.cts +3 -0
  80. package/dist/node/components/index.d.cts.map +1 -0
  81. package/dist/node/components/index.d.mts +3 -0
  82. package/dist/node/components/index.d.mts.map +1 -0
  83. package/dist/node/components/index.d.ts +3 -0
  84. package/dist/node/components/index.d.ts.map +1 -0
  85. package/dist/node/components/wallet/index.d.cts +2 -0
  86. package/dist/node/components/wallet/index.d.cts.map +1 -0
  87. package/dist/node/components/wallet/index.d.mts +2 -0
  88. package/dist/node/components/wallet/index.d.mts.map +1 -0
  89. package/dist/node/components/wallet/index.d.ts +2 -0
  90. package/dist/node/components/wallet/index.d.ts.map +1 -0
  91. package/dist/node/components/wallet/lib/TableHeadData.d.cts +3 -0
  92. package/dist/node/components/wallet/lib/TableHeadData.d.cts.map +1 -0
  93. package/dist/node/components/wallet/lib/TableHeadData.d.mts +3 -0
  94. package/dist/node/components/wallet/lib/TableHeadData.d.mts.map +1 -0
  95. package/dist/node/components/wallet/lib/TableHeadData.d.ts +3 -0
  96. package/dist/node/components/wallet/lib/TableHeadData.d.ts.map +1 -0
  97. package/dist/node/components/wallet/lib/index.d.cts +2 -0
  98. package/dist/node/components/wallet/lib/index.d.cts.map +1 -0
  99. package/dist/node/components/wallet/lib/index.d.mts +2 -0
  100. package/dist/node/components/wallet/lib/index.d.mts.map +1 -0
  101. package/dist/node/components/wallet/lib/index.d.ts +2 -0
  102. package/dist/node/components/wallet/lib/index.d.ts.map +1 -0
  103. package/dist/node/components/wallet/table/ConnectedWalletsTable.d.cts +8 -0
  104. package/dist/node/components/wallet/table/ConnectedWalletsTable.d.cts.map +1 -0
  105. package/dist/node/components/wallet/table/ConnectedWalletsTable.d.mts +8 -0
  106. package/dist/node/components/wallet/table/ConnectedWalletsTable.d.mts.map +1 -0
  107. package/dist/node/components/wallet/table/ConnectedWalletsTable.d.ts +8 -0
  108. package/dist/node/components/wallet/table/ConnectedWalletsTable.d.ts.map +1 -0
  109. package/dist/node/components/wallet/table/ConnectedWalletsTableRow.d.cts +16 -0
  110. package/dist/node/components/wallet/table/ConnectedWalletsTableRow.d.cts.map +1 -0
  111. package/dist/node/components/wallet/table/ConnectedWalletsTableRow.d.mts +16 -0
  112. package/dist/node/components/wallet/table/ConnectedWalletsTableRow.d.mts.map +1 -0
  113. package/dist/node/components/wallet/table/ConnectedWalletsTableRow.d.ts +16 -0
  114. package/dist/node/components/wallet/table/ConnectedWalletsTableRow.d.ts.map +1 -0
  115. package/dist/node/components/wallet/table/index.d.cts +3 -0
  116. package/dist/node/components/wallet/table/index.d.cts.map +1 -0
  117. package/dist/node/components/wallet/table/index.d.mts +3 -0
  118. package/dist/node/components/wallet/table/index.d.mts.map +1 -0
  119. package/dist/node/components/wallet/table/index.d.ts +3 -0
  120. package/dist/node/components/wallet/table/index.d.ts.map +1 -0
  121. package/dist/node/hooks/index.d.cts +2 -0
  122. package/dist/node/hooks/index.d.cts.map +1 -0
  123. package/dist/node/hooks/index.d.mts +2 -0
  124. package/dist/node/hooks/index.d.mts.map +1 -0
  125. package/dist/node/hooks/index.d.ts +2 -0
  126. package/dist/node/hooks/index.d.ts.map +1 -0
  127. package/dist/node/hooks/useDetectWallets.d.cts +6 -0
  128. package/dist/node/hooks/useDetectWallets.d.cts.map +1 -0
  129. package/dist/node/hooks/useDetectWallets.d.mts +6 -0
  130. package/dist/node/hooks/useDetectWallets.d.mts.map +1 -0
  131. package/dist/node/hooks/useDetectWallets.d.ts +6 -0
  132. package/dist/node/hooks/useDetectWallets.d.ts.map +1 -0
  133. package/dist/node/index.cjs +199 -0
  134. package/dist/node/index.cjs.map +1 -0
  135. package/dist/node/index.d.cts +3 -0
  136. package/dist/node/index.d.cts.map +1 -0
  137. package/dist/node/index.d.mts +3 -0
  138. package/dist/node/index.d.mts.map +1 -0
  139. package/dist/node/index.d.ts +3 -0
  140. package/dist/node/index.d.ts.map +1 -0
  141. package/dist/node/index.js +168 -0
  142. package/dist/node/index.js.map +1 -0
  143. package/package.json +83 -0
  144. package/src/components/ConnectedAccountsFlexbox.stories.tsx +26 -0
  145. package/src/components/ConnectedAccountsFlexbox.tsx +27 -0
  146. package/src/components/index.ts +2 -0
  147. package/src/components/wallet/index.ts +1 -0
  148. package/src/components/wallet/lib/TableHeadData.ts +32 -0
  149. package/src/components/wallet/lib/index.ts +1 -0
  150. package/src/components/wallet/table/ConnectedWalletsTable.tsx +30 -0
  151. package/src/components/wallet/table/ConnectedWalletsTableRow.tsx +95 -0
  152. package/src/components/wallet/table/index.ts +2 -0
  153. package/src/hooks/index.ts +1 -0
  154. package/src/hooks/useDetectWallets.tsx +40 -0
  155. package/src/index.ts +2 -0
  156. 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,2 @@
1
+ export * from './ConnectedAccountsFlexbox'
2
+ export * from './wallet'
@@ -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,2 @@
1
+ export * from './ConnectedWalletsTable'
2
+ export * from './ConnectedWalletsTableRow'
@@ -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
@@ -0,0 +1,2 @@
1
+ export * from './components'
2
+ export * from './hooks'
package/typedoc.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "$schema": "https://typedoc.org/schema.json",
3
+ "entryPoints": ["src/index.ts"],
4
+ "tsconfig": "./tsconfig.typedoc.json"
5
+ }