@xyo-network/react-wallet 2.55.9 → 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.
Files changed (104) hide show
  1. package/dist/cjs/components/SeedPhrase/DefaultSeedPhrase.js +2 -4
  2. package/dist/cjs/components/SeedPhrase/DefaultSeedPhrase.js.map +1 -1
  3. package/dist/cjs/components/WalletAccountSelect/Select.js +5 -5
  4. package/dist/cjs/components/WalletAccountSelect/Select.js.map +1 -1
  5. package/dist/cjs/components/WalletAccountSelect/WalletInfo.js +47 -0
  6. package/dist/cjs/components/WalletAccountSelect/WalletInfo.js.map +1 -0
  7. package/dist/cjs/contexts/SeedPhrase/Provider.js +3 -5
  8. package/dist/cjs/contexts/SeedPhrase/Provider.js.map +1 -1
  9. package/dist/cjs/contexts/Wallet/Provider.js +3 -3
  10. package/dist/cjs/contexts/Wallet/Provider.js.map +1 -1
  11. package/dist/cjs/contexts/Wallet/lib/WalletPath.js +17 -5
  12. package/dist/cjs/contexts/Wallet/lib/WalletPath.js.map +1 -1
  13. package/dist/cjs/contexts/Wallet/use.js +16 -11
  14. package/dist/cjs/contexts/Wallet/use.js.map +1 -1
  15. package/dist/cjs/contexts/index.js +0 -1
  16. package/dist/cjs/contexts/index.js.map +1 -1
  17. package/dist/cjs/hooks/useAccount.js +11 -15
  18. package/dist/cjs/hooks/useAccount.js.map +1 -1
  19. package/dist/cjs/hooks/useWallet.js +1 -1
  20. package/dist/cjs/hooks/useWallet.js.map +1 -1
  21. package/dist/docs.json +786 -832
  22. package/dist/esm/components/SeedPhrase/DefaultSeedPhrase.js +2 -4
  23. package/dist/esm/components/SeedPhrase/DefaultSeedPhrase.js.map +1 -1
  24. package/dist/esm/components/WalletAccountSelect/Select.js +6 -6
  25. package/dist/esm/components/WalletAccountSelect/Select.js.map +1 -1
  26. package/dist/esm/components/WalletAccountSelect/WalletInfo.js +35 -0
  27. package/dist/esm/components/WalletAccountSelect/WalletInfo.js.map +1 -0
  28. package/dist/esm/contexts/SeedPhrase/Provider.js +3 -5
  29. package/dist/esm/contexts/SeedPhrase/Provider.js.map +1 -1
  30. package/dist/esm/contexts/Wallet/Provider.js +3 -3
  31. package/dist/esm/contexts/Wallet/Provider.js.map +1 -1
  32. package/dist/esm/contexts/Wallet/lib/WalletPath.js +15 -4
  33. package/dist/esm/contexts/Wallet/lib/WalletPath.js.map +1 -1
  34. package/dist/esm/contexts/Wallet/use.js +13 -9
  35. package/dist/esm/contexts/Wallet/use.js.map +1 -1
  36. package/dist/esm/contexts/index.js +0 -1
  37. package/dist/esm/contexts/index.js.map +1 -1
  38. package/dist/esm/hooks/useAccount.js +11 -15
  39. package/dist/esm/hooks/useAccount.js.map +1 -1
  40. package/dist/esm/hooks/useWallet.js +2 -2
  41. package/dist/esm/hooks/useWallet.js.map +1 -1
  42. package/dist/types/components/SeedPhrase/DefaultSeedPhrase.d.ts.map +1 -1
  43. package/dist/types/components/WalletAccountSelect/WalletInfo.d.ts +18 -0
  44. package/dist/types/components/WalletAccountSelect/WalletInfo.d.ts.map +1 -0
  45. package/dist/types/contexts/SeedPhrase/Provider.d.ts.map +1 -1
  46. package/dist/types/contexts/Wallet/State.d.ts +2 -2
  47. package/dist/types/contexts/Wallet/State.d.ts.map +1 -1
  48. package/dist/types/contexts/Wallet/lib/WalletPath.d.ts +12 -4
  49. package/dist/types/contexts/Wallet/lib/WalletPath.d.ts.map +1 -1
  50. package/dist/types/contexts/Wallet/use.d.ts +4 -3
  51. package/dist/types/contexts/Wallet/use.d.ts.map +1 -1
  52. package/dist/types/contexts/index.d.ts +0 -1
  53. package/dist/types/contexts/index.d.ts.map +1 -1
  54. package/dist/types/hooks/useAccount.d.ts +5 -2
  55. package/dist/types/hooks/useAccount.d.ts.map +1 -1
  56. package/package.json +17 -16
  57. package/src/components/SeedPhrase/DefaultSeedPhrase.tsx +2 -4
  58. package/src/components/SeedPhrase/dialog/SeedPhraseDialog.stories.tsx +2 -4
  59. package/src/components/WalletAccountSelect/Select.tsx +6 -6
  60. package/src/components/WalletAccountSelect/WalletAccountSelect.stories.tsx +9 -0
  61. package/src/components/WalletAccountSelect/WalletInfo.tsx +100 -0
  62. package/src/contexts/SeedPhrase/Provider.tsx +3 -5
  63. package/src/contexts/Wallet/Provider.tsx +3 -3
  64. package/src/contexts/Wallet/State.ts +2 -2
  65. package/src/contexts/Wallet/lib/WalletPath.ts +16 -4
  66. package/src/contexts/Wallet/use.ts +16 -11
  67. package/src/contexts/index.ts +0 -1
  68. package/src/hooks/useAccount.tsx +16 -15
  69. package/src/hooks/useWallet.tsx +2 -2
  70. package/dist/cjs/contexts/Account/Context.js +0 -6
  71. package/dist/cjs/contexts/Account/Context.js.map +0 -1
  72. package/dist/cjs/contexts/Account/MemoryProvider.js +0 -14
  73. package/dist/cjs/contexts/Account/MemoryProvider.js.map +0 -1
  74. package/dist/cjs/contexts/Account/State.js +0 -3
  75. package/dist/cjs/contexts/Account/State.js.map +0 -1
  76. package/dist/cjs/contexts/Account/index.js +0 -8
  77. package/dist/cjs/contexts/Account/index.js.map +0 -1
  78. package/dist/cjs/contexts/Account/use.js +0 -11
  79. package/dist/cjs/contexts/Account/use.js.map +0 -1
  80. package/dist/esm/contexts/Account/Context.js +0 -3
  81. package/dist/esm/contexts/Account/Context.js.map +0 -1
  82. package/dist/esm/contexts/Account/MemoryProvider.js +0 -8
  83. package/dist/esm/contexts/Account/MemoryProvider.js.map +0 -1
  84. package/dist/esm/contexts/Account/State.js +0 -2
  85. package/dist/esm/contexts/Account/State.js.map +0 -1
  86. package/dist/esm/contexts/Account/index.js +0 -5
  87. package/dist/esm/contexts/Account/index.js.map +0 -1
  88. package/dist/esm/contexts/Account/use.js +0 -7
  89. package/dist/esm/contexts/Account/use.js.map +0 -1
  90. package/dist/types/contexts/Account/Context.d.ts +0 -4
  91. package/dist/types/contexts/Account/Context.d.ts.map +0 -1
  92. package/dist/types/contexts/Account/MemoryProvider.d.ts +0 -8
  93. package/dist/types/contexts/Account/MemoryProvider.d.ts.map +0 -1
  94. package/dist/types/contexts/Account/State.d.ts +0 -8
  95. package/dist/types/contexts/Account/State.d.ts.map +0 -1
  96. package/dist/types/contexts/Account/index.d.ts +0 -5
  97. package/dist/types/contexts/Account/index.d.ts.map +0 -1
  98. package/dist/types/contexts/Account/use.d.ts +0 -2
  99. package/dist/types/contexts/Account/use.d.ts.map +0 -1
  100. package/src/contexts/Account/Context.ts +0 -5
  101. package/src/contexts/Account/MemoryProvider.tsx +0 -15
  102. package/src/contexts/Account/State.ts +0 -8
  103. package/src/contexts/Account/index.ts +0 -4
  104. package/src/contexts/Account/use.ts +0 -8
@@ -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, derivedWallet } = useWalletContext()
30
- const disabled = !derivedWallet || activeAccountIndex === undefined
29
+ const { activeAccountIndex = 0, setActiveAccountIndex, coinTypeWallet } = useWalletContext()
30
+ const disabled = !coinTypeWallet || activeAccountIndex === undefined
31
31
 
32
32
  return (
33
33
  <>
34
- {derivedWallet ? (
34
+ {coinTypeWallet ? (
35
35
  <SelectEx
36
36
  disabled={disabled}
37
37
  renderValue={(selected) => {
38
38
  const Item: React.FC = () => {
39
- const [account] = useAccount({ path: selected.toString(), wallet: derivedWallet })
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({ path: index.toString(), wallet: derivedWallet })
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(wordlist, 256)
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, wordlist)
70
+ return validateMnemonic(passedPhrase, wordlists.english)
73
71
  }
74
72
 
75
73
  const validSeedPhrase = useMemo(() => validate?.(seedPhrase), [seedPhrase])
@@ -27,7 +27,7 @@ export const WalletProvider: React.FC<WithChildren<WalletProviderProps>> = ({
27
27
  }
28
28
  }, [defaultActiveAccountIndex])
29
29
 
30
- const [derivedWallet] = usePromise(async () => {
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(() => derivedWallet?.derivePath(activeAccountIndex.toString()), [derivedWallet, activeAccountIndex])
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
- derivedWallet,
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
- derivedWallet?: WalletInstance
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 WalletBase = 'm'
2
- export const DefaultRootWalletPath = `${WalletBase}/0`
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 = "44'/60'/0'/0"
5
- export const WalletPath = `${WalletBase}/${WalletRootPath}`
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
+ }
@@ -5,24 +5,29 @@ import { WalletInstance } from '@xyo-network/wallet-model'
5
5
  import { WalletContext } from './Context'
6
6
 
7
7
  export const useWalletContext = (required = true) => {
8
- return useContextEx(WalletContext, 'WalletContext', required)
8
+ return useContextEx(WalletContext, 'Wallet', required)
9
9
  }
10
10
 
11
- export const useContextWallet = (required = true): [WalletInstance | undefined] => {
12
- const { derivedWallet } = useWalletContext(required)
13
- return [derivedWallet]
11
+ export const useCoinTypeWallet = (required = true): [WalletInstance | undefined, Error | undefined] => {
12
+ const { coinTypeWallet } = useWalletContext(required)
13
+ return [coinTypeWallet, undefined]
14
14
  }
15
15
 
16
- export const useIndexedWalletFromContext = (index: number, required = true): [WalletInstance | undefined] => {
17
- const [wallet] = useContextWallet(required)
18
- const [account] = usePromise(() => wallet?.derivePath(index.toString()), [wallet, index])
19
- return [account]
16
+ export const useRootWallet = (required = true): [WalletInstance | undefined, Error | undefined] => {
17
+ const { rootWallet } = useWalletContext(required)
18
+ return [rootWallet, undefined]
20
19
  }
21
20
 
22
- export const useSelectedWalletAccount = (required = true): [WalletInstance | undefined] => {
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] => {
23
28
  const { activeAccountIndex } = useWalletContext(required)
24
29
  //we pass in 0 as default since we can not call the hook optionally,
25
30
  //we resolve this false result by checking whether activeAccountIndex is defined before returning it
26
- const [account] = useIndexedWalletFromContext(activeAccountIndex ?? 0)
27
- return [activeAccountIndex !== undefined ? account : undefined]
31
+ const [account] = useIndexedWalletFromContext(activeAccountIndex ?? 0, required)
32
+ return [activeAccountIndex !== undefined ? account : undefined, undefined]
28
33
  }
@@ -1,3 +1,2 @@
1
- export * from './Account'
2
1
  export * from './SeedPhrase'
3
2
  export * from './Wallet'
@@ -3,37 +3,38 @@ import { AccountInstance } from '@xyo-network/account-model'
3
3
  import { WalletInstance } from '@xyo-network/wallet-model'
4
4
  import { useState } from 'react'
5
5
 
6
- import { useContextAccount } from '../contexts'
6
+ import { useCoinTypeWallet, useWalletContext } from '../contexts'
7
7
 
8
8
  export interface AccountHookParams {
9
9
  account?: AccountInstance
10
- path?: string
10
+ index?: number
11
11
  required?: boolean
12
12
  wallet?: WalletInstance
13
13
  }
14
14
 
15
- export const useAccount = ({ wallet, account, path, required = false }: AccountHookParams = {}): [AccountInstance | undefined, Error | undefined] => {
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 (path && account && !validationError) {
22
- setValidationError(Error('useAccount can not have both a path and an account in the parameters'))
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 [contextAccount] = useContextAccount(!(account || wallet) && required)
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
- if (path) {
31
- return await wallet?.derivePath?.(path)
32
- } else {
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
- }, [path, wallet, contextAccount, validationError])
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
  }
@@ -4,7 +4,7 @@ import { DataLike } from '@xyo-network/core'
4
4
  import { WalletInstance } from '@xyo-network/wallet-model'
5
5
  import { useState } from 'react'
6
6
 
7
- import { useContextWallet } from '../contexts'
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] = useContextWallet(!wallet && required)
22
+ const [contextAccount] = useSelectedWalletAccount(!wallet && required)
23
23
  const [activeAccount] = usePromise(async () => {
24
24
  try {
25
25
  const newAccount = await (() => {
@@ -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,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=State.js.map
@@ -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,3 +0,0 @@
1
- import { createContextEx } from '@xyo-network/react-shared';
2
- export const AccountContext = createContextEx();
3
- //# sourceMappingURL=Context.js.map
@@ -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,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=State.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"State.js","sourceRoot":"","sources":["../../../../src/contexts/Account/State.ts"],"names":[],"mappings":""}
@@ -1,5 +0,0 @@
1
- export * from './Context';
2
- export * from './MemoryProvider';
3
- export * from './State';
4
- export * from './use';
5
- //# sourceMappingURL=index.js.map
@@ -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"}
@@ -1,4 +0,0 @@
1
- /// <reference types="react" />
2
- import { AccountContextState } from './State';
3
- export declare const AccountContext: import("react").Context<AccountContextState & import("@xyo-network/react-shared").ContextExState>;
4
- //# sourceMappingURL=Context.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../../../../src/contexts/Account/Context.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAE7C,eAAO,MAAM,cAAc,mGAAyC,CAAA"}
@@ -1,8 +0,0 @@
1
- /// <reference types="react" />
2
- import { WithChildren } from '@xylabs/react-shared';
3
- import { WalletInstance } from '@xyo-network/wallet-model';
4
- export interface AccountMemoryProviderProps {
5
- defaultAccount?: WalletInstance;
6
- }
7
- export declare const AccountMemoryProvider: React.FC<WithChildren<AccountMemoryProviderProps>>;
8
- //# sourceMappingURL=MemoryProvider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MemoryProvider.d.ts","sourceRoot":"","sources":["../../../../src/contexts/Account/MemoryProvider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAK1D,MAAM,WAAW,0BAA0B;IACzC,cAAc,CAAC,EAAE,cAAc,CAAA;CAChC;AAED,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,0BAA0B,CAAC,CAIpF,CAAA"}
@@ -1,8 +0,0 @@
1
- import { ContextExState } from '@xyo-network/react-shared';
2
- import { WalletInstance } from '@xyo-network/wallet-model';
3
- import { Dispatch } from 'react';
4
- export interface AccountContextState extends ContextExState {
5
- account?: WalletInstance;
6
- setAccount?: Dispatch<WalletInstance>;
7
- }
8
- //# sourceMappingURL=State.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"State.d.ts","sourceRoot":"","sources":["../../../../src/contexts/Account/State.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC,MAAM,WAAW,mBAAoB,SAAQ,cAAc;IACzD,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB,UAAU,CAAC,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAA;CACtC"}
@@ -1,5 +0,0 @@
1
- export * from './Context';
2
- export * from './MemoryProvider';
3
- export * from './State';
4
- export * from './use';
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","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,2 +0,0 @@
1
- export declare const useContextAccount: (required?: boolean) => (import("@xyo-network/wallet-model").WalletInstance | undefined)[];
2
- //# sourceMappingURL=use.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use.d.ts","sourceRoot":"","sources":["../../../../src/contexts/Account/use.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,iBAAiB,4FAG7B,CAAA"}
@@ -1,5 +0,0 @@
1
- import { createContextEx } from '@xyo-network/react-shared'
2
-
3
- import { AccountContextState } from './State'
4
-
5
- export const AccountContext = createContextEx<AccountContextState>()
@@ -1,15 +0,0 @@
1
- import { WithChildren } from '@xylabs/react-shared'
2
- import { WalletInstance } from '@xyo-network/wallet-model'
3
- import { useState } from 'react'
4
-
5
- import { AccountContext } from './Context'
6
-
7
- export interface AccountMemoryProviderProps {
8
- defaultAccount?: WalletInstance
9
- }
10
-
11
- export const AccountMemoryProvider: React.FC<WithChildren<AccountMemoryProviderProps>> = ({ defaultAccount, ...props }) => {
12
- const [account, setAccount] = useState<WalletInstance | undefined>(defaultAccount)
13
-
14
- return <AccountContext.Provider value={{ account: account, provided: true, setAccount }} {...props} />
15
- }
@@ -1,8 +0,0 @@
1
- import { ContextExState } from '@xyo-network/react-shared'
2
- import { WalletInstance } from '@xyo-network/wallet-model'
3
- import { Dispatch } from 'react'
4
-
5
- export interface AccountContextState extends ContextExState {
6
- account?: WalletInstance
7
- setAccount?: Dispatch<WalletInstance>
8
- }
@@ -1,4 +0,0 @@
1
- export * from './Context'
2
- export * from './MemoryProvider'
3
- export * from './State'
4
- export * from './use'
@@ -1,8 +0,0 @@
1
- import { useContextEx } from '@xyo-network/react-shared'
2
-
3
- import { AccountContext } from './Context'
4
-
5
- export const useContextAccount = (required = false) => {
6
- const { account } = useContextEx(AccountContext, 'Account', required)
7
- return [account]
8
- }