@xyo-network/react-wallet 2.55.8 → 2.55.10
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/cjs/components/SeedPhrase/DefaultSeedPhrase.js +2 -4
- package/dist/cjs/components/SeedPhrase/DefaultSeedPhrase.js.map +1 -1
- package/dist/cjs/components/WalletAccountSelect/Select.js +5 -5
- package/dist/cjs/components/WalletAccountSelect/Select.js.map +1 -1
- package/dist/cjs/components/WalletAccountSelect/WalletInfo.js +47 -0
- package/dist/cjs/components/WalletAccountSelect/WalletInfo.js.map +1 -0
- package/dist/cjs/contexts/SeedPhrase/Provider.js +3 -5
- package/dist/cjs/contexts/SeedPhrase/Provider.js.map +1 -1
- package/dist/cjs/contexts/Wallet/Provider.js +4 -4
- package/dist/cjs/contexts/Wallet/Provider.js.map +1 -1
- package/dist/cjs/contexts/Wallet/lib/WalletPath.js +17 -5
- package/dist/cjs/contexts/Wallet/lib/WalletPath.js.map +1 -1
- package/dist/cjs/contexts/Wallet/use.js +17 -11
- package/dist/cjs/contexts/Wallet/use.js.map +1 -1
- package/dist/cjs/contexts/index.js +0 -1
- package/dist/cjs/contexts/index.js.map +1 -1
- package/dist/cjs/hooks/useAccount.js +13 -17
- package/dist/cjs/hooks/useAccount.js.map +1 -1
- package/dist/cjs/hooks/useWallet.js +3 -3
- package/dist/cjs/hooks/useWallet.js.map +1 -1
- package/dist/cjs/hooks/useWallets.js +2 -2
- package/dist/cjs/hooks/useWallets.js.map +1 -1
- package/dist/docs.json +874 -920
- package/dist/esm/components/SeedPhrase/DefaultSeedPhrase.js +2 -4
- package/dist/esm/components/SeedPhrase/DefaultSeedPhrase.js.map +1 -1
- package/dist/esm/components/WalletAccountSelect/Select.js +6 -6
- package/dist/esm/components/WalletAccountSelect/Select.js.map +1 -1
- package/dist/esm/components/WalletAccountSelect/WalletInfo.js +35 -0
- package/dist/esm/components/WalletAccountSelect/WalletInfo.js.map +1 -0
- package/dist/esm/contexts/SeedPhrase/Provider.js +3 -5
- package/dist/esm/contexts/SeedPhrase/Provider.js.map +1 -1
- package/dist/esm/contexts/Wallet/Provider.js +4 -4
- package/dist/esm/contexts/Wallet/Provider.js.map +1 -1
- package/dist/esm/contexts/Wallet/lib/WalletPath.js +15 -4
- package/dist/esm/contexts/Wallet/lib/WalletPath.js.map +1 -1
- package/dist/esm/contexts/Wallet/use.js +15 -10
- package/dist/esm/contexts/Wallet/use.js.map +1 -1
- package/dist/esm/contexts/index.js +0 -1
- package/dist/esm/contexts/index.js.map +1 -1
- package/dist/esm/hooks/useAccount.js +12 -16
- package/dist/esm/hooks/useAccount.js.map +1 -1
- package/dist/esm/hooks/useWallet.js +3 -3
- package/dist/esm/hooks/useWallet.js.map +1 -1
- package/dist/esm/hooks/useWallets.js +1 -1
- package/dist/esm/hooks/useWallets.js.map +1 -1
- package/dist/types/components/SeedPhrase/DefaultSeedPhrase.d.ts.map +1 -1
- package/dist/types/components/WalletAccountSelect/WalletInfo.d.ts +18 -0
- package/dist/types/components/WalletAccountSelect/WalletInfo.d.ts.map +1 -0
- package/dist/types/contexts/SeedPhrase/Provider.d.ts.map +1 -1
- package/dist/types/contexts/Wallet/Provider.d.ts.map +1 -1
- package/dist/types/contexts/Wallet/State.d.ts +2 -2
- package/dist/types/contexts/Wallet/State.d.ts.map +1 -1
- package/dist/types/contexts/Wallet/lib/WalletPath.d.ts +12 -4
- package/dist/types/contexts/Wallet/lib/WalletPath.d.ts.map +1 -1
- package/dist/types/contexts/Wallet/use.d.ts +4 -3
- package/dist/types/contexts/Wallet/use.d.ts.map +1 -1
- package/dist/types/contexts/index.d.ts +0 -1
- package/dist/types/contexts/index.d.ts.map +1 -1
- package/dist/types/hooks/useAccount.d.ts +5 -2
- package/dist/types/hooks/useAccount.d.ts.map +1 -1
- package/dist/types/hooks/useWallet.d.ts.map +1 -1
- package/package.json +17 -16
- package/src/components/SeedPhrase/DefaultSeedPhrase.tsx +2 -4
- package/src/components/SeedPhrase/dialog/SeedPhraseDialog.stories.tsx +2 -4
- package/src/components/WalletAccountSelect/Select.tsx +6 -6
- package/src/components/WalletAccountSelect/WalletAccountSelect.stories.tsx +9 -0
- package/src/components/WalletAccountSelect/WalletInfo.tsx +100 -0
- package/src/contexts/SeedPhrase/Provider.tsx +3 -5
- package/src/contexts/Wallet/Provider.tsx +4 -4
- package/src/contexts/Wallet/State.ts +2 -2
- package/src/contexts/Wallet/lib/WalletPath.ts +16 -4
- package/src/contexts/Wallet/use.ts +18 -12
- package/src/contexts/index.ts +0 -1
- package/src/hooks/useAccount.tsx +17 -16
- package/src/hooks/useWallet.tsx +3 -3
- package/src/hooks/useWallets.tsx +1 -1
- package/dist/cjs/contexts/Account/Context.js +0 -6
- package/dist/cjs/contexts/Account/Context.js.map +0 -1
- package/dist/cjs/contexts/Account/MemoryProvider.js +0 -14
- package/dist/cjs/contexts/Account/MemoryProvider.js.map +0 -1
- package/dist/cjs/contexts/Account/State.js +0 -3
- package/dist/cjs/contexts/Account/State.js.map +0 -1
- package/dist/cjs/contexts/Account/index.js +0 -8
- package/dist/cjs/contexts/Account/index.js.map +0 -1
- package/dist/cjs/contexts/Account/use.js +0 -11
- package/dist/cjs/contexts/Account/use.js.map +0 -1
- package/dist/esm/contexts/Account/Context.js +0 -3
- package/dist/esm/contexts/Account/Context.js.map +0 -1
- package/dist/esm/contexts/Account/MemoryProvider.js +0 -8
- package/dist/esm/contexts/Account/MemoryProvider.js.map +0 -1
- package/dist/esm/contexts/Account/State.js +0 -2
- package/dist/esm/contexts/Account/State.js.map +0 -1
- package/dist/esm/contexts/Account/index.js +0 -5
- package/dist/esm/contexts/Account/index.js.map +0 -1
- package/dist/esm/contexts/Account/use.js +0 -7
- package/dist/esm/contexts/Account/use.js.map +0 -1
- package/dist/types/contexts/Account/Context.d.ts +0 -4
- package/dist/types/contexts/Account/Context.d.ts.map +0 -1
- package/dist/types/contexts/Account/MemoryProvider.d.ts +0 -8
- package/dist/types/contexts/Account/MemoryProvider.d.ts.map +0 -1
- package/dist/types/contexts/Account/State.d.ts +0 -8
- package/dist/types/contexts/Account/State.d.ts.map +0 -1
- package/dist/types/contexts/Account/index.d.ts +0 -5
- package/dist/types/contexts/Account/index.d.ts.map +0 -1
- package/dist/types/contexts/Account/use.d.ts +0 -2
- package/dist/types/contexts/Account/use.d.ts.map +0 -1
- package/src/contexts/Account/Context.ts +0 -5
- package/src/contexts/Account/MemoryProvider.tsx +0 -15
- package/src/contexts/Account/State.ts +0 -8
- package/src/contexts/Account/index.ts +0 -4
- package/src/contexts/Account/use.ts +0 -8
package/package.json
CHANGED
|
@@ -10,21 +10,22 @@
|
|
|
10
10
|
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/issues"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@scure/bip39": "^1.2.0",
|
|
14
13
|
"@xylabs/eth-address": "^2.9.1",
|
|
15
|
-
"@xylabs/react-button": "^2.17.
|
|
16
|
-
"@xylabs/react-crypto": "^2.17.
|
|
17
|
-
"@xylabs/react-flexbox": "^2.17.
|
|
18
|
-
"@xylabs/react-number-status": "^2.17.
|
|
19
|
-
"@xylabs/react-
|
|
20
|
-
"@xylabs/react-
|
|
21
|
-
"@
|
|
22
|
-
"@xyo-network/account
|
|
23
|
-
"@xyo-network/
|
|
24
|
-
"@xyo-network/
|
|
25
|
-
"@xyo-network/
|
|
26
|
-
"@xyo-network/react-
|
|
27
|
-
"@xyo-network/
|
|
14
|
+
"@xylabs/react-button": "^2.17.6",
|
|
15
|
+
"@xylabs/react-crypto": "^2.17.6",
|
|
16
|
+
"@xylabs/react-flexbox": "^2.17.6",
|
|
17
|
+
"@xylabs/react-number-status": "^2.17.6",
|
|
18
|
+
"@xylabs/react-promise": "^2.17.6",
|
|
19
|
+
"@xylabs/react-select": "^2.17.6",
|
|
20
|
+
"@xylabs/react-shared": "^2.17.6",
|
|
21
|
+
"@xyo-network/account": "^2.63.10",
|
|
22
|
+
"@xyo-network/account-model": "^2.63.10",
|
|
23
|
+
"@xyo-network/bip39": "^2.63.8",
|
|
24
|
+
"@xyo-network/core": "^2.63.10",
|
|
25
|
+
"@xyo-network/react-address-render": "^2.55.10",
|
|
26
|
+
"@xyo-network/react-network": "^2.55.10",
|
|
27
|
+
"@xyo-network/react-shared": "^2.55.10",
|
|
28
|
+
"@xyo-network/wallet-model": "^2.63.10"
|
|
28
29
|
},
|
|
29
30
|
"peerDependencies": {
|
|
30
31
|
"@mui/icons-material": "^5",
|
|
@@ -40,7 +41,7 @@
|
|
|
40
41
|
"@storybook/react": "^7.0.23",
|
|
41
42
|
"@xylabs/ts-scripts-yarn3": "^2.17.17",
|
|
42
43
|
"@xylabs/tsconfig-react": "^2.17.17",
|
|
43
|
-
"@xyo-network/react-storybook": "^2.55.
|
|
44
|
+
"@xyo-network/react-storybook": "^2.55.10",
|
|
44
45
|
"typescript": "^5.1.3"
|
|
45
46
|
},
|
|
46
47
|
"browser": "dist/esm/index.js",
|
|
@@ -85,5 +86,5 @@
|
|
|
85
86
|
},
|
|
86
87
|
"sideEffects": false,
|
|
87
88
|
"types": "dist/types/index.d.ts",
|
|
88
|
-
"version": "2.55.
|
|
89
|
+
"version": "2.55.10"
|
|
89
90
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { Alert, AlertTitle, Snackbar } from '@mui/material'
|
|
2
|
-
import { generateMnemonic } from '@scure/bip39'
|
|
3
|
-
// eslint-disable-next-line import/no-internal-modules
|
|
4
|
-
import { wordlist } from '@scure/bip39/wordlists/english'
|
|
5
2
|
import { WithChildren } from '@xylabs/react-shared'
|
|
3
|
+
import { generateMnemonic, wordlists } from '@xyo-network/bip39'
|
|
6
4
|
import { useEffect, useState } from 'react'
|
|
7
5
|
|
|
8
6
|
export interface DefaultSeedPhraseProps extends WithChildren {
|
|
@@ -15,7 +13,7 @@ export const DefaultSeedPhrase: React.FC<DefaultSeedPhraseProps> = ({ changeSeed
|
|
|
15
13
|
|
|
16
14
|
useEffect(() => {
|
|
17
15
|
if (!seedPhrase) {
|
|
18
|
-
const mnemonic = generateMnemonic(
|
|
16
|
+
const mnemonic = generateMnemonic(wordlists.english, 256)
|
|
19
17
|
changeSeedPhrase?.(mnemonic)
|
|
20
18
|
setShowSnackBar(true)
|
|
21
19
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { Button, Typography } from '@mui/material'
|
|
2
|
-
import { generateMnemonic } from '@scure/bip39'
|
|
3
|
-
// eslint-disable-next-line import/no-internal-modules
|
|
4
|
-
import { wordlist } from '@scure/bip39/wordlists/english'
|
|
5
2
|
import { Meta, StoryFn } from '@storybook/react'
|
|
6
3
|
import { FlexCol } from '@xylabs/react-flexbox'
|
|
4
|
+
import { generateMnemonic, wordlists } from '@xyo-network/bip39'
|
|
7
5
|
import { useState } from 'react'
|
|
8
6
|
|
|
9
7
|
import { SeedPhraseDialog } from './SeedPhraseDialog'
|
|
@@ -15,7 +13,7 @@ export default {
|
|
|
15
13
|
} as Meta
|
|
16
14
|
|
|
17
15
|
const Template: StoryFn<typeof SeedPhraseDialog> = (props) => {
|
|
18
|
-
const mnemonic = generateMnemonic(
|
|
16
|
+
const mnemonic = generateMnemonic(wordlists.english, 256)
|
|
19
17
|
const [seedPhrase, setSeedPhrase] = useState(mnemonic)
|
|
20
18
|
const [open, setOpen] = useState(false)
|
|
21
19
|
return (
|
|
@@ -3,7 +3,7 @@ import { SelectEx } from '@xylabs/react-select'
|
|
|
3
3
|
import { AddressRenderRowBox, AddressRenderRowBoxPropsBase } from '@xyo-network/react-address-render'
|
|
4
4
|
|
|
5
5
|
import { useWalletContext } from '../../contexts'
|
|
6
|
-
import { useAccount } from '../../hooks'
|
|
6
|
+
import { useAccount, useWallet } from '../../hooks'
|
|
7
7
|
|
|
8
8
|
type SharedAddressRenderRowBoxProps = Pick<AddressRenderRowBoxPropsBase, 'iconOnly' | 'iconSize' | 'icons' | 'showFavorite'>
|
|
9
9
|
|
|
@@ -26,17 +26,17 @@ export const WalletAccountSelect: React.FC<WalletAccountSelectProps> = ({
|
|
|
26
26
|
size,
|
|
27
27
|
...props
|
|
28
28
|
}) => {
|
|
29
|
-
const { activeAccountIndex = 0, setActiveAccountIndex,
|
|
30
|
-
const disabled = !
|
|
29
|
+
const { activeAccountIndex = 0, setActiveAccountIndex, coinTypeWallet } = useWalletContext()
|
|
30
|
+
const disabled = !coinTypeWallet || activeAccountIndex === undefined
|
|
31
31
|
|
|
32
32
|
return (
|
|
33
33
|
<>
|
|
34
|
-
{
|
|
34
|
+
{coinTypeWallet ? (
|
|
35
35
|
<SelectEx
|
|
36
36
|
disabled={disabled}
|
|
37
37
|
renderValue={(selected) => {
|
|
38
38
|
const Item: React.FC = () => {
|
|
39
|
-
const [account] =
|
|
39
|
+
const [account] = useWallet({ path: selected.toString(), wallet: coinTypeWallet })
|
|
40
40
|
const customName = account ? addressNames[account.address] : undefined
|
|
41
41
|
const favorite = account && account.address in addressNames
|
|
42
42
|
return (
|
|
@@ -61,7 +61,7 @@ export const WalletAccountSelect: React.FC<WalletAccountSelectProps> = ({
|
|
|
61
61
|
>
|
|
62
62
|
{arrayRange(maxAccounts).map((index) => {
|
|
63
63
|
const Item: React.FC = () => {
|
|
64
|
-
const [account] = useAccount({
|
|
64
|
+
const [account] = useAccount({ index, wallet: coinTypeWallet })
|
|
65
65
|
const customName = account ? addressNames[account.address] : undefined
|
|
66
66
|
const favorite = account && account.address in addressNames
|
|
67
67
|
return (
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { Stack } from '@mui/material'
|
|
1
2
|
import { Meta, StoryFn } from '@storybook/react'
|
|
2
3
|
import { DefaultSeedPhrase } from '@xyo-network/react-storybook'
|
|
3
4
|
|
|
4
5
|
import { WalletProvider } from '../../contexts'
|
|
5
6
|
import { useWallet } from '../../hooks'
|
|
6
7
|
import { WalletAccountSelect } from './Select'
|
|
8
|
+
import { AccountInfo, CoinTypeWalletInfo, RootWalletInfo, SelectedWalletInfo, WalletInfo } from './WalletInfo'
|
|
7
9
|
|
|
8
10
|
const StorybookEntry = {
|
|
9
11
|
argTypes: {},
|
|
@@ -25,6 +27,13 @@ const WithWalletTemplate: StoryFn<typeof WalletAccountSelect> = (args) => {
|
|
|
25
27
|
return (
|
|
26
28
|
<WalletProvider rootWallet={wallet}>
|
|
27
29
|
<WalletAccountSelect {...args} />
|
|
30
|
+
<Stack direction="row" position="absolute" right={0} top={0} bgcolor="black" height={16}>
|
|
31
|
+
<RootWalletInfo />
|
|
32
|
+
<CoinTypeWalletInfo />
|
|
33
|
+
<SelectedWalletInfo />
|
|
34
|
+
<WalletInfo />
|
|
35
|
+
<AccountInfo />
|
|
36
|
+
</Stack>
|
|
28
37
|
</WalletProvider>
|
|
29
38
|
)
|
|
30
39
|
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import LoadingIcon from '@mui/icons-material/Circle'
|
|
2
|
+
import ErrorIcon from '@mui/icons-material/ErrorOutlined'
|
|
3
|
+
import { FlexBoxProps, FlexCol } from '@xylabs/react-flexbox'
|
|
4
|
+
import { Identicon } from '@xylabs/react-identicon'
|
|
5
|
+
import { QuickTipButton } from '@xylabs/react-quick-tip-button'
|
|
6
|
+
import { AccountInstance } from '@xyo-network/account-model'
|
|
7
|
+
|
|
8
|
+
import { useCoinTypeWallet, useRootWallet, useSelectedWalletAccount } from '../../contexts'
|
|
9
|
+
import { useAccount, useWallet } from '../../hooks'
|
|
10
|
+
|
|
11
|
+
export interface WalletErrorProps {
|
|
12
|
+
error?: Error
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const WalletError: React.FC<WalletErrorProps> = ({ error }) => {
|
|
16
|
+
return error ? (
|
|
17
|
+
<div>
|
|
18
|
+
<ErrorIcon style={{ fontSize: '12px', position: 'absolute' }} color="error" />
|
|
19
|
+
<QuickTipButton
|
|
20
|
+
size="small"
|
|
21
|
+
style={{ color: '#ffffff00', fontSize: '12px', padding: 0, position: 'absolute' }}
|
|
22
|
+
hoverText={error.message}
|
|
23
|
+
disableDialog
|
|
24
|
+
/>
|
|
25
|
+
</div>
|
|
26
|
+
) : null
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface WalletIdenticonProps {
|
|
30
|
+
account?: AccountInstance
|
|
31
|
+
name: string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const WalletIdenticon: React.FC<WalletIdenticonProps> = ({ account, name }) => {
|
|
35
|
+
return (
|
|
36
|
+
<div style={{ width: 20 }}>
|
|
37
|
+
{account ? (
|
|
38
|
+
<Identicon size={8} value={account.address} style={{ position: 'absolute', right: 2, top: 2 }} />
|
|
39
|
+
) : (
|
|
40
|
+
<LoadingIcon style={{ fontSize: '10px', padding: 0, position: 'absolute', right: 2, top: 2 }} color="disabled" />
|
|
41
|
+
)}
|
|
42
|
+
<QuickTipButton
|
|
43
|
+
size="small"
|
|
44
|
+
style={{ color: '#ffffff00', fontSize: '12px', padding: 0, position: 'absolute' }}
|
|
45
|
+
hoverText={`${name ?? ''}: ${account?.address ?? 'no address'}`}
|
|
46
|
+
disableDialog
|
|
47
|
+
/>
|
|
48
|
+
</div>
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const CoinTypeWalletInfo: React.FC<FlexBoxProps> = (props) => {
|
|
53
|
+
const [wallet, error] = useCoinTypeWallet()
|
|
54
|
+
return (
|
|
55
|
+
<FlexCol width={12} {...props}>
|
|
56
|
+
{error ? null : <WalletIdenticon name="CoinType" account={wallet} />}
|
|
57
|
+
<WalletError error={error} />
|
|
58
|
+
</FlexCol>
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const RootWalletInfo: React.FC<FlexBoxProps> = (props) => {
|
|
63
|
+
const [wallet, error] = useRootWallet()
|
|
64
|
+
return (
|
|
65
|
+
<FlexCol width={12} {...props}>
|
|
66
|
+
{error ? null : <WalletIdenticon name="Root" account={wallet} />}
|
|
67
|
+
<WalletError error={error} />
|
|
68
|
+
</FlexCol>
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const SelectedWalletInfo: React.FC<FlexBoxProps> = (props) => {
|
|
73
|
+
const [wallet, error] = useSelectedWalletAccount()
|
|
74
|
+
return (
|
|
75
|
+
<FlexCol width={12} {...props}>
|
|
76
|
+
{error ? null : <WalletIdenticon name="Selected" account={wallet} />}
|
|
77
|
+
<WalletError error={error} />
|
|
78
|
+
</FlexCol>
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const WalletInfo: React.FC<FlexBoxProps> = (props) => {
|
|
83
|
+
const [wallet, error] = useWallet()
|
|
84
|
+
return (
|
|
85
|
+
<FlexCol width={12} {...props}>
|
|
86
|
+
{error ? null : <WalletIdenticon name="Wallet" account={wallet} />}
|
|
87
|
+
<WalletError error={error} />
|
|
88
|
+
</FlexCol>
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export const AccountInfo: React.FC<FlexBoxProps> = (props) => {
|
|
93
|
+
const [account, error] = useAccount()
|
|
94
|
+
return (
|
|
95
|
+
<FlexCol width={12} {...props}>
|
|
96
|
+
{error ? null : <WalletIdenticon name="Account" account={account} />}
|
|
97
|
+
<WalletError error={error} />
|
|
98
|
+
</FlexCol>
|
|
99
|
+
)
|
|
100
|
+
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { generateMnemonic, validateMnemonic } from '@scure/bip39'
|
|
2
|
-
// eslint-disable-next-line import/no-internal-modules
|
|
3
|
-
import { wordlist } from '@scure/bip39/wordlists/english'
|
|
4
1
|
import { WithChildren } from '@xylabs/react-shared'
|
|
2
|
+
import { generateMnemonic, validateMnemonic, wordlists } from '@xyo-network/bip39'
|
|
5
3
|
import { useEffect, useMemo, useState } from 'react'
|
|
6
4
|
|
|
7
5
|
import { SeedPhraseContext } from './Context'
|
|
@@ -42,7 +40,7 @@ export const SeedPhraseProvider: React.FC<SeedPhraseProviderProps> = ({
|
|
|
42
40
|
}, [seedPhrase, open, setPhrase])
|
|
43
41
|
|
|
44
42
|
const handleGenerate = () => {
|
|
45
|
-
const mnemonic = generateMnemonic(
|
|
43
|
+
const mnemonic = generateMnemonic(wordlists.english, 256)
|
|
46
44
|
setPhrase?.(mnemonic)
|
|
47
45
|
setOverwriteWarning?.(false)
|
|
48
46
|
}
|
|
@@ -69,7 +67,7 @@ export const SeedPhraseProvider: React.FC<SeedPhraseProviderProps> = ({
|
|
|
69
67
|
if (!passedPhrase) {
|
|
70
68
|
return null
|
|
71
69
|
}
|
|
72
|
-
return validateMnemonic(passedPhrase,
|
|
70
|
+
return validateMnemonic(passedPhrase, wordlists.english)
|
|
73
71
|
}
|
|
74
72
|
|
|
75
73
|
const validSeedPhrase = useMemo(() => validate?.(seedPhrase), [seedPhrase])
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { usePromise } from '@xylabs/react-promise'
|
|
1
2
|
import { WithChildren } from '@xylabs/react-shared'
|
|
2
|
-
import { usePromise } from '@xyo-network/react-shared'
|
|
3
3
|
import { WalletInstance } from '@xyo-network/wallet-model'
|
|
4
4
|
import { useEffect, useState } from 'react'
|
|
5
5
|
|
|
@@ -27,7 +27,7 @@ export const WalletProvider: React.FC<WithChildren<WalletProviderProps>> = ({
|
|
|
27
27
|
}
|
|
28
28
|
}, [defaultActiveAccountIndex])
|
|
29
29
|
|
|
30
|
-
const [
|
|
30
|
+
const [coinTypeWallet] = usePromise(async () => {
|
|
31
31
|
// ensure the wallet has the proper base
|
|
32
32
|
if (rootWallet) {
|
|
33
33
|
if (!rootWallet?.path.includes(basePath)) {
|
|
@@ -42,7 +42,7 @@ export const WalletProvider: React.FC<WithChildren<WalletProviderProps>> = ({
|
|
|
42
42
|
}
|
|
43
43
|
}, [basePath, rootWallet])
|
|
44
44
|
|
|
45
|
-
const [activeAccount] = usePromise(() =>
|
|
45
|
+
const [activeAccount] = usePromise(() => coinTypeWallet?.derivePath(activeAccountIndex.toString()), [coinTypeWallet, activeAccountIndex])
|
|
46
46
|
|
|
47
47
|
return (
|
|
48
48
|
<WalletContext.Provider
|
|
@@ -50,7 +50,7 @@ export const WalletProvider: React.FC<WithChildren<WalletProviderProps>> = ({
|
|
|
50
50
|
activeAccount,
|
|
51
51
|
activeAccountIndex,
|
|
52
52
|
basePath,
|
|
53
|
-
|
|
53
|
+
coinTypeWallet,
|
|
54
54
|
provided: true,
|
|
55
55
|
rootWallet,
|
|
56
56
|
setActiveAccountIndex,
|
|
@@ -9,8 +9,8 @@ export interface WalletContextState extends ContextExState {
|
|
|
9
9
|
activeAccountIndex?: number
|
|
10
10
|
/** Base path from which the wallet was derived */
|
|
11
11
|
basePath?: string
|
|
12
|
-
/** The derived wallet being used */
|
|
13
|
-
|
|
12
|
+
/** The coin_type derived wallet being used */
|
|
13
|
+
coinTypeWallet?: WalletInstance
|
|
14
14
|
/** The root wallet being used */
|
|
15
15
|
rootWallet?: WalletInstance
|
|
16
16
|
/** Set currently selected index */
|
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
export const
|
|
2
|
-
|
|
1
|
+
export const Bip44 = {
|
|
2
|
+
base: 'm',
|
|
3
|
+
coin_type: {
|
|
4
|
+
/* https://github.com/satoshilabs/slips/blob/master/slip-0044.md */
|
|
5
|
+
bitcoin: "0'",
|
|
6
|
+
bitcoinTestnet: "1'",
|
|
7
|
+
ether: "60'",
|
|
8
|
+
etherClassic: "61'",
|
|
9
|
+
},
|
|
10
|
+
purpose: "44'",
|
|
11
|
+
}
|
|
3
12
|
|
|
4
|
-
export const WalletRootPath =
|
|
5
|
-
|
|
13
|
+
export const WalletRootPath = `${Bip44.base}/${Bip44.purpose}/${Bip44.coin_type.ether}`
|
|
14
|
+
|
|
15
|
+
export const ethereumAccountPath = (index: number, hardened = true) => {
|
|
16
|
+
return `${WalletRootPath}/${index}${hardened ? "'" : ''}/0`
|
|
17
|
+
}
|
|
@@ -1,27 +1,33 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { usePromise } from '@xylabs/react-promise'
|
|
2
|
+
import { useContextEx } from '@xyo-network/react-shared'
|
|
2
3
|
import { WalletInstance } from '@xyo-network/wallet-model'
|
|
3
4
|
|
|
4
5
|
import { WalletContext } from './Context'
|
|
5
6
|
|
|
6
7
|
export const useWalletContext = (required = true) => {
|
|
7
|
-
return useContextEx(WalletContext, '
|
|
8
|
+
return useContextEx(WalletContext, 'Wallet', required)
|
|
8
9
|
}
|
|
9
10
|
|
|
10
|
-
export const
|
|
11
|
-
const {
|
|
12
|
-
return [
|
|
11
|
+
export const useCoinTypeWallet = (required = true): [WalletInstance | undefined, Error | undefined] => {
|
|
12
|
+
const { coinTypeWallet } = useWalletContext(required)
|
|
13
|
+
return [coinTypeWallet, undefined]
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
export const
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
return [account]
|
|
16
|
+
export const useRootWallet = (required = true): [WalletInstance | undefined, Error | undefined] => {
|
|
17
|
+
const { rootWallet } = useWalletContext(required)
|
|
18
|
+
return [rootWallet, undefined]
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export const
|
|
21
|
+
export const useIndexedWalletFromContext = (index: number, required = true): [WalletInstance | undefined, Error | undefined] => {
|
|
22
|
+
const [coinTypeWallet] = useCoinTypeWallet(required)
|
|
23
|
+
const [wallet] = usePromise(() => coinTypeWallet?.derivePath(index.toString()), [coinTypeWallet, index])
|
|
24
|
+
return [wallet, undefined]
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const useSelectedWalletAccount = (required = true): [WalletInstance | undefined, Error | undefined] => {
|
|
22
28
|
const { activeAccountIndex } = useWalletContext(required)
|
|
23
29
|
//we pass in 0 as default since we can not call the hook optionally,
|
|
24
30
|
//we resolve this false result by checking whether activeAccountIndex is defined before returning it
|
|
25
|
-
const [account] = useIndexedWalletFromContext(activeAccountIndex ?? 0)
|
|
26
|
-
return [activeAccountIndex !== undefined ? account : undefined]
|
|
31
|
+
const [account] = useIndexedWalletFromContext(activeAccountIndex ?? 0, required)
|
|
32
|
+
return [activeAccountIndex !== undefined ? account : undefined, undefined]
|
|
27
33
|
}
|
package/src/contexts/index.ts
CHANGED
package/src/hooks/useAccount.tsx
CHANGED
|
@@ -1,39 +1,40 @@
|
|
|
1
|
+
import { usePromise } from '@xylabs/react-promise'
|
|
1
2
|
import { AccountInstance } from '@xyo-network/account-model'
|
|
2
|
-
import { usePromise } from '@xyo-network/react-shared'
|
|
3
3
|
import { WalletInstance } from '@xyo-network/wallet-model'
|
|
4
4
|
import { useState } from 'react'
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { useCoinTypeWallet, useWalletContext } from '../contexts'
|
|
7
7
|
|
|
8
8
|
export interface AccountHookParams {
|
|
9
9
|
account?: AccountInstance
|
|
10
|
-
|
|
10
|
+
index?: number
|
|
11
11
|
required?: boolean
|
|
12
12
|
wallet?: WalletInstance
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export const useAccount = ({ wallet, account,
|
|
15
|
+
export const useAccount = ({ wallet, account, index, required = false }: AccountHookParams = {}): [
|
|
16
|
+
AccountInstance | undefined,
|
|
17
|
+
Error | undefined,
|
|
18
|
+
] => {
|
|
16
19
|
const [validationError, setValidationError] = useState<Error>()
|
|
17
20
|
if (wallet && account && !validationError) {
|
|
18
21
|
setValidationError(Error('useAccount can not have both a wallet and an account in the parameters'))
|
|
19
22
|
}
|
|
20
23
|
|
|
21
|
-
if (
|
|
22
|
-
setValidationError(Error('useAccount can not have both a
|
|
24
|
+
if (index && account && !validationError) {
|
|
25
|
+
setValidationError(Error('useAccount can not have both a index and an account in the parameters'))
|
|
23
26
|
}
|
|
27
|
+
|
|
24
28
|
const [error, setError] = useState<Error>()
|
|
25
|
-
const [
|
|
29
|
+
const [coinTypeWallet] = useCoinTypeWallet(!wallet && required)
|
|
30
|
+
const { activeAccountIndex } = useWalletContext(false)
|
|
26
31
|
const [activeAccount] = usePromise(async () => {
|
|
27
32
|
try {
|
|
28
33
|
if (!validationError) {
|
|
29
34
|
if (wallet) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return wallet
|
|
34
|
-
}
|
|
35
|
-
} else {
|
|
36
|
-
return contextAccount
|
|
35
|
+
return await wallet?.derivePath?.(`${index ?? 0}'\0`)
|
|
36
|
+
} else if (coinTypeWallet) {
|
|
37
|
+
return await coinTypeWallet?.derivePath?.(`${index ?? activeAccountIndex ?? 0}'\0`)
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
} catch (ex) {
|
|
@@ -41,11 +42,11 @@ export const useAccount = ({ wallet, account, path, required = false }: AccountH
|
|
|
41
42
|
console.error(error.message)
|
|
42
43
|
setError(error)
|
|
43
44
|
}
|
|
44
|
-
}, [
|
|
45
|
+
}, [index, wallet, coinTypeWallet, activeAccountIndex, validationError])
|
|
45
46
|
if (validationError && !error) {
|
|
46
47
|
console.error(validationError.message)
|
|
47
48
|
setError(validationError)
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
return [error ? undefined : activeAccount, error]
|
|
51
|
+
return [error ? undefined : account ?? activeAccount, error]
|
|
51
52
|
}
|
package/src/hooks/useWallet.tsx
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { usePromise } from '@xylabs/react-promise'
|
|
1
2
|
import { HDWallet } from '@xyo-network/account'
|
|
2
3
|
import { DataLike } from '@xyo-network/core'
|
|
3
|
-
import { usePromise } from '@xyo-network/react-shared'
|
|
4
4
|
import { WalletInstance } from '@xyo-network/wallet-model'
|
|
5
5
|
import { useState } from 'react'
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { useSelectedWalletAccount } from '../contexts'
|
|
8
8
|
|
|
9
9
|
export interface WalletHookParams {
|
|
10
10
|
mnemonic?: string
|
|
@@ -19,7 +19,7 @@ export const useWallet = ({ mnemonic, wallet, path, required = false, seed }: Wa
|
|
|
19
19
|
Error | undefined,
|
|
20
20
|
] => {
|
|
21
21
|
const [error, setError] = useState<Error>()
|
|
22
|
-
const [contextAccount] =
|
|
22
|
+
const [contextAccount] = useSelectedWalletAccount(!wallet && required)
|
|
23
23
|
const [activeAccount] = usePromise(async () => {
|
|
24
24
|
try {
|
|
25
25
|
const newAccount = await (() => {
|
package/src/hooks/useWallets.tsx
CHANGED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AccountContext = void 0;
|
|
4
|
-
const react_shared_1 = require("@xyo-network/react-shared");
|
|
5
|
-
exports.AccountContext = (0, react_shared_1.createContextEx)();
|
|
6
|
-
//# sourceMappingURL=Context.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Context.js","sourceRoot":"","sources":["../../../../src/contexts/Account/Context.ts"],"names":[],"mappings":";;;AAAA,4DAA2D;AAI9C,QAAA,cAAc,GAAG,IAAA,8BAAe,GAAuB,CAAA"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AccountMemoryProvider = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
-
const react_1 = require("react");
|
|
7
|
-
const Context_1 = require("./Context");
|
|
8
|
-
const AccountMemoryProvider = (_a) => {
|
|
9
|
-
var { defaultAccount } = _a, props = tslib_1.__rest(_a, ["defaultAccount"]);
|
|
10
|
-
const [account, setAccount] = (0, react_1.useState)(defaultAccount);
|
|
11
|
-
return (0, jsx_runtime_1.jsx)(Context_1.AccountContext.Provider, Object.assign({ value: { account: account, provided: true, setAccount } }, props));
|
|
12
|
-
};
|
|
13
|
-
exports.AccountMemoryProvider = AccountMemoryProvider;
|
|
14
|
-
//# sourceMappingURL=MemoryProvider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryProvider.js","sourceRoot":"","sources":["../../../../src/contexts/Account/MemoryProvider.tsx"],"names":[],"mappings":";;;;;AAEA,iCAAgC;AAEhC,uCAA0C;AAMnC,MAAM,qBAAqB,GAAuD,CAAC,EAA4B,EAAE,EAAE;QAAhC,EAAE,cAAc,OAAY,EAAP,KAAK,sBAA1B,kBAA4B,CAAF;IAClH,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,IAAA,gBAAQ,EAA6B,cAAc,CAAC,CAAA;IAElF,OAAO,uBAAC,wBAAc,CAAC,QAAQ,kBAAC,KAAK,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAM,KAAK,EAAI,CAAA;AACxG,CAAC,CAAA;AAJY,QAAA,qBAAqB,yBAIjC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"State.js","sourceRoot":"","sources":["../../../../src/contexts/Account/State.ts"],"names":[],"mappings":""}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./Context"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./MemoryProvider"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./State"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./use"), exports);
|
|
8
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/contexts/Account/index.ts"],"names":[],"mappings":";;;AAAA,oDAAyB;AACzB,2DAAgC;AAChC,kDAAuB;AACvB,gDAAqB"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useContextAccount = void 0;
|
|
4
|
-
const react_shared_1 = require("@xyo-network/react-shared");
|
|
5
|
-
const Context_1 = require("./Context");
|
|
6
|
-
const useContextAccount = (required = false) => {
|
|
7
|
-
const { account } = (0, react_shared_1.useContextEx)(Context_1.AccountContext, 'Account', required);
|
|
8
|
-
return [account];
|
|
9
|
-
};
|
|
10
|
-
exports.useContextAccount = useContextAccount;
|
|
11
|
-
//# sourceMappingURL=use.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use.js","sourceRoot":"","sources":["../../../../src/contexts/Account/use.ts"],"names":[],"mappings":";;;AAAA,4DAAwD;AAExD,uCAA0C;AAEnC,MAAM,iBAAiB,GAAG,CAAC,QAAQ,GAAG,KAAK,EAAE,EAAE;IACpD,MAAM,EAAE,OAAO,EAAE,GAAG,IAAA,2BAAY,EAAC,wBAAc,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAA;IACrE,OAAO,CAAC,OAAO,CAAC,CAAA;AAClB,CAAC,CAAA;AAHY,QAAA,iBAAiB,qBAG7B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Context.js","sourceRoot":"","sources":["../../../../src/contexts/Account/Context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAI3D,MAAM,CAAC,MAAM,cAAc,GAAG,eAAe,EAAuB,CAAA"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useState } from 'react';
|
|
3
|
-
import { AccountContext } from './Context';
|
|
4
|
-
export const AccountMemoryProvider = ({ defaultAccount, ...props }) => {
|
|
5
|
-
const [account, setAccount] = useState(defaultAccount);
|
|
6
|
-
return _jsx(AccountContext.Provider, { value: { account: account, provided: true, setAccount }, ...props });
|
|
7
|
-
};
|
|
8
|
-
//# sourceMappingURL=MemoryProvider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryProvider.js","sourceRoot":"","sources":["../../../../src/contexts/Account/MemoryProvider.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAM1C,MAAM,CAAC,MAAM,qBAAqB,GAAuD,CAAC,EAAE,cAAc,EAAE,GAAG,KAAK,EAAE,EAAE,EAAE;IACxH,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAA6B,cAAc,CAAC,CAAA;IAElF,OAAO,KAAC,cAAc,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,KAAM,KAAK,GAAI,CAAA;AACxG,CAAC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"State.js","sourceRoot":"","sources":["../../../../src/contexts/Account/State.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/contexts/Account/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,kBAAkB,CAAA;AAChC,cAAc,SAAS,CAAA;AACvB,cAAc,OAAO,CAAA"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { useContextEx } from '@xyo-network/react-shared';
|
|
2
|
-
import { AccountContext } from './Context';
|
|
3
|
-
export const useContextAccount = (required = false) => {
|
|
4
|
-
const { account } = useContextEx(AccountContext, 'Account', required);
|
|
5
|
-
return [account];
|
|
6
|
-
};
|
|
7
|
-
//# sourceMappingURL=use.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use.js","sourceRoot":"","sources":["../../../../src/contexts/Account/use.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAExD,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAE1C,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,QAAQ,GAAG,KAAK,EAAE,EAAE;IACpD,MAAM,EAAE,OAAO,EAAE,GAAG,YAAY,CAAC,cAAc,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAA;IACrE,OAAO,CAAC,OAAO,CAAC,CAAA;AAClB,CAAC,CAAA"}
|