@xyo-network/react-connected-accounts 7.5.8 → 7.5.12
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.
- package/dist/browser/classes/EnabledWallets.d.ts +5 -9
- package/dist/browser/classes/EnabledWallets.d.ts.map +1 -1
- package/dist/browser/hooks/useEnabledWallets.d.ts.map +1 -1
- package/dist/browser/index.mjs +377 -343
- package/dist/browser/index.mjs.map +1 -1
- package/package.json +61 -28
- package/src/classes/EnabledWallets.ts +0 -134
- package/src/classes/index.ts +0 -1
- package/src/components/ConnectedAccountsFlexbox.stories.tsx +0 -32
- package/src/components/ConnectedAccountsFlexbox.tsx +0 -43
- package/src/components/index.ts +0 -2
- package/src/components/wallet/dialogs/connect/CheckboxFormControl.tsx +0 -20
- package/src/components/wallet/dialogs/connect/Dialog.tsx +0 -55
- package/src/components/wallet/dialogs/connect/LinkedProvidersFlexbox.tsx +0 -36
- package/src/components/wallet/dialogs/connect/Permissions.tsx +0 -33
- package/src/components/wallet/dialogs/connect/index.ts +0 -2
- package/src/components/wallet/dialogs/index.ts +0 -2
- package/src/components/wallet/dialogs/revoke/Dialog.tsx +0 -44
- package/src/components/wallet/dialogs/revoke/index.ts +0 -1
- package/src/components/wallet/index.ts +0 -3
- package/src/components/wallet/lib/ActiveProvider.ts +0 -7
- package/src/components/wallet/lib/TableHeadData.ts +0 -39
- package/src/components/wallet/lib/index.ts +0 -2
- package/src/components/wallet/table/ConnectedWalletsTable.tsx +0 -62
- package/src/components/wallet/table/ConnectedWalletsTableRow.tsx +0 -77
- package/src/components/wallet/table/cells/Accounts.tsx +0 -26
- package/src/components/wallet/table/cells/Actions.tsx +0 -38
- package/src/components/wallet/table/cells/Cells.tsx +0 -16
- package/src/components/wallet/table/cells/ChainName.tsx +0 -8
- package/src/components/wallet/table/cells/State.tsx +0 -30
- package/src/components/wallet/table/cells/Wallet.tsx +0 -21
- package/src/components/wallet/table/cells/index.ts +0 -6
- package/src/components/wallet/table/cells/lib/ConnectedWalletTableCellProps.tsx +0 -17
- package/src/components/wallet/table/cells/lib/index.ts +0 -1
- package/src/components/wallet/table/hooks/index.ts +0 -1
- package/src/components/wallet/table/hooks/useActiveProviderDialogState.tsx +0 -21
- package/src/components/wallet/table/index.ts +0 -4
- package/src/hooks/index.ts +0 -2
- package/src/hooks/useDetectWallets.tsx +0 -29
- package/src/hooks/useEnabledWallets.tsx +0 -47
- package/src/img/index.ts +0 -2
- package/src/img/xyo-color-logo-text-only.svg +0 -1
- package/src/img/xyo-color-logo.svg +0 -1
- package/src/index.ts +0 -3
- package/src/types/global.d.ts +0 -1
- package/src/types/images.d.ts +0 -5
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type { DialogProps } from '@mui/material'
|
|
2
|
-
import {
|
|
3
|
-
Button, Dialog, DialogActions, DialogContent, DialogTitle,
|
|
4
|
-
} from '@mui/material'
|
|
5
|
-
import React from 'react'
|
|
6
|
-
|
|
7
|
-
import type { ActiveProvider } from '../../lib/index.ts'
|
|
8
|
-
import { CheckboxFormControl } from './CheckboxFormControl.tsx'
|
|
9
|
-
import { LinkedProvidersFlexbox } from './LinkedProvidersFlexbox.tsx'
|
|
10
|
-
import { WalletPermissionsFlexbox } from './Permissions.tsx'
|
|
11
|
-
|
|
12
|
-
export interface ConnectWalletDialogProps extends DialogProps {
|
|
13
|
-
activeProvider?: ActiveProvider
|
|
14
|
-
onIgnoreConnectDialog?: (checked: boolean) => void
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const ConnectWalletDialog: React.FC<ConnectWalletDialogProps> = ({
|
|
18
|
-
activeProvider, onIgnoreConnectDialog, ...props
|
|
19
|
-
}) => {
|
|
20
|
-
const { icon, providerName } = activeProvider ?? {}
|
|
21
|
-
|
|
22
|
-
const onConnect = async () => {
|
|
23
|
-
try {
|
|
24
|
-
await activeProvider?.connectWallet?.()
|
|
25
|
-
props.onClose?.({}, 'escapeKeyDown')
|
|
26
|
-
} catch (e) {
|
|
27
|
-
console.warn(`Error connecting to wallet: ${(e as Error).message}`)
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return (
|
|
32
|
-
<Dialog
|
|
33
|
-
slotProps={{ paper: { sx: { display: 'flex', gap: 4 } } }}
|
|
34
|
-
{...props}
|
|
35
|
-
>
|
|
36
|
-
<DialogTitle sx={{ textAlign: 'center' }}>XYO Wants To Access The Blockchain on Your Behalf</DialogTitle>
|
|
37
|
-
<DialogContent sx={{
|
|
38
|
-
display: 'flex', flexDirection: 'column', gap: 4,
|
|
39
|
-
}}
|
|
40
|
-
>
|
|
41
|
-
<LinkedProvidersFlexbox icon={icon} providerName={providerName} />
|
|
42
|
-
<WalletPermissionsFlexbox />
|
|
43
|
-
<CheckboxFormControl onCheckChanged={onIgnoreConnectDialog} />
|
|
44
|
-
</DialogContent>
|
|
45
|
-
<DialogActions>
|
|
46
|
-
<Button variant="outlined" onClick={() => props.onClose?.({}, 'escapeKeyDown')}>
|
|
47
|
-
Close
|
|
48
|
-
</Button>
|
|
49
|
-
<Button variant="contained" onClick={onConnect}>
|
|
50
|
-
Connect
|
|
51
|
-
</Button>
|
|
52
|
-
</DialogActions>
|
|
53
|
-
</Dialog>
|
|
54
|
-
)
|
|
55
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { SyncAlt } from '@mui/icons-material'
|
|
2
|
-
import { Typography } from '@mui/material'
|
|
3
|
-
import { ConstrainedImage } from '@xylabs/react-crypto'
|
|
4
|
-
import type { FlexBoxProps } from '@xylabs/react-flexbox'
|
|
5
|
-
import { FlexCol, FlexRow } from '@xylabs/react-flexbox'
|
|
6
|
-
import React from 'react'
|
|
7
|
-
|
|
8
|
-
import { xyoColorLogo } from '../../../../img/index.ts'
|
|
9
|
-
|
|
10
|
-
export interface LinkedProvidersFlexboxProps extends FlexBoxProps {
|
|
11
|
-
icon?: string
|
|
12
|
-
providerName?: string
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const LinkedProvidersFlexbox: React.FC<LinkedProvidersFlexboxProps> = ({
|
|
16
|
-
icon, providerName, ...props
|
|
17
|
-
}) => {
|
|
18
|
-
return (
|
|
19
|
-
<FlexRow gap={4} justifyContent="space-evenly" {...props}>
|
|
20
|
-
<FlexCol gap={0.5}>
|
|
21
|
-
<img alt="XYO Logo" src={xyoColorLogo} style={{ height: '48px' }} />
|
|
22
|
-
<Typography variant="subtitle1">XYO App</Typography>
|
|
23
|
-
</FlexCol>
|
|
24
|
-
<SyncAlt fontSize="large" />
|
|
25
|
-
<FlexCol gap={0.5}>
|
|
26
|
-
<ConstrainedImage
|
|
27
|
-
constrainedValue="48px"
|
|
28
|
-
src={icon}
|
|
29
|
-
alt={providerName}
|
|
30
|
-
style={{ height: '48px', maxWidth: '48px' }}
|
|
31
|
-
/>
|
|
32
|
-
<Typography variant="subtitle1">{providerName}</Typography>
|
|
33
|
-
</FlexCol>
|
|
34
|
-
</FlexRow>
|
|
35
|
-
)
|
|
36
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Link, Typography } from '@mui/material'
|
|
2
|
-
import type { FlexBoxProps } from '@xylabs/react-flexbox'
|
|
3
|
-
import { FlexCol } from '@xylabs/react-flexbox'
|
|
4
|
-
import React from 'react'
|
|
5
|
-
|
|
6
|
-
export interface WalletPermissionsFlexBoxProps extends FlexBoxProps {}
|
|
7
|
-
|
|
8
|
-
export const WalletPermissionsFlexbox: React.FC<WalletPermissionsFlexBoxProps> = (props) => {
|
|
9
|
-
return (
|
|
10
|
-
<FlexCol gap={4} {...props}>
|
|
11
|
-
<Typography fontWeight="bold" sx={{ textAlign: 'center' }}>
|
|
12
|
-
This will allow XYO to:
|
|
13
|
-
</Typography>
|
|
14
|
-
<ul>
|
|
15
|
-
<li>View your wallet account(s) and address(es)</li>
|
|
16
|
-
<li>Read-only access to browse the public blockchain(s) you select</li>
|
|
17
|
-
</ul>
|
|
18
|
-
<Typography variant="subtitle1" sx={{ textAlign: 'center' }}>
|
|
19
|
-
You control what accounts to share and what blockchains to view. You can see or revoke access via your wallet's settings at anytime. View
|
|
20
|
-
more on XYO's sovereign data philosophy
|
|
21
|
-
{' '}
|
|
22
|
-
<Link
|
|
23
|
-
href="https://cointelegraph.com/innovation-circle/decentralization-and-sovereignty-debunking-our-approach-to-digital-sovereignty"
|
|
24
|
-
sx={{ fontWeight: 'bold' }}
|
|
25
|
-
target="_blank"
|
|
26
|
-
>
|
|
27
|
-
here
|
|
28
|
-
</Link>
|
|
29
|
-
.
|
|
30
|
-
</Typography>
|
|
31
|
-
</FlexCol>
|
|
32
|
-
)
|
|
33
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { DialogProps } from '@mui/material'
|
|
2
|
-
import {
|
|
3
|
-
Button, Dialog, DialogActions, DialogContent, DialogTitle, Typography,
|
|
4
|
-
} from '@mui/material'
|
|
5
|
-
import { ConstrainedImage } from '@xylabs/react-crypto'
|
|
6
|
-
import { FlexRow } from '@xylabs/react-flexbox'
|
|
7
|
-
import React from 'react'
|
|
8
|
-
|
|
9
|
-
import type { ActiveProvider } from '../../lib/index.ts'
|
|
10
|
-
|
|
11
|
-
export interface RevokeWalletConnectionDialogProps extends DialogProps {
|
|
12
|
-
activeProvider?: ActiveProvider
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const RevokeWalletConnectionDialog: React.FC<RevokeWalletConnectionDialogProps> = ({ activeProvider, ...props }) => {
|
|
16
|
-
return (
|
|
17
|
-
<Dialog {...props}>
|
|
18
|
-
<FlexRow gap={2} justifyContent="start" pl={2}>
|
|
19
|
-
<ConstrainedImage src={activeProvider?.icon} constrainedValue="24px" />
|
|
20
|
-
<DialogTitle sx={{ pl: 0 }}>
|
|
21
|
-
Revoke
|
|
22
|
-
{activeProvider?.providerName}
|
|
23
|
-
{' '}
|
|
24
|
-
Access
|
|
25
|
-
</DialogTitle>
|
|
26
|
-
</FlexRow>
|
|
27
|
-
<DialogContent>
|
|
28
|
-
<Typography>
|
|
29
|
-
Revoking access to your wallet must be done from the wallet's browser extension. Wallets grant access to specific domains please
|
|
30
|
-
consult
|
|
31
|
-
{' '}
|
|
32
|
-
{activeProvider?.providerName}
|
|
33
|
-
's documentation on how to revoke access to this website:
|
|
34
|
-
</Typography>
|
|
35
|
-
<Typography>{globalThis.location.origin}</Typography>
|
|
36
|
-
</DialogContent>
|
|
37
|
-
<DialogActions>
|
|
38
|
-
<Button variant="contained" onClick={() => props.onClose?.({}, 'escapeKeyDown')}>
|
|
39
|
-
Close
|
|
40
|
-
</Button>
|
|
41
|
-
</DialogActions>
|
|
42
|
-
</Dialog>
|
|
43
|
-
)
|
|
44
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './Dialog.tsx'
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { 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
|
-
{
|
|
33
|
-
disablePadding: false,
|
|
34
|
-
id: 'enabled',
|
|
35
|
-
label: 'Enabled',
|
|
36
|
-
numeric: false,
|
|
37
|
-
showOnMobile: true,
|
|
38
|
-
},
|
|
39
|
-
]
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import type { TableProps } from '@mui/material'
|
|
2
|
-
import {
|
|
3
|
-
Table, TableBody, TableCell, TableHead, TableRow,
|
|
4
|
-
} from '@mui/material'
|
|
5
|
-
import type { EIP6963Connector } from '@xylabs/react-crypto'
|
|
6
|
-
import React, { useState } from 'react'
|
|
7
|
-
|
|
8
|
-
import { ConnectWalletDialog, RevokeWalletConnectionDialog } from '../dialogs/index.ts'
|
|
9
|
-
import type { ActiveProvider } from '../lib/index.ts'
|
|
10
|
-
import { WalletsTableHeadCells } from '../lib/index.ts'
|
|
11
|
-
import { WalletConnectionsTableRow } from './ConnectedWalletsTableRow.tsx'
|
|
12
|
-
import { useActiveProviderDialogState } from './hooks/index.ts'
|
|
13
|
-
|
|
14
|
-
export interface ConnectedWalletsTableProps extends TableProps {
|
|
15
|
-
ignoreConnectDialog?: boolean
|
|
16
|
-
onIgnoreConnectDialog?: (checked: boolean) => void
|
|
17
|
-
wallets?: EIP6963Connector[]
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const ConnectedWalletsTable: React.FC<ConnectedWalletsTableProps> = ({
|
|
21
|
-
ignoreConnectDialog, onIgnoreConnectDialog, wallets, ...props
|
|
22
|
-
}) => {
|
|
23
|
-
const [activeProvider, setActiveProvider] = useState<ActiveProvider>()
|
|
24
|
-
const [showConnect, onSetActiveProviderConnect, onConnectClose] = useActiveProviderDialogState(setActiveProvider)
|
|
25
|
-
const [showRevoke, onSetActiveProviderRevoke, onRevokeClose] = useActiveProviderDialogState(setActiveProvider)
|
|
26
|
-
|
|
27
|
-
return (
|
|
28
|
-
<>
|
|
29
|
-
<Table {...props}>
|
|
30
|
-
<TableHead>
|
|
31
|
-
<TableRow>
|
|
32
|
-
{WalletsTableHeadCells.map(({
|
|
33
|
-
disablePadding, id, label, align, width,
|
|
34
|
-
}) => (
|
|
35
|
-
<TableCell align={align} key={id} padding={disablePadding ? 'none' : 'normal'} width={width ?? 'auto'}>
|
|
36
|
-
{label}
|
|
37
|
-
</TableCell>
|
|
38
|
-
))}
|
|
39
|
-
</TableRow>
|
|
40
|
-
</TableHead>
|
|
41
|
-
<TableBody>
|
|
42
|
-
{(wallets ?? []).map(wallet => (
|
|
43
|
-
<WalletConnectionsTableRow
|
|
44
|
-
ignoreConnectDialog={ignoreConnectDialog}
|
|
45
|
-
key={wallet.providerInfo?.rdns}
|
|
46
|
-
onConnectClick={onSetActiveProviderConnect}
|
|
47
|
-
onRevoke={onSetActiveProviderRevoke}
|
|
48
|
-
wallet={wallet}
|
|
49
|
-
/>
|
|
50
|
-
))}
|
|
51
|
-
</TableBody>
|
|
52
|
-
</Table>
|
|
53
|
-
<RevokeWalletConnectionDialog open={showRevoke} onClose={onRevokeClose} activeProvider={activeProvider} />
|
|
54
|
-
<ConnectWalletDialog
|
|
55
|
-
activeProvider={activeProvider}
|
|
56
|
-
onClose={onConnectClose}
|
|
57
|
-
open={showConnect}
|
|
58
|
-
onIgnoreConnectDialog={onIgnoreConnectDialog}
|
|
59
|
-
/>
|
|
60
|
-
</>
|
|
61
|
-
)
|
|
62
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import type { TableRowProps } from '@mui/material'
|
|
2
|
-
import { TableRow } from '@mui/material'
|
|
3
|
-
import type { EthWalletConnectorBase } from '@xylabs/react-crypto'
|
|
4
|
-
import { useEthWallet } from '@xylabs/react-crypto'
|
|
5
|
-
import React, { useCallback, useMemo } from 'react'
|
|
6
|
-
|
|
7
|
-
import type { ActiveProvider } from '../lib/index.ts'
|
|
8
|
-
import { ConnectedWalletTableCells } from './cells/index.ts'
|
|
9
|
-
|
|
10
|
-
export interface WalletConnectionsTableRowProps extends TableRowProps {
|
|
11
|
-
ignoreConnectDialog?: boolean
|
|
12
|
-
onConnectClick?: (activeProvider: ActiveProvider) => void
|
|
13
|
-
onRevoke?: (activeProvider: ActiveProvider) => void
|
|
14
|
-
wallet: EthWalletConnectorBase
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const WalletConnectionsTableRow: React.FC<WalletConnectionsTableRowProps> = ({
|
|
18
|
-
ignoreConnectDialog,
|
|
19
|
-
onConnectClick,
|
|
20
|
-
onRevoke,
|
|
21
|
-
wallet,
|
|
22
|
-
...props
|
|
23
|
-
}) => {
|
|
24
|
-
const {
|
|
25
|
-
currentAccount: currentAccountFromWallet, additionalAccounts, chainName, connectWallet, providerInfo,
|
|
26
|
-
} = useEthWallet(wallet)
|
|
27
|
-
|
|
28
|
-
const currentAccount = currentAccountFromWallet?.toString() ? [currentAccountFromWallet.toString()] : []
|
|
29
|
-
const totalAccounts = (additionalAccounts?.length ?? 0) + (currentAccount?.length ?? 0)
|
|
30
|
-
const connected = !!(currentAccount?.length)
|
|
31
|
-
const {
|
|
32
|
-
icon, name, rdns,
|
|
33
|
-
} = useMemo(() => providerInfo ?? {
|
|
34
|
-
icon: undefined, name: undefined, rdns: undefined,
|
|
35
|
-
}, [providerInfo])
|
|
36
|
-
|
|
37
|
-
const activeProvider = useMemo<ActiveProvider>(
|
|
38
|
-
() => ({
|
|
39
|
-
connectWallet,
|
|
40
|
-
icon,
|
|
41
|
-
providerName: name,
|
|
42
|
-
}),
|
|
43
|
-
[connectWallet, icon, name],
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
const onRevokeLocal = useCallback(() => {
|
|
47
|
-
onRevoke?.(activeProvider)
|
|
48
|
-
}, [activeProvider, onRevoke])
|
|
49
|
-
|
|
50
|
-
const onConnectLocal = useCallback(async () => {
|
|
51
|
-
if (ignoreConnectDialog) {
|
|
52
|
-
await connectWallet?.()
|
|
53
|
-
} else {
|
|
54
|
-
onConnectClick?.(activeProvider)
|
|
55
|
-
}
|
|
56
|
-
}, [activeProvider, connectWallet, ignoreConnectDialog, onConnectClick])
|
|
57
|
-
|
|
58
|
-
return (
|
|
59
|
-
<TableRow {...props}>
|
|
60
|
-
{Object.values(ConnectedWalletTableCells).map((Cell, index) => (
|
|
61
|
-
<Cell
|
|
62
|
-
key={index}
|
|
63
|
-
additionalAccounts={additionalAccounts}
|
|
64
|
-
chainName={chainName}
|
|
65
|
-
connected={connected}
|
|
66
|
-
currentAccount={currentAccount}
|
|
67
|
-
icon={icon}
|
|
68
|
-
onConnect={onConnectLocal}
|
|
69
|
-
onRevoke={onRevokeLocal}
|
|
70
|
-
totalAccounts={totalAccounts}
|
|
71
|
-
walletName={name}
|
|
72
|
-
walletRdns={rdns}
|
|
73
|
-
/>
|
|
74
|
-
))}
|
|
75
|
-
</TableRow>
|
|
76
|
-
)
|
|
77
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
TableCell, Tooltip, Typography,
|
|
3
|
-
} from '@mui/material'
|
|
4
|
-
import React from 'react'
|
|
5
|
-
|
|
6
|
-
import type { ConnectedWalletTableCellProps } from './lib/index.ts'
|
|
7
|
-
|
|
8
|
-
export const ConnectedWalletsAccountsTableCell: React.FC<ConnectedWalletTableCellProps> = ({
|
|
9
|
-
additionalAccounts,
|
|
10
|
-
currentAccount,
|
|
11
|
-
totalAccounts,
|
|
12
|
-
tableCellProps,
|
|
13
|
-
}) => {
|
|
14
|
-
return (
|
|
15
|
-
<TableCell {...tableCellProps}>
|
|
16
|
-
<Tooltip
|
|
17
|
-
sx={{ cursor: totalAccounts > 0 ? 'pointer' : 'auto' }}
|
|
18
|
-
title={[...(currentAccount ?? []), ...(additionalAccounts ?? [])].map((address, index) => (
|
|
19
|
-
<p key={index}>{address}</p>
|
|
20
|
-
))}
|
|
21
|
-
>
|
|
22
|
-
<Typography>{totalAccounts}</Typography>
|
|
23
|
-
</Tooltip>
|
|
24
|
-
</TableCell>
|
|
25
|
-
)
|
|
26
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Check, InfoOutlined } from '@mui/icons-material'
|
|
2
|
-
import {
|
|
3
|
-
Button, IconButton, TableCell, Typography,
|
|
4
|
-
} from '@mui/material'
|
|
5
|
-
import { FlexRow } from '@xylabs/react-flexbox'
|
|
6
|
-
import React from 'react'
|
|
7
|
-
|
|
8
|
-
import type { ConnectedWalletTableCellProps } from './lib/index.ts'
|
|
9
|
-
|
|
10
|
-
export const ConnectedWalletsActionsTableCell: React.FC<ConnectedWalletTableCellProps> = ({
|
|
11
|
-
connected, onConnect, onRevoke, tableCellProps,
|
|
12
|
-
}) => {
|
|
13
|
-
return (
|
|
14
|
-
<TableCell {...tableCellProps}>
|
|
15
|
-
<FlexRow gap={2} justifyContent="start">
|
|
16
|
-
{connected
|
|
17
|
-
? (
|
|
18
|
-
<Typography sx={{ display: 'inline-flex', gap: 0.5 }}>
|
|
19
|
-
<Check />
|
|
20
|
-
Connected
|
|
21
|
-
</Typography>
|
|
22
|
-
)
|
|
23
|
-
: (
|
|
24
|
-
<Button variant="contained" onClick={onConnect}>
|
|
25
|
-
Connect
|
|
26
|
-
</Button>
|
|
27
|
-
)}
|
|
28
|
-
{connected
|
|
29
|
-
? (
|
|
30
|
-
<IconButton onClick={onRevoke}>
|
|
31
|
-
<InfoOutlined />
|
|
32
|
-
</IconButton>
|
|
33
|
-
)
|
|
34
|
-
: null}
|
|
35
|
-
</FlexRow>
|
|
36
|
-
</TableCell>
|
|
37
|
-
)
|
|
38
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { ComponentType } from 'react'
|
|
2
|
-
|
|
3
|
-
import { ConnectedWalletsAccountsTableCell } from './Accounts.tsx'
|
|
4
|
-
import { ConnectedWalletsActionsTableCell } from './Actions.tsx'
|
|
5
|
-
import { ConnectedWalletsChainNameTableCell } from './ChainName.tsx'
|
|
6
|
-
import type { ConnectedWalletTableCellProps } from './lib/index.ts'
|
|
7
|
-
import { ConnectedWalletState } from './State.tsx'
|
|
8
|
-
import { ConnectedWalletsWalletTableCell } from './Wallet.tsx'
|
|
9
|
-
|
|
10
|
-
export const ConnectedWalletTableCells: ComponentType<ConnectedWalletTableCellProps>[] = [
|
|
11
|
-
ConnectedWalletsWalletTableCell,
|
|
12
|
-
ConnectedWalletsChainNameTableCell,
|
|
13
|
-
ConnectedWalletsAccountsTableCell,
|
|
14
|
-
ConnectedWalletsActionsTableCell,
|
|
15
|
-
ConnectedWalletState,
|
|
16
|
-
]
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { TableCell } from '@mui/material'
|
|
2
|
-
import React from 'react'
|
|
3
|
-
|
|
4
|
-
import type { ConnectedWalletTableCellProps } from './lib/index.ts'
|
|
5
|
-
|
|
6
|
-
export const ConnectedWalletsChainNameTableCell: React.FC<ConnectedWalletTableCellProps> = ({ chainName, tableCellProps }) => {
|
|
7
|
-
return <TableCell {...tableCellProps}>{chainName}</TableCell>
|
|
8
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Switch, TableCell } from '@mui/material'
|
|
2
|
-
import { isDefined } from '@xylabs/sdk-js'
|
|
3
|
-
import type { ChangeEvent } from 'react'
|
|
4
|
-
import React, { useMemo } from 'react'
|
|
5
|
-
|
|
6
|
-
import { useEnabledWallets } from '../../../../hooks/index.ts'
|
|
7
|
-
import type { ConnectedWalletTableCellProps } from './lib/index.ts'
|
|
8
|
-
|
|
9
|
-
export const ConnectedWalletState: React.FC<ConnectedWalletTableCellProps> = ({
|
|
10
|
-
connected, walletRdns, tableCellProps,
|
|
11
|
-
}) => {
|
|
12
|
-
const {
|
|
13
|
-
disableWallet, enableWallet, wallets,
|
|
14
|
-
} = useEnabledWallets()
|
|
15
|
-
|
|
16
|
-
const enabled = useMemo(() => (isDefined(walletRdns) ? wallets[walletRdns]?.enabled : false), [wallets, walletRdns])
|
|
17
|
-
|
|
18
|
-
const handleClick = (event: ChangeEvent<HTMLInputElement>) => {
|
|
19
|
-
const checked = event.target?.checked
|
|
20
|
-
if (isDefined(walletRdns)) {
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
22
|
-
checked ? enableWallet?.(walletRdns) : disableWallet?.(walletRdns)
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return (
|
|
26
|
-
<TableCell {...tableCellProps}>
|
|
27
|
-
<Switch disabled={!connected} checked={connected && enabled} onChange={handleClick} />
|
|
28
|
-
</TableCell>
|
|
29
|
-
)
|
|
30
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { TableCell, useTheme } from '@mui/material'
|
|
2
|
-
import { ConstrainedImage } from '@xylabs/react-crypto'
|
|
3
|
-
import { FlexRow } from '@xylabs/react-flexbox'
|
|
4
|
-
import React from 'react'
|
|
5
|
-
|
|
6
|
-
import type { ConnectedWalletTableCellProps } from './lib/index.ts'
|
|
7
|
-
|
|
8
|
-
export const ConnectedWalletsWalletTableCell: React.FC<ConnectedWalletTableCellProps> = ({
|
|
9
|
-
icon, walletName, tableCellProps,
|
|
10
|
-
}) => {
|
|
11
|
-
const theme = useTheme()
|
|
12
|
-
|
|
13
|
-
return (
|
|
14
|
-
<TableCell {...tableCellProps}>
|
|
15
|
-
<FlexRow gap={2} justifyContent="start">
|
|
16
|
-
<ConstrainedImage constrainedValue={theme.spacing(4)} src={icon} />
|
|
17
|
-
{walletName}
|
|
18
|
-
</FlexRow>
|
|
19
|
-
</TableCell>
|
|
20
|
-
)
|
|
21
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { TableCellProps } from '@mui/material'
|
|
2
|
-
|
|
3
|
-
export interface ConnectedWalletTableCellProps {
|
|
4
|
-
additionalAccounts?: string[]
|
|
5
|
-
chainName?: string
|
|
6
|
-
connected?: boolean
|
|
7
|
-
currentAccount?: string[]
|
|
8
|
-
icon?: string
|
|
9
|
-
onConnect?: () => Promise<void>
|
|
10
|
-
onRevoke?: () => void
|
|
11
|
-
// Using a separate prop instead of extending the interface so we can safely pass all props to
|
|
12
|
-
// the individual components and let them pick off the ones they want.
|
|
13
|
-
tableCellProps?: TableCellProps
|
|
14
|
-
totalAccounts: number
|
|
15
|
-
walletName?: string
|
|
16
|
-
walletRdns?: string
|
|
17
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './ConnectedWalletTableCellProps.tsx'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useActiveProviderDialogState.tsx'
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { Dispatch, SetStateAction } from 'react'
|
|
2
|
-
import { useState } from 'react'
|
|
3
|
-
|
|
4
|
-
import type { ActiveProvider } from '../../lib/index.ts'
|
|
5
|
-
|
|
6
|
-
export const useActiveProviderDialogState = (
|
|
7
|
-
setActiveProvider: Dispatch<SetStateAction<ActiveProvider | undefined>>,
|
|
8
|
-
): [boolean, (activeProvider: ActiveProvider) => void, () => void] => {
|
|
9
|
-
const [show, setShow] = useState(false)
|
|
10
|
-
const onSetActiveProvider = (activeProvider: ActiveProvider) => {
|
|
11
|
-
setShow(true)
|
|
12
|
-
setActiveProvider(activeProvider)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const onClose = () => {
|
|
16
|
-
setShow(false)
|
|
17
|
-
setActiveProvider({})
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return [show, onSetActiveProvider, onClose]
|
|
21
|
-
}
|
package/src/hooks/index.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { DiscoveredWallets, EIP6963Connector } from '@xylabs/react-crypto'
|
|
2
|
-
import { useWalletDiscovery } from '@xylabs/react-crypto'
|
|
3
|
-
import { useMemo } from 'react'
|
|
4
|
-
|
|
5
|
-
const sortWallets = (wallets: DiscoveredWallets) => {
|
|
6
|
-
const result: EIP6963Connector[] = []
|
|
7
|
-
|
|
8
|
-
for (const wallet of Object.values(wallets)) {
|
|
9
|
-
if (wallet) {
|
|
10
|
-
if (wallet.allowedAccounts.length > 0)
|
|
11
|
-
result.unshift(wallet)
|
|
12
|
-
else
|
|
13
|
-
result.push(wallet)
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return result
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const useDetectedWallets = () => {
|
|
20
|
-
const wallets = useWalletDiscovery()
|
|
21
|
-
const sortedWallets = useMemo(() => sortWallets(wallets), [wallets])
|
|
22
|
-
|
|
23
|
-
const totalConnectedAccounts = useMemo(
|
|
24
|
-
() => Object.values(sortedWallets).reduce((acc, wallet) => acc + wallet.allowedAccounts.length, 0),
|
|
25
|
-
[sortedWallets],
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
return { sortedWallets, totalConnectedAccounts }
|
|
29
|
-
}
|