@xyo-network/react-wallet 2.71.0 → 2.71.2
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/components/WalletAccountSelect/WalletInfo.d.cts +1 -0
- package/dist/browser/components/WalletAccountSelect/WalletInfo.d.cts.map +1 -1
- package/dist/browser/components/WalletAccountSelect/WalletInfo.d.mts +1 -0
- package/dist/browser/components/WalletAccountSelect/WalletInfo.d.mts.map +1 -1
- package/dist/browser/components/WalletAccountSelect/WalletInfo.d.ts +1 -0
- package/dist/browser/components/WalletAccountSelect/WalletInfo.d.ts.map +1 -1
- package/dist/browser/components/WalletAccountSelect/stories/WalletProviderDecorator.d.cts +3 -0
- package/dist/browser/components/WalletAccountSelect/stories/WalletProviderDecorator.d.cts.map +1 -0
- package/dist/browser/components/WalletAccountSelect/stories/WalletProviderDecorator.d.mts +3 -0
- package/dist/browser/components/WalletAccountSelect/stories/WalletProviderDecorator.d.mts.map +1 -0
- package/dist/browser/components/WalletAccountSelect/stories/WalletProviderDecorator.d.ts +3 -0
- package/dist/browser/components/WalletAccountSelect/stories/WalletProviderDecorator.d.ts.map +1 -0
- package/dist/browser/components/WalletAccountSelect/stories/index.d.cts +2 -0
- package/dist/browser/components/WalletAccountSelect/stories/index.d.cts.map +1 -0
- package/dist/browser/components/WalletAccountSelect/stories/index.d.mts +2 -0
- package/dist/browser/components/WalletAccountSelect/stories/index.d.mts.map +1 -0
- package/dist/browser/components/WalletAccountSelect/stories/index.d.ts +2 -0
- package/dist/browser/components/WalletAccountSelect/stories/index.d.ts.map +1 -0
- package/dist/browser/contexts/Wallet/Provider.d.cts +1 -0
- package/dist/browser/contexts/Wallet/Provider.d.cts.map +1 -1
- package/dist/browser/contexts/Wallet/Provider.d.mts +1 -0
- package/dist/browser/contexts/Wallet/Provider.d.mts.map +1 -1
- package/dist/browser/contexts/Wallet/Provider.d.ts +1 -0
- package/dist/browser/contexts/Wallet/Provider.d.ts.map +1 -1
- package/dist/browser/contexts/Wallet/State.d.cts +2 -0
- package/dist/browser/contexts/Wallet/State.d.cts.map +1 -1
- package/dist/browser/contexts/Wallet/State.d.mts +2 -0
- package/dist/browser/contexts/Wallet/State.d.mts.map +1 -1
- package/dist/browser/contexts/Wallet/State.d.ts +2 -0
- package/dist/browser/contexts/Wallet/State.d.ts.map +1 -1
- package/dist/browser/contexts/Wallet/index.d.cts +0 -1
- package/dist/browser/contexts/Wallet/index.d.cts.map +1 -1
- package/dist/browser/contexts/Wallet/index.d.mts +0 -1
- package/dist/browser/contexts/Wallet/index.d.mts.map +1 -1
- package/dist/browser/contexts/Wallet/index.d.ts +0 -1
- package/dist/browser/contexts/Wallet/index.d.ts.map +1 -1
- package/dist/browser/contexts/Wallet/use.d.cts +1 -0
- package/dist/browser/contexts/Wallet/use.d.cts.map +1 -1
- package/dist/browser/contexts/Wallet/use.d.mts +1 -0
- package/dist/browser/contexts/Wallet/use.d.mts.map +1 -1
- package/dist/browser/contexts/Wallet/use.d.ts +1 -0
- package/dist/browser/contexts/Wallet/use.d.ts.map +1 -1
- package/dist/browser/index.cjs +18 -53
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +18 -53
- package/dist/browser/index.js.map +1 -1
- package/dist/node/components/WalletAccountSelect/WalletInfo.d.cts +1 -0
- package/dist/node/components/WalletAccountSelect/WalletInfo.d.cts.map +1 -1
- package/dist/node/components/WalletAccountSelect/WalletInfo.d.mts +1 -0
- package/dist/node/components/WalletAccountSelect/WalletInfo.d.mts.map +1 -1
- package/dist/node/components/WalletAccountSelect/WalletInfo.d.ts +1 -0
- package/dist/node/components/WalletAccountSelect/WalletInfo.d.ts.map +1 -1
- package/dist/node/components/WalletAccountSelect/stories/WalletProviderDecorator.d.cts +3 -0
- package/dist/node/components/WalletAccountSelect/stories/WalletProviderDecorator.d.cts.map +1 -0
- package/dist/node/components/WalletAccountSelect/stories/WalletProviderDecorator.d.mts +3 -0
- package/dist/node/components/WalletAccountSelect/stories/WalletProviderDecorator.d.mts.map +1 -0
- package/dist/node/components/WalletAccountSelect/stories/WalletProviderDecorator.d.ts +3 -0
- package/dist/node/components/WalletAccountSelect/stories/WalletProviderDecorator.d.ts.map +1 -0
- package/dist/node/components/WalletAccountSelect/stories/index.d.cts +2 -0
- package/dist/node/components/WalletAccountSelect/stories/index.d.cts.map +1 -0
- package/dist/node/components/WalletAccountSelect/stories/index.d.mts +2 -0
- package/dist/node/components/WalletAccountSelect/stories/index.d.mts.map +1 -0
- package/dist/node/components/WalletAccountSelect/stories/index.d.ts +2 -0
- package/dist/node/components/WalletAccountSelect/stories/index.d.ts.map +1 -0
- package/dist/node/contexts/Wallet/Provider.d.cts +1 -0
- package/dist/node/contexts/Wallet/Provider.d.cts.map +1 -1
- package/dist/node/contexts/Wallet/Provider.d.mts +1 -0
- package/dist/node/contexts/Wallet/Provider.d.mts.map +1 -1
- package/dist/node/contexts/Wallet/Provider.d.ts +1 -0
- package/dist/node/contexts/Wallet/Provider.d.ts.map +1 -1
- package/dist/node/contexts/Wallet/State.d.cts +2 -0
- package/dist/node/contexts/Wallet/State.d.cts.map +1 -1
- package/dist/node/contexts/Wallet/State.d.mts +2 -0
- package/dist/node/contexts/Wallet/State.d.mts.map +1 -1
- package/dist/node/contexts/Wallet/State.d.ts +2 -0
- package/dist/node/contexts/Wallet/State.d.ts.map +1 -1
- package/dist/node/contexts/Wallet/index.d.cts +0 -1
- package/dist/node/contexts/Wallet/index.d.cts.map +1 -1
- package/dist/node/contexts/Wallet/index.d.mts +0 -1
- package/dist/node/contexts/Wallet/index.d.mts.map +1 -1
- package/dist/node/contexts/Wallet/index.d.ts +0 -1
- package/dist/node/contexts/Wallet/index.d.ts.map +1 -1
- package/dist/node/contexts/Wallet/use.d.cts +1 -0
- package/dist/node/contexts/Wallet/use.d.cts.map +1 -1
- package/dist/node/contexts/Wallet/use.d.mts +1 -0
- package/dist/node/contexts/Wallet/use.d.mts.map +1 -1
- package/dist/node/contexts/Wallet/use.d.ts +1 -0
- package/dist/node/contexts/Wallet/use.d.ts.map +1 -1
- package/dist/node/index.cjs +18 -56
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +18 -53
- package/dist/node/index.js.map +1 -1
- package/package.json +8 -8
- package/src/components/WalletAccountSelect/Select.tsx +5 -5
- package/src/components/WalletAccountSelect/WalletAccountSelect.stories.tsx +5 -8
- package/src/components/WalletAccountSelect/WalletAccountSelectBar.stories.tsx +9 -19
- package/src/components/WalletAccountSelect/WalletAccountSelectWithProvider.stories.tsx +3 -9
- package/src/components/WalletAccountSelect/WalletInfo.tsx +1 -0
- package/src/components/WalletAccountSelect/stories/WalletProviderDecorator.tsx +15 -0
- package/src/components/WalletAccountSelect/stories/index.ts +1 -0
- package/src/contexts/Wallet/Provider.tsx +6 -25
- package/src/contexts/Wallet/State.ts +2 -0
- package/src/contexts/Wallet/index.ts +0 -1
- package/src/contexts/Wallet/use.ts +3 -2
- package/src/hooks/useAccount.ts +5 -5
- package/src/hooks/useWallet.ts +2 -2
- package/src/hooks/useWallets.ts +2 -2
- package/dist/browser/contexts/Wallet/lib/WalletPath.d.cts +0 -13
- package/dist/browser/contexts/Wallet/lib/WalletPath.d.cts.map +0 -1
- package/dist/browser/contexts/Wallet/lib/WalletPath.d.mts +0 -13
- package/dist/browser/contexts/Wallet/lib/WalletPath.d.mts.map +0 -1
- package/dist/browser/contexts/Wallet/lib/WalletPath.d.ts +0 -13
- package/dist/browser/contexts/Wallet/lib/WalletPath.d.ts.map +0 -1
- package/dist/browser/contexts/Wallet/lib/index.d.cts +0 -2
- package/dist/browser/contexts/Wallet/lib/index.d.cts.map +0 -1
- package/dist/browser/contexts/Wallet/lib/index.d.mts +0 -2
- package/dist/browser/contexts/Wallet/lib/index.d.mts.map +0 -1
- package/dist/browser/contexts/Wallet/lib/index.d.ts +0 -2
- package/dist/browser/contexts/Wallet/lib/index.d.ts.map +0 -1
- package/dist/node/contexts/Wallet/lib/WalletPath.d.cts +0 -13
- package/dist/node/contexts/Wallet/lib/WalletPath.d.cts.map +0 -1
- package/dist/node/contexts/Wallet/lib/WalletPath.d.mts +0 -13
- package/dist/node/contexts/Wallet/lib/WalletPath.d.mts.map +0 -1
- package/dist/node/contexts/Wallet/lib/WalletPath.d.ts +0 -13
- package/dist/node/contexts/Wallet/lib/WalletPath.d.ts.map +0 -1
- package/dist/node/contexts/Wallet/lib/index.d.cts +0 -2
- package/dist/node/contexts/Wallet/lib/index.d.cts.map +0 -1
- package/dist/node/contexts/Wallet/lib/index.d.mts +0 -2
- package/dist/node/contexts/Wallet/lib/index.d.mts.map +0 -1
- package/dist/node/contexts/Wallet/lib/index.d.ts +0 -2
- package/dist/node/contexts/Wallet/lib/index.d.ts.map +0 -1
- package/src/contexts/Wallet/lib/WalletPath.ts +0 -17
- package/src/contexts/Wallet/lib/index.ts +0 -1
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { Meta, StoryFn } from '@storybook/react'
|
|
2
|
-
import { DefaultSeedPhrase } from '@xyo-network/react-storybook'
|
|
3
2
|
import { WalletInstance } from '@xyo-network/wallet-model'
|
|
4
3
|
|
|
5
|
-
import {
|
|
6
|
-
import { useWallet, useWallets } from '../../hooks'
|
|
4
|
+
import { useWallets } from '../../hooks'
|
|
7
5
|
import { WalletAccountSelectBar } from './SelectBar'
|
|
6
|
+
import { WalletProviderDecorator } from './stories'
|
|
7
|
+
|
|
8
|
+
const PATHS = { paths: ['0', '3', '5']}
|
|
8
9
|
|
|
9
10
|
const StorybookEntry = {
|
|
10
11
|
argTypes: {},
|
|
11
12
|
component: WalletAccountSelectBar,
|
|
13
|
+
decorators: [WalletProviderDecorator],
|
|
12
14
|
parameters: {
|
|
13
15
|
docs: {
|
|
14
16
|
page: null,
|
|
@@ -21,21 +23,10 @@ const Template: StoryFn<typeof WalletAccountSelectBar> = (args) => {
|
|
|
21
23
|
return <WalletAccountSelectBar {...args}></WalletAccountSelectBar>
|
|
22
24
|
}
|
|
23
25
|
|
|
24
|
-
const WithWalletTemplate: StoryFn<typeof WalletAccountSelectBar> = (args) => {
|
|
25
|
-
const [rootWallet] = useWallet({ mnemonic: DefaultSeedPhrase })
|
|
26
|
-
return (
|
|
27
|
-
<WalletProvider rootWallet={rootWallet}>
|
|
28
|
-
<WalletAccountSelectBar {...args} />
|
|
29
|
-
</WalletProvider>
|
|
30
|
-
)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
26
|
const WithFavoritesTemplate: StoryFn<typeof WalletAccountSelectBar> = (args) => {
|
|
34
|
-
const [
|
|
35
|
-
const [wallets] = useWallets({ paths: ['0', '3', '5'], wallet: rootWallet })
|
|
27
|
+
const [wallets] = useWallets(PATHS)
|
|
36
28
|
const castWallets = wallets as WalletInstance[] | undefined
|
|
37
29
|
return (
|
|
38
|
-
<WalletProvider rootWallet={rootWallet}>
|
|
39
30
|
<WalletAccountSelectBar
|
|
40
31
|
addressNames={
|
|
41
32
|
castWallets
|
|
@@ -51,20 +42,19 @@ const WithFavoritesTemplate: StoryFn<typeof WalletAccountSelectBar> = (args) =>
|
|
|
51
42
|
showFavorite
|
|
52
43
|
{...args}
|
|
53
44
|
/>
|
|
54
|
-
</WalletProvider>
|
|
55
45
|
)
|
|
56
46
|
}
|
|
57
47
|
|
|
58
48
|
const Default = Template.bind({})
|
|
59
49
|
Default.args = {}
|
|
60
50
|
|
|
61
|
-
const WithWallet =
|
|
51
|
+
const WithWallet = Template.bind({})
|
|
62
52
|
WithWallet.args = {}
|
|
63
53
|
|
|
64
|
-
const WithWalletIcon =
|
|
54
|
+
const WithWalletIcon = Template.bind({})
|
|
65
55
|
WithWalletIcon.args = { icons: true }
|
|
66
56
|
|
|
67
|
-
const WithAdditionalAccounts =
|
|
57
|
+
const WithAdditionalAccounts = Template.bind({})
|
|
68
58
|
WithAdditionalAccounts.args = { icons: true, maxAccounts: 10 }
|
|
69
59
|
|
|
70
60
|
const WithAccountFavorites = WithFavoritesTemplate.bind({})
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { Meta, StoryFn } from '@storybook/react'
|
|
2
|
-
import { DefaultSeedPhrase } from '@xyo-network/react-storybook'
|
|
3
2
|
|
|
4
|
-
import { WalletProvider } from '../../contexts'
|
|
5
|
-
import { useWallet } from '../../hooks'
|
|
6
3
|
import { WalletAccountSelect } from './Select'
|
|
4
|
+
import { WalletProviderDecorator } from './stories'
|
|
7
5
|
|
|
8
6
|
const StorybookEntry = {
|
|
9
7
|
argTypes: {},
|
|
10
8
|
component: WalletAccountSelect,
|
|
9
|
+
decorators: [WalletProviderDecorator],
|
|
11
10
|
parameters: {
|
|
12
11
|
docs: {
|
|
13
12
|
page: null,
|
|
@@ -17,12 +16,7 @@ const StorybookEntry = {
|
|
|
17
16
|
} as Meta<typeof WalletAccountSelect>
|
|
18
17
|
|
|
19
18
|
const Template: StoryFn<typeof WalletAccountSelect> = (args) => {
|
|
20
|
-
|
|
21
|
-
return (
|
|
22
|
-
<WalletProvider rootWallet={rootWallet}>
|
|
23
|
-
<WalletAccountSelect {...args}></WalletAccountSelect>
|
|
24
|
-
</WalletProvider>
|
|
25
|
-
)
|
|
19
|
+
return <WalletAccountSelect {...args}></WalletAccountSelect>
|
|
26
20
|
}
|
|
27
21
|
|
|
28
22
|
const Default = Template.bind({})
|
|
@@ -46,6 +46,7 @@ export const WalletIdenticon: React.FC<WalletIdenticonProps> = ({ account, name
|
|
|
46
46
|
)
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
/** @deprecated - use rootWallet instead */
|
|
49
50
|
export const CoinTypeWalletInfo: React.FC<FlexBoxProps> = (props) => {
|
|
50
51
|
const [wallet, error] = useCoinTypeWallet()
|
|
51
52
|
return (
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Decorator } from '@storybook/react'
|
|
2
|
+
import { DefaultSeedPhrase } from '@xyo-network/react-storybook'
|
|
3
|
+
|
|
4
|
+
import { WalletProvider } from '../../../contexts'
|
|
5
|
+
import { useWallet } from '../../../hooks'
|
|
6
|
+
|
|
7
|
+
export const WalletProviderDecorator: Decorator = (Story, context) => {
|
|
8
|
+
const [rootWallet] = useWallet({ mnemonic: DefaultSeedPhrase })
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<WalletProvider rootWallet={rootWallet}>
|
|
12
|
+
<Story {...context} />
|
|
13
|
+
</WalletProvider>
|
|
14
|
+
)
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './WalletProviderDecorator'
|
|
@@ -4,16 +4,16 @@ import { WalletInstance } from '@xyo-network/wallet-model'
|
|
|
4
4
|
import { useEffect, useState } from 'react'
|
|
5
5
|
|
|
6
6
|
import { WalletContext } from './Context'
|
|
7
|
-
import { WalletRootPath } from './lib'
|
|
8
7
|
|
|
9
8
|
export interface WalletProviderProps {
|
|
9
|
+
/** @deprecated - BasePath is no longer supported. Set base path outside of WalletProvider */
|
|
10
10
|
basePath?: string
|
|
11
11
|
defaultActiveAccountIndex?: number
|
|
12
12
|
rootWallet?: WalletInstance | null
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export const WalletProvider: React.FC<WithChildren<WalletProviderProps>> = ({
|
|
16
|
-
basePath
|
|
16
|
+
basePath,
|
|
17
17
|
children,
|
|
18
18
|
defaultActiveAccountIndex = 0,
|
|
19
19
|
rootWallet = null,
|
|
@@ -27,28 +27,7 @@ export const WalletProvider: React.FC<WithChildren<WalletProviderProps>> = ({
|
|
|
27
27
|
}
|
|
28
28
|
}, [defaultActiveAccountIndex])
|
|
29
29
|
|
|
30
|
-
const [
|
|
31
|
-
// ensure the wallet has the proper base
|
|
32
|
-
if (rootWallet) {
|
|
33
|
-
if (rootWallet?.path !== basePath) {
|
|
34
|
-
try {
|
|
35
|
-
const result = await rootWallet?.derivePath(basePath)
|
|
36
|
-
return result
|
|
37
|
-
} catch (e) {
|
|
38
|
-
console.error('Error setting proper wallet base path', e)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
} else {
|
|
42
|
-
return rootWallet
|
|
43
|
-
}
|
|
44
|
-
}, [basePath, rootWallet])
|
|
45
|
-
|
|
46
|
-
//console.log(`coinTypeWallet: ${coinTypeWallet}`)
|
|
47
|
-
|
|
48
|
-
const [activeAccount = null] = usePromise(
|
|
49
|
-
async () => await coinTypeWallet?.derivePath(activeAccountIndex.toString()),
|
|
50
|
-
[coinTypeWallet, activeAccountIndex],
|
|
51
|
-
)
|
|
30
|
+
const [activeAccount = null] = usePromise(async () => await rootWallet?.derivePath(activeAccountIndex.toString()), [activeAccountIndex, rootWallet])
|
|
52
31
|
|
|
53
32
|
return (
|
|
54
33
|
<WalletContext.Provider
|
|
@@ -56,7 +35,9 @@ export const WalletProvider: React.FC<WithChildren<WalletProviderProps>> = ({
|
|
|
56
35
|
activeAccount,
|
|
57
36
|
activeAccountIndex,
|
|
58
37
|
basePath,
|
|
59
|
-
|
|
38
|
+
/* eslint-disable deprecation/deprecation */
|
|
39
|
+
/** @deprecated - Set path for coinTypeWallet outside of provider and pass as rootWallet */
|
|
40
|
+
coinTypeWallet: null,
|
|
60
41
|
provided: true,
|
|
61
42
|
rootWallet,
|
|
62
43
|
setActiveAccountIndex,
|
|
@@ -7,8 +7,10 @@ export interface WalletContextState extends ContextExState {
|
|
|
7
7
|
activeAccount?: WalletInstance | null
|
|
8
8
|
/** Currently selected index */
|
|
9
9
|
activeAccountIndex?: number
|
|
10
|
+
/** @deprecated - BasePath is no longer supported. Set base path outside of WalletProvider */
|
|
10
11
|
/** Base path from which the wallet was derived */
|
|
11
12
|
basePath?: string
|
|
13
|
+
/** @deprecated - Set path for coinTypeWallet outside of provider and pass as rootWallet */
|
|
12
14
|
/** The coin_type derived wallet being used */
|
|
13
15
|
coinTypeWallet?: WalletInstance | null
|
|
14
16
|
/** The root wallet being used */
|
|
@@ -12,6 +12,7 @@ export const useWalletProvided = () => {
|
|
|
12
12
|
return useProvided(WalletContext)
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
/** @deprecated - useWalletContext instead */
|
|
15
16
|
export const useCoinTypeWallet = (required = true): [WalletInstance | null | undefined, Error | undefined] => {
|
|
16
17
|
const { coinTypeWallet } = useWalletContext(required)
|
|
17
18
|
return [coinTypeWallet, undefined]
|
|
@@ -23,8 +24,8 @@ export const useRootWallet = (required = true): [WalletInstance | null | undefin
|
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
export const useIndexedWalletFromContext = (index: number, required = true): [WalletInstance | null | undefined, Error | undefined] => {
|
|
26
|
-
const
|
|
27
|
-
const [wallet] = usePromise(async () => (await
|
|
27
|
+
const { rootWallet } = useWalletContext(required)
|
|
28
|
+
const [wallet] = usePromise(async () => (await rootWallet?.derivePath(index.toString())) ?? rootWallet, [rootWallet, index])
|
|
28
29
|
return [wallet, undefined]
|
|
29
30
|
}
|
|
30
31
|
|
package/src/hooks/useAccount.ts
CHANGED
|
@@ -3,7 +3,7 @@ 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 {
|
|
6
|
+
import { useRootWallet, useWalletContext, useWalletProvided } from '../contexts'
|
|
7
7
|
|
|
8
8
|
export interface AccountHookParams {
|
|
9
9
|
account?: AccountInstance
|
|
@@ -27,15 +27,15 @@ export const useAccount = ({ wallet, account, index, required = false }: Account
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
const [error, setError] = useState<Error>()
|
|
30
|
-
const [
|
|
30
|
+
const [rootWallet] = useRootWallet(!wallet && required)
|
|
31
31
|
const { activeAccountIndex } = useWalletContext(false)
|
|
32
32
|
const [activeAccount] = usePromise(async () => {
|
|
33
33
|
try {
|
|
34
34
|
if (!validationError) {
|
|
35
35
|
if (wallet) {
|
|
36
36
|
return await wallet?.derivePath?.(`${index ?? 0}'\0`)
|
|
37
|
-
} else if (
|
|
38
|
-
return await
|
|
37
|
+
} else if (rootWallet) {
|
|
38
|
+
return await rootWallet?.derivePath?.(`${index ?? activeAccountIndex ?? 0}'\0`)
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
} catch (ex) {
|
|
@@ -43,7 +43,7 @@ export const useAccount = ({ wallet, account, index, required = false }: Account
|
|
|
43
43
|
console.error(error.message)
|
|
44
44
|
setError(error)
|
|
45
45
|
}
|
|
46
|
-
}, [index, wallet,
|
|
46
|
+
}, [index, wallet, rootWallet, activeAccountIndex, validationError])
|
|
47
47
|
if (validationError && !error) {
|
|
48
48
|
console.error(validationError.message)
|
|
49
49
|
setError(validationError)
|
package/src/hooks/useWallet.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { HDWallet } from '@xyo-network/account'
|
|
|
3
3
|
import { WalletInstance } from '@xyo-network/wallet-model'
|
|
4
4
|
import { useState } from 'react'
|
|
5
5
|
|
|
6
|
-
import { useSelectedWalletAccount,
|
|
6
|
+
import { useSelectedWalletAccount, useWalletContext } from '../contexts'
|
|
7
7
|
|
|
8
8
|
export interface WalletHookParams {
|
|
9
9
|
mnemonic?: string
|
|
@@ -17,7 +17,7 @@ export const useWallet = ({ mnemonic, wallet, path, required = false, seed }: Wa
|
|
|
17
17
|
WalletInstance | null | undefined,
|
|
18
18
|
Error | undefined,
|
|
19
19
|
] => {
|
|
20
|
-
const walletContextProvided =
|
|
20
|
+
const walletContextProvided = useWalletContext(false)
|
|
21
21
|
const [error, setError] = useState<Error>()
|
|
22
22
|
const [contextAccount] = useSelectedWalletAccount(!wallet && required)
|
|
23
23
|
const [activeAccount] = usePromise(async () => {
|
package/src/hooks/useWallets.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { usePromise } from '@xylabs/react-promise'
|
|
2
2
|
import { WalletInstance } from '@xyo-network/wallet-model'
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { useWalletContext } from '../contexts'
|
|
5
5
|
import { useWallet } from './useWallet'
|
|
6
6
|
|
|
7
7
|
export interface WalletsHookParams {
|
|
@@ -10,7 +10,7 @@ export interface WalletsHookParams {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export const useWallets = ({ wallet, paths }: WalletsHookParams): [WalletInstance[] | null | undefined, Error | undefined] => {
|
|
13
|
-
const walletContextProvided =
|
|
13
|
+
const walletContextProvided = useWalletContext(false)
|
|
14
14
|
const [foundWallet] = useWallet({ wallet })
|
|
15
15
|
const [wallets, error] = usePromise(
|
|
16
16
|
async () => (foundWallet ? await Promise.all(paths.map((path) => foundWallet.derivePath(path))) : undefined),
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare const Bip44: {
|
|
2
|
-
base: string;
|
|
3
|
-
coin_type: {
|
|
4
|
-
bitcoin: string;
|
|
5
|
-
bitcoinTestnet: string;
|
|
6
|
-
ether: string;
|
|
7
|
-
etherClassic: string;
|
|
8
|
-
};
|
|
9
|
-
purpose: string;
|
|
10
|
-
};
|
|
11
|
-
export declare const WalletRootPath: string;
|
|
12
|
-
export declare const ethereumAccountPath: (index: number, hardened?: boolean) => string;
|
|
13
|
-
//# sourceMappingURL=WalletPath.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WalletPath.d.ts","sourceRoot":"","sources":["../../../../../src/contexts/Wallet/lib/WalletPath.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK;;;;;;;;;CAUjB,CAAA;AAED,eAAO,MAAM,cAAc,QAA4D,CAAA;AAEvF,eAAO,MAAM,mBAAmB,UAAW,MAAM,+BAEhD,CAAA"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare const Bip44: {
|
|
2
|
-
base: string;
|
|
3
|
-
coin_type: {
|
|
4
|
-
bitcoin: string;
|
|
5
|
-
bitcoinTestnet: string;
|
|
6
|
-
ether: string;
|
|
7
|
-
etherClassic: string;
|
|
8
|
-
};
|
|
9
|
-
purpose: string;
|
|
10
|
-
};
|
|
11
|
-
export declare const WalletRootPath: string;
|
|
12
|
-
export declare const ethereumAccountPath: (index: number, hardened?: boolean) => string;
|
|
13
|
-
//# sourceMappingURL=WalletPath.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WalletPath.d.ts","sourceRoot":"","sources":["../../../../../src/contexts/Wallet/lib/WalletPath.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK;;;;;;;;;CAUjB,CAAA;AAED,eAAO,MAAM,cAAc,QAA4D,CAAA;AAEvF,eAAO,MAAM,mBAAmB,UAAW,MAAM,+BAEhD,CAAA"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare const Bip44: {
|
|
2
|
-
base: string;
|
|
3
|
-
coin_type: {
|
|
4
|
-
bitcoin: string;
|
|
5
|
-
bitcoinTestnet: string;
|
|
6
|
-
ether: string;
|
|
7
|
-
etherClassic: string;
|
|
8
|
-
};
|
|
9
|
-
purpose: string;
|
|
10
|
-
};
|
|
11
|
-
export declare const WalletRootPath: string;
|
|
12
|
-
export declare const ethereumAccountPath: (index: number, hardened?: boolean) => string;
|
|
13
|
-
//# sourceMappingURL=WalletPath.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WalletPath.d.ts","sourceRoot":"","sources":["../../../../../src/contexts/Wallet/lib/WalletPath.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK;;;;;;;;;CAUjB,CAAA;AAED,eAAO,MAAM,cAAc,QAA4D,CAAA;AAEvF,eAAO,MAAM,mBAAmB,UAAW,MAAM,+BAEhD,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/contexts/Wallet/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/contexts/Wallet/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/contexts/Wallet/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare const Bip44: {
|
|
2
|
-
base: string;
|
|
3
|
-
coin_type: {
|
|
4
|
-
bitcoin: string;
|
|
5
|
-
bitcoinTestnet: string;
|
|
6
|
-
ether: string;
|
|
7
|
-
etherClassic: string;
|
|
8
|
-
};
|
|
9
|
-
purpose: string;
|
|
10
|
-
};
|
|
11
|
-
export declare const WalletRootPath: string;
|
|
12
|
-
export declare const ethereumAccountPath: (index: number, hardened?: boolean) => string;
|
|
13
|
-
//# sourceMappingURL=WalletPath.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WalletPath.d.ts","sourceRoot":"","sources":["../../../../../src/contexts/Wallet/lib/WalletPath.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK;;;;;;;;;CAUjB,CAAA;AAED,eAAO,MAAM,cAAc,QAA4D,CAAA;AAEvF,eAAO,MAAM,mBAAmB,UAAW,MAAM,+BAEhD,CAAA"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare const Bip44: {
|
|
2
|
-
base: string;
|
|
3
|
-
coin_type: {
|
|
4
|
-
bitcoin: string;
|
|
5
|
-
bitcoinTestnet: string;
|
|
6
|
-
ether: string;
|
|
7
|
-
etherClassic: string;
|
|
8
|
-
};
|
|
9
|
-
purpose: string;
|
|
10
|
-
};
|
|
11
|
-
export declare const WalletRootPath: string;
|
|
12
|
-
export declare const ethereumAccountPath: (index: number, hardened?: boolean) => string;
|
|
13
|
-
//# sourceMappingURL=WalletPath.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WalletPath.d.ts","sourceRoot":"","sources":["../../../../../src/contexts/Wallet/lib/WalletPath.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK;;;;;;;;;CAUjB,CAAA;AAED,eAAO,MAAM,cAAc,QAA4D,CAAA;AAEvF,eAAO,MAAM,mBAAmB,UAAW,MAAM,+BAEhD,CAAA"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare const Bip44: {
|
|
2
|
-
base: string;
|
|
3
|
-
coin_type: {
|
|
4
|
-
bitcoin: string;
|
|
5
|
-
bitcoinTestnet: string;
|
|
6
|
-
ether: string;
|
|
7
|
-
etherClassic: string;
|
|
8
|
-
};
|
|
9
|
-
purpose: string;
|
|
10
|
-
};
|
|
11
|
-
export declare const WalletRootPath: string;
|
|
12
|
-
export declare const ethereumAccountPath: (index: number, hardened?: boolean) => string;
|
|
13
|
-
//# sourceMappingURL=WalletPath.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WalletPath.d.ts","sourceRoot":"","sources":["../../../../../src/contexts/Wallet/lib/WalletPath.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK;;;;;;;;;CAUjB,CAAA;AAED,eAAO,MAAM,cAAc,QAA4D,CAAA;AAEvF,eAAO,MAAM,mBAAmB,UAAW,MAAM,+BAEhD,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/contexts/Wallet/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/contexts/Wallet/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/contexts/Wallet/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA"}
|
|
@@ -1,17 +0,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
|
-
}
|
|
12
|
-
|
|
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 +0,0 @@
|
|
|
1
|
-
export * from './WalletPath'
|