@xyo-network/react-wallet 7.5.8 → 7.5.11

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 (63) hide show
  1. package/dist/browser/components/WalletAccountDetails/WalletAccountDetails.d.ts.map +1 -1
  2. package/dist/browser/contexts/SeedPhrase/Provider.d.ts.map +1 -1
  3. package/dist/browser/index.mjs +656 -566
  4. package/dist/browser/index.mjs.map +1 -1
  5. package/package.json +112 -46
  6. package/src/components/MaxAccounts/MaxAccountsTableRow.tsx +0 -75
  7. package/src/components/MaxAccounts/OutOfBoundsSnackBar.tsx +0 -41
  8. package/src/components/MaxAccounts/index.ts +0 -1
  9. package/src/components/SeedPhrase/DefaultSeedPhrase.stories.tsx +0 -27
  10. package/src/components/SeedPhrase/DefaultSeedPhrase.tsx +0 -52
  11. package/src/components/SeedPhrase/_shared/SeedPhraseIconButton.tsx +0 -53
  12. package/src/components/SeedPhrase/_shared/index.ts +0 -1
  13. package/src/components/SeedPhrase/dialog/SeedPhraseDialog.stories.tsx +0 -33
  14. package/src/components/SeedPhrase/dialog/SeedPhraseDialog.tsx +0 -84
  15. package/src/components/SeedPhrase/dialog/components/DialogActionButtons.tsx +0 -33
  16. package/src/components/SeedPhrase/dialog/components/OverwriteWarning.tsx +0 -28
  17. package/src/components/SeedPhrase/dialog/components/fields/NewPhraseTextField.tsx +0 -45
  18. package/src/components/SeedPhrase/dialog/components/fields/PhraseDialogActions.stories.tsx +0 -29
  19. package/src/components/SeedPhrase/dialog/components/fields/PhraseDialogActions.tsx +0 -38
  20. package/src/components/SeedPhrase/dialog/components/fields/SavedPhraseTextField.tsx +0 -113
  21. package/src/components/SeedPhrase/dialog/components/fields/index.ts +0 -4
  22. package/src/components/SeedPhrase/dialog/components/fields/validation-messages/InvalidPhrase.tsx +0 -14
  23. package/src/components/SeedPhrase/dialog/components/fields/validation-messages/PhraseHeaderBox.tsx +0 -50
  24. package/src/components/SeedPhrase/dialog/components/fields/validation-messages/colorParser.ts +0 -14
  25. package/src/components/SeedPhrase/dialog/components/fields/validation-messages/index.ts +0 -3
  26. package/src/components/SeedPhrase/dialog/components/index.ts +0 -3
  27. package/src/components/SeedPhrase/dialog/index.ts +0 -2
  28. package/src/components/SeedPhrase/index.ts +0 -4
  29. package/src/components/SeedPhrase/settings/SeedPhraseTableRow.stories.tsx +0 -31
  30. package/src/components/SeedPhrase/settings/SeedPhraseTableRow.tsx +0 -48
  31. package/src/components/SeedPhrase/settings/index.ts +0 -1
  32. package/src/components/WalletAccountDetails/WalletAccountDetails.stories.tsx +0 -27
  33. package/src/components/WalletAccountDetails/WalletAccountDetails.tsx +0 -37
  34. package/src/components/WalletAccountDetails/WalletAccountDetailsWithProvider.stories.tsx +0 -33
  35. package/src/components/WalletAccountDetails/index.ts +0 -1
  36. package/src/components/WalletAccountSelect/RenderedMenuItem.tsx +0 -52
  37. package/src/components/WalletAccountSelect/Select.tsx +0 -84
  38. package/src/components/WalletAccountSelect/SelectBar.tsx +0 -44
  39. package/src/components/WalletAccountSelect/WalletAccountSelect.stories.tsx +0 -45
  40. package/src/components/WalletAccountSelect/WalletAccountSelectBar.stories.tsx +0 -61
  41. package/src/components/WalletAccountSelect/WalletAccountSelectWithProvider.stories.tsx +0 -43
  42. package/src/components/WalletAccountSelect/WalletInfo.tsx +0 -121
  43. package/src/components/WalletAccountSelect/index.ts +0 -2
  44. package/src/components/WalletAccountSelect/stories/WalletProviderDecorator.tsx +0 -31
  45. package/src/components/WalletAccountSelect/stories/index.ts +0 -1
  46. package/src/components/index.ts +0 -4
  47. package/src/contexts/SeedPhrase/Context.ts +0 -6
  48. package/src/contexts/SeedPhrase/Provider.tsx +0 -103
  49. package/src/contexts/SeedPhrase/State.ts +0 -19
  50. package/src/contexts/SeedPhrase/index.ts +0 -4
  51. package/src/contexts/SeedPhrase/use.ts +0 -6
  52. package/src/contexts/Wallet/Context.ts +0 -6
  53. package/src/contexts/Wallet/Provider.tsx +0 -46
  54. package/src/contexts/Wallet/State.ts +0 -15
  55. package/src/contexts/Wallet/index.ts +0 -4
  56. package/src/contexts/Wallet/use.ts +0 -37
  57. package/src/contexts/index.ts +0 -2
  58. package/src/hooks/index.ts +0 -4
  59. package/src/hooks/useAccount.ts +0 -68
  60. package/src/hooks/useWallet.ts +0 -46
  61. package/src/hooks/useWallets.ts +0 -22
  62. package/src/hooks/useWrapperAccount.ts +0 -36
  63. package/src/index.ts +0 -3
@@ -1,121 +0,0 @@
1
- import { Circle as LoadingIcon, ErrorOutlined as ErrorIcon } from '@mui/icons-material'
2
- import type { FlexBoxProps } from '@xylabs/react-flexbox'
3
- import { FlexCol } from '@xylabs/react-flexbox'
4
- import { Identicon } from '@xylabs/react-identicon'
5
- import { QuickTipButton } from '@xylabs/react-quick-tip-button'
6
- import type { AccountInstance } from '@xyo-network/account-model'
7
- import React from 'react'
8
-
9
- import { useRootWallet, useSelectedWalletAccount } from '../../contexts/index.ts'
10
- import { useAccount, useWallet } from '../../hooks/index.ts'
11
-
12
- /** @public */
13
- export interface WalletErrorProps {
14
- error?: Error
15
- }
16
-
17
- /** @public */
18
- export const WalletError: React.FC<WalletErrorProps> = ({ error }) => {
19
- return error
20
- ? (
21
- <div>
22
- <ErrorIcon
23
- style={{ fontSize: '12px', position: 'absolute' }}
24
- color="error"
25
- />
26
- <QuickTipButton
27
- size="small"
28
- style={{
29
- color: '#ffffff00', fontSize: '12px', padding: 0, position: 'absolute',
30
- }}
31
- hoverText={error.message}
32
- disableDialog
33
- />
34
- </div>
35
- )
36
- : null
37
- }
38
-
39
- /** @public */
40
- export interface WalletIdenticonProps {
41
- account?: AccountInstance | null
42
- name: string
43
- }
44
-
45
- /** @public */
46
- export const WalletIdenticon: React.FC<WalletIdenticonProps> = ({ account, name }) => {
47
- return (
48
- <div style={{ width: 20 }}>
49
- {account
50
- ? (
51
- <Identicon
52
- size={8}
53
- value={account.address}
54
- style={{
55
- position: 'absolute', right: 2, top: 2,
56
- }}
57
- />
58
- )
59
- : (
60
- <LoadingIcon
61
- style={{
62
- fontSize: '10px', padding: 0, position: 'absolute', right: 2, top: 2,
63
- }}
64
- color="disabled"
65
- />
66
- )}
67
- <QuickTipButton
68
- size="small"
69
- style={{
70
- color: '#ffffff00', fontSize: '12px', padding: 0, position: 'absolute',
71
- }}
72
- hoverText={`${name ?? ''}: ${account?.address ?? 'no address'}`}
73
- disableDialog
74
- />
75
- </div>
76
- )
77
- }
78
-
79
- /** @public */
80
- export const RootWalletInfo: React.FC<FlexBoxProps> = (props) => {
81
- const [wallet, error] = useRootWallet()
82
- return (
83
- <FlexCol width={12} {...props}>
84
- {error ? null : <WalletIdenticon name="Root" account={wallet} />}
85
- <WalletError error={error} />
86
- </FlexCol>
87
- )
88
- }
89
-
90
- /** @public */
91
- export const SelectedWalletInfo: React.FC<FlexBoxProps> = (props) => {
92
- const [wallet, error] = useSelectedWalletAccount()
93
- return (
94
- <FlexCol width={12} {...props}>
95
- {error ? null : <WalletIdenticon name="Selected" account={wallet} />}
96
- <WalletError error={error} />
97
- </FlexCol>
98
- )
99
- }
100
-
101
- /** @public */
102
- export const WalletInfo: React.FC<FlexBoxProps> = (props) => {
103
- const [wallet, error] = useWallet()
104
- return (
105
- <FlexCol width={12} {...props}>
106
- {error ? null : <WalletIdenticon name="Wallet" account={wallet} />}
107
- <WalletError error={error} />
108
- </FlexCol>
109
- )
110
- }
111
-
112
- /** @public */
113
- export const AccountInfo: React.FC<FlexBoxProps> = (props) => {
114
- const [account, error] = useAccount()
115
- return (
116
- <FlexCol width={12} {...props}>
117
- {error ? null : <WalletIdenticon name="Account" account={account} />}
118
- <WalletError error={error} />
119
- </FlexCol>
120
- )
121
- }
@@ -1,2 +0,0 @@
1
- export * from './Select.tsx'
2
- export * from './SelectBar.tsx'
@@ -1,31 +0,0 @@
1
- import type { Decorator } from '@storybook/react-vite'
2
- import { DefaultSeedPhrase } from '@xyo-network/react-storybook'
3
- import type { WalletInstance } from '@xyo-network/wallet-model'
4
- import React, { useEffect, useState } from 'react'
5
-
6
- import { WalletProvider } from '../../../contexts/index.ts'
7
- import { useWallet } from '../../../hooks/index.ts'
8
-
9
- export const WalletProviderDecorator: Decorator = (Story, context) => {
10
- const [rootWallet] = useWallet({ mnemonic: DefaultSeedPhrase })
11
- const [wallet, setWallet] = useState<WalletInstance>()
12
-
13
- useEffect(() => {
14
- let timeout: ReturnType<typeof setTimeout>
15
- if (rootWallet) {
16
- timeout = setTimeout(() => {
17
- setWallet(rootWallet)
18
- }, 1000)
19
- }
20
- return () => {
21
- if (timeout) {
22
- clearTimeout(timeout)
23
- }
24
- }
25
- }, [rootWallet])
26
- return (
27
- <WalletProvider rootWallet={wallet}>
28
- <Story {...context} />
29
- </WalletProvider>
30
- )
31
- }
@@ -1 +0,0 @@
1
- export * from './WalletProviderDecorator.tsx'
@@ -1,4 +0,0 @@
1
- export * from './MaxAccounts/index.ts'
2
- export * from './SeedPhrase/index.ts'
3
- export * from './WalletAccountDetails/index.ts'
4
- export * from './WalletAccountSelect/index.ts'
@@ -1,6 +0,0 @@
1
- import { createContextEx } from '@xylabs/react-shared'
2
-
3
- import type { SeedPhraseContextState } from './State.ts'
4
-
5
- /** @public */
6
- export const SeedPhraseContext = createContextEx<SeedPhraseContextState>()
@@ -1,103 +0,0 @@
1
- import { generateMnemonic, validateMnemonic } from '@scure/bip39'
2
- import { wordlist } from '@scure/bip39/wordlists/english.js'
3
- import { useResetState } from '@xylabs/react-hooks'
4
- import type { PropsWithChildren } from 'react'
5
- import React, {
6
- useCallback, useEffect, useMemo, useState,
7
- } from 'react'
8
-
9
- import { SeedPhraseContext } from './Context.ts'
10
- import type { SeedPhraseContextState } from './State.ts'
11
-
12
- /** @public */
13
- export interface SeedPhraseProviderProps extends PropsWithChildren {
14
- defaultPhrase?: string
15
- handleChangeSeedPhrase?: (phrase: string) => void
16
- open?: boolean
17
- saveCallback?: () => void
18
- seedPhrase?: string
19
- }
20
-
21
- const validate = (passedPhrase?: string) => {
22
- if (!passedPhrase) {
23
- return null
24
- }
25
- return validateMnemonic(passedPhrase, wordlist)
26
- }
27
-
28
- /** @public */
29
- export const SeedPhraseProvider: React.FC<SeedPhraseProviderProps> = ({
30
- children,
31
- defaultPhrase,
32
- handleChangeSeedPhrase,
33
- saveCallback,
34
- seedPhrase,
35
- open,
36
- }) => {
37
- const [phrase, setPhrase] = useResetState<string | undefined>(defaultPhrase)
38
- const [overwriteWarning, setOverwriteWarning] = useState(false)
39
-
40
- useEffect(() => {
41
- if (seedPhrase || open) {
42
- setPhrase?.(seedPhrase ?? '')
43
- }
44
- }, [seedPhrase, open, setPhrase])
45
-
46
- const handleGenerate = useCallback(() => {
47
- const mnemonic = generateMnemonic(wordlist, 256)
48
- setPhrase?.(mnemonic)
49
- setOverwriteWarning?.(false)
50
- }, [setPhrase])
51
-
52
- const handleCancelOverwrite = useCallback(() => {
53
- setOverwriteWarning(false)
54
- }, [setOverwriteWarning])
55
-
56
- const handleClear = useCallback(() => {
57
- setPhrase('')
58
- setOverwriteWarning(false)
59
- }, [setPhrase, setOverwriteWarning])
60
-
61
- const handleSave = useCallback(() => {
62
- if (!overwriteWarning && seedPhrase && seedPhrase !== phrase) {
63
- setOverwriteWarning?.(true)
64
- } else {
65
- handleChangeSeedPhrase?.(phrase ?? '')
66
- saveCallback?.()
67
- }
68
- }, [handleChangeSeedPhrase, overwriteWarning, phrase, saveCallback, seedPhrase])
69
-
70
- useEffect(() => {
71
- if (!open) {
72
- handleCancelOverwrite()
73
- }
74
- }, [handleCancelOverwrite, open])
75
-
76
- const validSeedPhrase = useMemo(() => validate?.(seedPhrase), [seedPhrase])
77
- const validPhrase = useMemo(() => validate?.(phrase), [phrase])
78
-
79
- const value: SeedPhraseContextState = useMemo(() => ({
80
- handleCancelOverwrite,
81
- handleChangeSeedPhrase,
82
- handleClear,
83
- handleGenerate,
84
- handleSave,
85
- overwriteWarning,
86
- phrase,
87
- provided: true,
88
- seedPhrase,
89
- setOverwriteWarning,
90
- setPhrase,
91
- validPhrase,
92
- validSeedPhrase,
93
- validate,
94
- }), [handleCancelOverwrite, handleChangeSeedPhrase, handleClear, handleGenerate, handleSave, overwriteWarning, phrase, seedPhrase, setOverwriteWarning, setPhrase, validPhrase, validSeedPhrase])
95
-
96
- return (
97
- <SeedPhraseContext
98
- value={value}
99
- >
100
- {children}
101
- </SeedPhraseContext>
102
- )
103
- }
@@ -1,19 +0,0 @@
1
- import type { ContextExState } from '@xylabs/react-shared'
2
- import type { Dispatch, SetStateAction } from 'react'
3
-
4
- /** @public */
5
- export type SeedPhraseContextState = ContextExState<{
6
- handleCancelOverwrite?: () => void
7
- handleChangeSeedPhrase?: (value: string) => void
8
- handleClear?: () => void
9
- handleGenerate?: () => void
10
- handleSave?: () => void
11
- overwriteWarning?: boolean
12
- phrase?: string
13
- seedPhrase?: string
14
- setOverwriteWarning?: Dispatch<SetStateAction<boolean>>
15
- setPhrase?: Dispatch<SetStateAction<string | undefined>>
16
- validPhrase?: boolean | null
17
- validSeedPhrase?: boolean | null
18
- validate?: (passedPhrase?: string) => boolean | null
19
- }>
@@ -1,4 +0,0 @@
1
- export * from './Context.ts'
2
- export * from './Provider.tsx'
3
- export * from './State.ts'
4
- export * from './use.ts'
@@ -1,6 +0,0 @@
1
- import { useContextEx } from '@xylabs/react-shared'
2
-
3
- import { SeedPhraseContext } from './Context.ts'
4
-
5
- /** @public */
6
- export const useSeedPhrase = () => useContextEx(SeedPhraseContext, 'SeedPhrase', true)
@@ -1,6 +0,0 @@
1
- import { createContextEx } from '@xylabs/react-shared'
2
-
3
- import type { WalletContextState } from './State.ts'
4
-
5
- /** @public */
6
- export const WalletContext = createContextEx<WalletContextState>()
@@ -1,46 +0,0 @@
1
- import { useResetState } from '@xylabs/react-hooks'
2
- import { usePromise } from '@xylabs/react-promise'
3
- import type { WalletInstance } from '@xyo-network/wallet-model'
4
- import type { PropsWithChildren } from 'react'
5
- import React, { useMemo } from 'react'
6
-
7
- import { WalletContext } from './Context.ts'
8
- import type { WalletContextState } from './State.ts'
9
-
10
- /** @public */
11
- export interface WalletProviderProps {
12
- defaultActiveAccountIndex?: number
13
- rootWallet?: WalletInstance | null
14
- }
15
-
16
- /** @public */
17
- export const WalletProvider: React.FC<PropsWithChildren<WalletProviderProps>> = ({
18
- children,
19
- defaultActiveAccountIndex = 0,
20
- rootWallet = null,
21
- ...props
22
- }) => {
23
- const [activeAccountIndex, setActiveAccountIndex] = useResetState(defaultActiveAccountIndex)
24
-
25
- const [activeAccount = null] = usePromise(async () => await rootWallet?.derivePath(activeAccountIndex.toString()), [activeAccountIndex, rootWallet])
26
-
27
- const value: WalletContextState = useMemo(() => ({
28
- activeAccount,
29
- activeAccountIndex,
30
- provided: true,
31
- rootWallet,
32
- setActiveAccountIndex,
33
- }), [activeAccount,
34
- activeAccountIndex,
35
- rootWallet,
36
- setActiveAccountIndex])
37
-
38
- return (
39
- <WalletContext
40
- value={value}
41
- {...props}
42
- >
43
- {children}
44
- </WalletContext>
45
- )
46
- }
@@ -1,15 +0,0 @@
1
- import type { ContextExState } from '@xylabs/react-shared'
2
- import type { WalletInstance } from '@xyo-network/wallet-model'
3
- import type { Dispatch } from 'react'
4
-
5
- /** @public */
6
- export type WalletContextState = ContextExState<{
7
- /** Currently selected account */
8
- activeAccount?: WalletInstance | null
9
- /** Currently selected index */
10
- activeAccountIndex?: number
11
- /** The root wallet being used */
12
- rootWallet?: WalletInstance | null
13
- /** Set currently selected index */
14
- setActiveAccountIndex?: Dispatch<number>
15
- }>
@@ -1,4 +0,0 @@
1
- export * from './Context.ts'
2
- export * from './Provider.tsx'
3
- export * from './State.ts'
4
- export * from './use.ts'
@@ -1,37 +0,0 @@
1
- import { usePromise } from '@xylabs/react-promise'
2
- import { useContextEx, useProvided } from '@xylabs/react-shared'
3
- import type { WalletInstance } from '@xyo-network/wallet-model'
4
-
5
- import { WalletContext } from './Context.ts'
6
-
7
- /** @public */
8
- export const useWalletContext = (required = true) => {
9
- return useContextEx(WalletContext, 'Wallet', required)
10
- }
11
-
12
- /** @public */
13
- export const useWalletProvided = () => {
14
- return useProvided(WalletContext)
15
- }
16
-
17
- /** @public */
18
- export const useRootWallet = (required = true): [WalletInstance | null | undefined, Error | undefined] => {
19
- const { rootWallet } = useWalletContext(required)
20
- return [rootWallet, undefined]
21
- }
22
-
23
- /** @public */
24
- export const useIndexedWalletFromContext = (index: number, required = true): [WalletInstance | null | undefined, Error | undefined] => {
25
- const { rootWallet } = useWalletContext(required)
26
- const [wallet] = usePromise(async () => (await rootWallet?.derivePath(index.toString())) ?? rootWallet, [rootWallet, index])
27
- return [wallet, undefined]
28
- }
29
-
30
- /** @public */
31
- export const useSelectedWalletAccount = (required = true): [WalletInstance | null | undefined, Error | undefined] => {
32
- const { activeAccountIndex } = useWalletContext(required)
33
- // we pass in 0 as default since we can not call the hook optionally,
34
- // we resolve this false result by checking whether activeAccountIndex is defined before returning it
35
- const [account] = useIndexedWalletFromContext(activeAccountIndex ?? 0, required)
36
- return activeAccountIndex === undefined && account === null ? [null, undefined] : [account, undefined]
37
- }
@@ -1,2 +0,0 @@
1
- export * from './SeedPhrase/index.ts'
2
- export * from './Wallet/index.ts'
@@ -1,4 +0,0 @@
1
- export * from './useAccount.ts'
2
- export * from './useWallet.ts'
3
- export * from './useWallets.ts'
4
- export * from './useWrapperAccount.ts'
@@ -1,68 +0,0 @@
1
- import { usePromise } from '@xylabs/react-promise'
2
- import type { AccountInstance } from '@xyo-network/account-model'
3
- import type { WalletInstance } from '@xyo-network/wallet-model'
4
- import { useState } from 'react'
5
-
6
- import {
7
- useRootWallet, useWalletContext, useWalletProvided,
8
- } from '../contexts/index.ts'
9
-
10
- /** @public */
11
- export interface AccountHookParams {
12
- account?: AccountInstance
13
- index?: number
14
- required?: boolean
15
- wallet?: WalletInstance
16
- }
17
-
18
- /** @public */
19
- export const useAccount = ({
20
- wallet, account, index, required = false,
21
- }: AccountHookParams = {}): [
22
- AccountInstance | null | undefined,
23
- Error | undefined,
24
- ] => {
25
- const walletContextProvided = useWalletProvided()
26
- const [validationError, setValidationError] = useState<Error>()
27
- if (wallet && account && !validationError) {
28
- setValidationError(new Error('useAccount can not have both a wallet and an account in the parameters'))
29
- }
30
-
31
- if (index && account && !validationError) {
32
- setValidationError(new Error('useAccount can not have both a index and an account in the parameters'))
33
- }
34
-
35
- const [error, setError] = useState<Error>()
36
- const [rootWallet] = useRootWallet(!wallet && required)
37
- const { activeAccountIndex } = useWalletContext(false)
38
- const [activeAccount] = usePromise(async () => {
39
- try {
40
- if (!validationError) {
41
- if (wallet) {
42
- const path = `${index ?? 0}'\0`
43
- return await wallet?.derivePath?.(path)
44
- } else if (rootWallet) {
45
- const path = `${index ?? activeAccountIndex ?? 0}'\/0`
46
- return await rootWallet?.derivePath?.(path)
47
- }
48
- }
49
- } catch (ex) {
50
- const error = ex as Error
51
- console.error(error.message)
52
- setError(error)
53
- }
54
- }, [index, wallet, rootWallet, activeAccountIndex, validationError])
55
- if (validationError && !error) {
56
- console.error(validationError.message)
57
- setError(validationError)
58
- }
59
-
60
- return [
61
- error
62
- ? undefined
63
- : (account ?? activeAccount ?? walletContextProvided)
64
- ? null
65
- : undefined,
66
- error,
67
- ]
68
- }
@@ -1,46 +0,0 @@
1
- import { usePromise } from '@xylabs/react-promise'
2
- import { HDWallet } from '@xyo-network/wallet'
3
- import type { WalletInstance } from '@xyo-network/wallet-model'
4
- import { useState } from 'react'
5
-
6
- import { useSelectedWalletAccount, useWalletContext } from '../contexts/index.ts'
7
-
8
- /** @public */
9
- export interface WalletHookParams {
10
- mnemonic?: string
11
- path?: string
12
- required?: boolean
13
- seed?: ArrayBufferLike | string
14
- wallet?: WalletInstance | null
15
- }
16
-
17
- /** @public */
18
- export const useWallet = ({
19
- mnemonic, wallet, path, required = false, seed,
20
- }: WalletHookParams = {}): [
21
- WalletInstance | null | undefined,
22
- Error | undefined,
23
- ] => {
24
- const walletContextProvided = useWalletContext(false)
25
- const [error, setError] = useState<Error>()
26
- const [contextAccount] = useSelectedWalletAccount(!wallet && required)
27
- const [activeAccount] = usePromise(async () => {
28
- try {
29
- const newAccount = await (() => {
30
- if (wallet) {
31
- return wallet
32
- } else if (mnemonic) {
33
- return HDWallet.fromPhrase(mnemonic)
34
- } else if (seed) {
35
- return HDWallet.fromSeed(seed)
36
- }
37
- return contextAccount
38
- })()
39
-
40
- return path ? newAccount?.derivePath?.(path) : (newAccount ?? wallet)
41
- } catch (ex) {
42
- setError(ex as Error)
43
- }
44
- }, [mnemonic, contextAccount, seed, path, wallet])
45
- return [activeAccount ?? (walletContextProvided ? null : activeAccount), error]
46
- }
@@ -1,22 +0,0 @@
1
- import { usePromise } from '@xylabs/react-promise'
2
- import type { WalletInstance } from '@xyo-network/wallet-model'
3
-
4
- import { useWalletContext } from '../contexts/index.ts'
5
- import { useWallet } from './useWallet.ts'
6
-
7
- /** @public */
8
- export interface WalletsHookParams {
9
- paths: string[]
10
- wallet?: WalletInstance | null
11
- }
12
-
13
- /** @public */
14
- export const useWallets = ({ wallet, paths }: WalletsHookParams): [WalletInstance[] | null | undefined, Error | undefined] => {
15
- const walletContextProvided = useWalletContext(false)
16
- const [foundWallet] = useWallet({ wallet })
17
- const [wallets, error] = usePromise(
18
- async () => (foundWallet ? await Promise.all(paths.map(path => foundWallet.derivePath(path))) : undefined),
19
- [foundWallet, paths],
20
- )
21
- return [wallets ?? (walletContextProvided ? null : wallets), error]
22
- }
@@ -1,36 +0,0 @@
1
- import type { UsePromiseState } from '@xylabs/react-promise'
2
- import { usePromise } from '@xylabs/react-promise'
3
- import type { AccountInstance } from '@xyo-network/account-model'
4
- import { HDWallet } from '@xyo-network/wallet'
5
- import type { WalletInstance } from '@xyo-network/wallet-model'
6
- import { Mutex } from 'async-mutex'
7
-
8
- let globalWrapperWallet: WalletInstance | undefined
9
- const globalWrapperWalletMutex = new Mutex()
10
-
11
- /** @public */
12
- export const useWrapperAccount = (
13
- account?: AccountInstance | null,
14
- ): [AccountInstance | null | undefined, Error | undefined, UsePromiseState | undefined] => {
15
- return usePromise(async () => {
16
- return await globalWrapperWalletMutex.runExclusive(async () => {
17
- // if we are expecting to receive a wallet or did receive on, return the override account
18
- if (account !== undefined) {
19
- return account
20
- }
21
-
22
- if (globalWrapperWallet) {
23
- return globalWrapperWallet
24
- }
25
-
26
- try {
27
- globalWrapperWallet = await HDWallet.random()
28
- console.log(`Global Wrapper Wallet Creation Success: ${globalWrapperWallet.address}`)
29
- } catch (ex) {
30
- const error = ex as Error
31
- console.error(`Global Wrapper Wallet Creation Failed: ${error.message}`)
32
- }
33
- return globalWrapperWallet
34
- })
35
- }, [account])
36
- }
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './components/index.ts'
2
- export * from './contexts/index.ts'
3
- export * from './hooks/index.ts'