@xyo-network/react-wallet 2.45.0-rc.9 → 2.45.0
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/WalletAccountDetails/WalletAccountDetails.js +1 -1
- package/dist/cjs/components/WalletAccountDetails/WalletAccountDetails.js.map +1 -1
- package/dist/cjs/components/WalletAccountSelect/Select.js +4 -4
- package/dist/cjs/components/WalletAccountSelect/Select.js.map +1 -1
- package/dist/cjs/contexts/Account/MemoryProvider.js.map +1 -1
- package/dist/cjs/contexts/Account/use.js +2 -1
- package/dist/cjs/contexts/Account/use.js.map +1 -1
- package/dist/cjs/contexts/Wallet/Provider.js +11 -2
- package/dist/cjs/contexts/Wallet/Provider.js.map +1 -1
- package/dist/docs.json +772 -763
- package/dist/esm/components/WalletAccountDetails/WalletAccountDetails.js +1 -1
- package/dist/esm/components/WalletAccountDetails/WalletAccountDetails.js.map +1 -1
- package/dist/esm/components/WalletAccountSelect/Select.js +4 -4
- package/dist/esm/components/WalletAccountSelect/Select.js.map +1 -1
- package/dist/esm/contexts/Account/MemoryProvider.js.map +1 -1
- package/dist/esm/contexts/Account/use.js +2 -1
- package/dist/esm/contexts/Account/use.js.map +1 -1
- package/dist/esm/contexts/Wallet/Provider.js +11 -2
- package/dist/esm/contexts/Wallet/Provider.js.map +1 -1
- package/dist/types/contexts/Account/MemoryProvider.d.ts +2 -2
- package/dist/types/contexts/Account/MemoryProvider.d.ts.map +1 -1
- package/dist/types/contexts/Account/State.d.ts +3 -3
- package/dist/types/contexts/Account/State.d.ts.map +1 -1
- package/dist/types/contexts/Account/use.d.ts +1 -1
- package/dist/types/contexts/Account/use.d.ts.map +1 -1
- package/dist/types/contexts/Wallet/Provider.d.ts +2 -2
- package/dist/types/contexts/Wallet/Provider.d.ts.map +1 -1
- package/dist/types/contexts/Wallet/State.d.ts +4 -4
- package/dist/types/contexts/Wallet/State.d.ts.map +1 -1
- package/package.json +14 -14
- package/src/components/WalletAccountDetails/WalletAccountDetails.tsx +1 -1
- package/src/components/WalletAccountDetails/WalletAccountDetailsWithProvider.stories.tsx +3 -2
- package/src/components/WalletAccountSelect/Select.tsx +4 -4
- package/src/components/WalletAccountSelect/WalletAccountSelect.stories.tsx +5 -5
- package/src/components/WalletAccountSelect/WalletAccountSelectBar.stories.tsx +8 -5
- package/src/components/WalletAccountSelect/WalletAccountSelectWithProvider.stories.tsx +3 -2
- package/src/contexts/Account/MemoryProvider.tsx +3 -3
- package/src/contexts/Account/State.ts +3 -3
- package/src/contexts/Account/use.ts +2 -1
- package/src/contexts/Wallet/Provider.tsx +14 -5
- package/src/contexts/Wallet/State.ts +4 -4
|
@@ -6,7 +6,7 @@ import { NumberStatus } from '@xylabs/react-number-status';
|
|
|
6
6
|
import { useNetwork } from '@xyo-network/react-network';
|
|
7
7
|
import { useAccount } from '../../contexts';
|
|
8
8
|
export const WalletAccountDetails = ({ exploreUrl = 'https://explore.xyo.network', account: accountProp, ...props }) => {
|
|
9
|
-
const
|
|
9
|
+
const [account = accountProp] = useAccount();
|
|
10
10
|
const { network } = useNetwork();
|
|
11
11
|
const exploreAddressUrl = `${exploreUrl}/recent?account=${account?.addressValue.hex}&network=${network?.name ?? 'main'}`;
|
|
12
12
|
return (_jsxs(FlexCol, { ...props, children: [_jsx(EthAccountButton, { address: EthAddress.fromString(account?.addressValue.hex) }), _jsxs(FlexRow, { gap: 1, children: [_jsx(NumberStatus, { rounded: true, title: "Tokens", value: 0, to: `${exploreAddressUrl}&schema=network.xyo.account.tokens`, target: "_blank" }), _jsx(NumberStatus, { rounded: true, title: "NFTs", value: 0, to: `${exploreAddressUrl}&schema=network.xyo.account.nfts`, target: "_blank" }), _jsx(NumberStatus, { rounded: true, title: "Signatures", value: 0, to: `${exploreAddressUrl}&schema=network.xyo.account.signatures`, target: "_blank" }), _jsx(NumberStatus, { rounded: true, title: "Signins", value: 0, to: `${exploreAddressUrl}&schema=network.xyo.account.signins`, target: "_blank" })] })] }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WalletAccountDetails.js","sourceRoot":"","sources":["../../../../src/components/WalletAccountDetails/WalletAccountDetails.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAgB,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAA;AAE1D,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AAEvD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAO3C,MAAM,CAAC,MAAM,oBAAoB,GAAwC,CAAC,EACxE,UAAU,GAAG,6BAA6B,EAC1C,OAAO,EAAE,WAAW,EACpB,GAAG,KAAK,EACT,EAAE,EAAE;IACH,MAAM,
|
|
1
|
+
{"version":3,"file":"WalletAccountDetails.js","sourceRoot":"","sources":["../../../../src/components/WalletAccountDetails/WalletAccountDetails.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAgB,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAA;AAE1D,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AAEvD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAO3C,MAAM,CAAC,MAAM,oBAAoB,GAAwC,CAAC,EACxE,UAAU,GAAG,6BAA6B,EAC1C,OAAO,EAAE,WAAW,EACpB,GAAG,KAAK,EACT,EAAE,EAAE;IACH,MAAM,CAAC,OAAO,GAAG,WAAW,CAAC,GAAG,UAAU,EAAE,CAAA;IAC5C,MAAM,EAAE,OAAO,EAAE,GAAG,UAAU,EAAE,CAAA;IAChC,MAAM,iBAAiB,GAAG,GAAG,UAAU,mBAAmB,OAAO,EAAE,YAAY,CAAC,GAAG,YAAY,OAAO,EAAE,IAAI,IAAI,MAAM,EAAE,CAAA;IAExH,OAAO,CACL,MAAC,OAAO,OAAK,KAAK,aAChB,KAAC,gBAAgB,IAAC,OAAO,EAAE,UAAU,CAAC,UAAU,CAAC,OAAO,EAAE,YAAY,CAAC,GAAG,CAAC,GAAI,EAC/E,MAAC,OAAO,IAAC,GAAG,EAAE,CAAC,aACb,KAAC,YAAY,IAAC,OAAO,QAAC,KAAK,EAAC,QAAQ,EAAC,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,GAAG,iBAAiB,oCAAoC,EAAE,MAAM,EAAC,QAAQ,GAAG,EAC/H,KAAC,YAAY,IAAC,OAAO,QAAC,KAAK,EAAC,MAAM,EAAC,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,GAAG,iBAAiB,kCAAkC,EAAE,MAAM,EAAC,QAAQ,GAAG,EAC3H,KAAC,YAAY,IAAC,OAAO,QAAC,KAAK,EAAC,YAAY,EAAC,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,GAAG,iBAAiB,wCAAwC,EAAE,MAAM,EAAC,QAAQ,GAAG,EACvI,KAAC,YAAY,IAAC,OAAO,QAAC,KAAK,EAAC,SAAS,EAAC,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,GAAG,iBAAiB,qCAAqC,EAAE,MAAM,EAAC,QAAQ,GAAG,IACzH,IACF,CACX,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -10,14 +10,14 @@ const arrayRange = (length, start = 0) => {
|
|
|
10
10
|
return Array.from(Array(length).keys()).map((x) => x + start);
|
|
11
11
|
};
|
|
12
12
|
export const WalletAccountSelect = ({ iconOnly, iconSize = 24, icons, maxAccounts = 1, size, ...props }) => {
|
|
13
|
-
const {
|
|
13
|
+
const { activeAccountIndex = 0, setActiveAccountIndex, wallet } = useWallet();
|
|
14
14
|
return (_jsx(SelectEx, { renderValue: (selected) => {
|
|
15
|
-
const account = wallet?.
|
|
15
|
+
const account = wallet?.deriveAccount(selected.toString());
|
|
16
16
|
return (_jsxs(FlexRow, { justifyContent: "flex-start", gap: 1, children: [icons ? (_jsx(FlexRow, { children: _jsx(Identicon, { size: iconSize, value: account?.addressValue.hex }) })) : null, _jsx(EthAccountBox, { alignItems: "stretch", iconOnly: iconOnly, address: EthAddress.fromString(account?.addressValue.hex) })] }));
|
|
17
17
|
}, value: activeAccountIndex, onChange: (event) => setActiveAccountIndex?.(parseInt(`${event.target.value}`)), size: size, variant: "outlined", ...props, children: wallet
|
|
18
18
|
? arrayRange(maxAccounts).map((index) => {
|
|
19
|
-
const account = wallet?.
|
|
20
|
-
return (_jsx(MenuItem, { value: index, children: _jsx(EthAccountBox, { iconSize: iconSize, icon: icons, address: EthAddress.fromString(account
|
|
19
|
+
const account = wallet?.deriveAccount(index.toString());
|
|
20
|
+
return (_jsx(MenuItem, { value: index, children: _jsx(EthAccountBox, { iconSize: iconSize, icon: icons, address: EthAddress.fromString(account?.addressValue.hex) }) }, index));
|
|
21
21
|
})
|
|
22
22
|
: null }));
|
|
23
23
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Select.js","sourceRoot":"","sources":["../../../../src/components/WalletAccountSelect/Select.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAe,MAAM,eAAe,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAEnD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CA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AAK,YAChC,KAAC,aAAa,IAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,CAAC,UAAU,CAAC,OAAO,EAAE,YAAY,CAAC,GAAG,CAAC,GAAI,IADhG,KAAK,CAET,CACZ,CAAA;YACH,CAAC,CAAC;YACJ,CAAC,CAAC,IAAI,GACC,CACZ,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,CAA8B,cAAc,CAAC,CAAA;IAEnF,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,6 +1,7 @@
|
|
|
1
1
|
import { useContextEx } from '@xyo-network/react-shared';
|
|
2
2
|
import { AccountContext } from './Context';
|
|
3
3
|
export const useAccount = (required = false) => {
|
|
4
|
-
|
|
4
|
+
const { account } = useContextEx(AccountContext, 'Account', required);
|
|
5
|
+
return [account];
|
|
5
6
|
};
|
|
6
7
|
//# sourceMappingURL=use.js.map
|
|
@@ -1 +1 @@
|
|
|
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,UAAU,GAAG,CAAC,QAAQ,GAAG,KAAK,EAAE,EAAE;IAC7C,OAAO,YAAY,CAAC,cAAc,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAA;
|
|
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,UAAU,GAAG,CAAC,QAAQ,GAAG,KAAK,EAAE,EAAE;IAC7C,MAAM,EAAE,OAAO,EAAE,GAAG,YAAY,CAAC,cAAc,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAA;IACrE,OAAO,CAAC,OAAO,CAAC,CAAA;AAClB,CAAC,CAAA"}
|
|
@@ -3,9 +3,11 @@ import { useEffect, useState } from 'react';
|
|
|
3
3
|
import { AccountContext } from '../Account';
|
|
4
4
|
import { WalletContext } from './Context';
|
|
5
5
|
import { useWallet } from './use';
|
|
6
|
+
const WalletBase = 'm';
|
|
7
|
+
const WalletRootPath = "44'/60'/0'/0";
|
|
6
8
|
const AccountWalletProvider = (props) => {
|
|
7
9
|
const { wallet, activeAccountIndex = 0 } = useWallet();
|
|
8
|
-
return _jsx(AccountContext.Provider, { value: { account: wallet?.
|
|
10
|
+
return _jsx(AccountContext.Provider, { value: { account: wallet?.deriveAccount(activeAccountIndex.toString()), provided: true }, ...props });
|
|
9
11
|
};
|
|
10
12
|
export const WalletProvider = ({ children, defaultActiveAccountIndex = 0, defaultWallet, ...props }) => {
|
|
11
13
|
const [wallet, setWallet] = useState(defaultWallet);
|
|
@@ -16,8 +18,15 @@ export const WalletProvider = ({ children, defaultActiveAccountIndex = 0, defaul
|
|
|
16
18
|
}
|
|
17
19
|
}, [defaultActiveAccountIndex]);
|
|
18
20
|
useEffect(() => {
|
|
21
|
+
// ensure the wallet has the proper base
|
|
19
22
|
if (defaultWallet) {
|
|
20
|
-
|
|
23
|
+
try {
|
|
24
|
+
const walletWithBasePath = defaultWallet?.derivePath(WalletBase).derivePath(WalletRootPath);
|
|
25
|
+
setWallet(walletWithBasePath);
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
console.error('Error setting proper wallet base path', e);
|
|
29
|
+
}
|
|
21
30
|
}
|
|
22
31
|
}, [defaultWallet]);
|
|
23
32
|
return (_jsx(WalletContext.Provider, { value: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Provider.js","sourceRoot":"","sources":["../../../../src/contexts/Wallet/Provider.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAE3C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"Provider.js","sourceRoot":"","sources":["../../../../src/contexts/Wallet/Provider.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAE3C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,EA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AK,CAAC,uCAAuC,EAAE,CAAC,CAAC,CAAA;aAC1D;SACF;IACH,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAA;IAEnB,OAAO,CACL,KAAC,aAAa,CAAC,QAAQ,IACrB,KAAK,EAAE;YACL,kBAAkB;YAClB,QAAQ,EAAE,IAAI;YACd,qBAAqB;YACrB,SAAS;YACT,MAAM;SACP,KACG,KAAK,YAET,KAAC,qBAAqB,cAAE,QAAQ,GAAyB,GAClC,CAC1B,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { WithChildren } from '@xylabs/react-shared';
|
|
3
|
-
import {
|
|
3
|
+
import { AccountInstance } from '@xyo-network/account-model';
|
|
4
4
|
export interface AccountMemoryProviderProps {
|
|
5
|
-
defaultAccount?:
|
|
5
|
+
defaultAccount?: AccountInstance;
|
|
6
6
|
}
|
|
7
7
|
export declare const AccountMemoryProvider: React.FC<WithChildren<AccountMemoryProviderProps>>;
|
|
8
8
|
//# sourceMappingURL=MemoryProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAK5D,MAAM,WAAW,0BAA0B;IACzC,cAAc,CAAC,EAAE,eAAe,CAAA;CACjC;AAED,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,0BAA0B,CAAC,CAIpF,CAAA"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AccountInstance } from '@xyo-network/account-model';
|
|
2
2
|
import { ContextExState } from '@xyo-network/react-shared';
|
|
3
3
|
import { Dispatch } from 'react';
|
|
4
4
|
export interface AccountContextState extends ContextExState {
|
|
5
|
-
account?:
|
|
6
|
-
setAccount?: Dispatch<
|
|
5
|
+
account?: AccountInstance;
|
|
6
|
+
setAccount?: Dispatch<AccountInstance>;
|
|
7
7
|
}
|
|
8
8
|
//# sourceMappingURL=State.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"State.d.ts","sourceRoot":"","sources":["../../../../src/contexts/Account/State.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"State.d.ts","sourceRoot":"","sources":["../../../../src/contexts/Account/State.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAC5D,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,eAAe,CAAA;IACzB,UAAU,CAAC,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAA;CACvC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const useAccount: (required?: boolean) =>
|
|
1
|
+
export declare const useAccount: (required?: boolean) => (import("@xyo-network/account-model").AccountInstance | undefined)[];
|
|
2
2
|
//# sourceMappingURL=use.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use.d.ts","sourceRoot":"","sources":["../../../../src/contexts/Account/use.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"use.d.ts","sourceRoot":"","sources":["../../../../src/contexts/Account/use.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,UAAU,8FAGtB,CAAA"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { WithChildren } from '@xylabs/react-shared';
|
|
3
|
-
import {
|
|
3
|
+
import { HDWallet } from '@xyo-network/account';
|
|
4
4
|
export interface WalletProviderProps {
|
|
5
5
|
defaultActiveAccountIndex?: number;
|
|
6
|
-
defaultWallet?:
|
|
6
|
+
defaultWallet?: HDWallet;
|
|
7
7
|
}
|
|
8
8
|
export declare const WalletProvider: React.FC<WithChildren<WalletProviderProps>>;
|
|
9
9
|
//# sourceMappingURL=Provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../../../../src/contexts/Wallet/Provider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACnD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../../../../src/contexts/Wallet/Provider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAU/C,MAAM,WAAW,mBAAmB;IAClC,yBAAyB,CAAC,EAAE,MAAM,CAAA;IAClC,aAAa,CAAC,EAAE,QAAQ,CAAA;CACzB;AAQD,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,mBAAmB,CAAC,CAoCtE,CAAA"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { HDWallet } from '@xyo-network/account';
|
|
1
2
|
import { ContextExState } from '@xyo-network/react-shared';
|
|
2
|
-
import {
|
|
3
|
-
import { Dispatch } from 'react';
|
|
3
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
4
4
|
export interface WalletContextState extends ContextExState {
|
|
5
5
|
activeAccountIndex?: number;
|
|
6
6
|
setActiveAccountIndex?: Dispatch<number>;
|
|
7
|
-
setWallet?: Dispatch<
|
|
8
|
-
wallet?:
|
|
7
|
+
setWallet?: Dispatch<SetStateAction<HDWallet | undefined>>;
|
|
8
|
+
wallet?: HDWallet;
|
|
9
9
|
}
|
|
10
10
|
//# sourceMappingURL=State.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"State.d.ts","sourceRoot":"","sources":["../../../../src/contexts/Wallet/State.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"State.d.ts","sourceRoot":"","sources":["../../../../src/contexts/Wallet/State.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAEhD,MAAM,WAAW,kBAAmB,SAAQ,cAAc;IACxD,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,qBAAqB,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAA;IACxC,SAAS,CAAC,EAAE,QAAQ,CAAC,cAAc,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAA;IAC1D,MAAM,CAAC,EAAE,QAAQ,CAAA;CAClB"}
|
package/package.json
CHANGED
|
@@ -12,14 +12,16 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@scure/bip39": "^1.1.1",
|
|
14
14
|
"@xylabs/eth-address": "^2.7.4",
|
|
15
|
-
"@xylabs/react-common": "^2.16.
|
|
16
|
-
"@xylabs/react-crypto": "^2.16.
|
|
17
|
-
"@xylabs/react-flexbox": "^2.16.
|
|
18
|
-
"@xylabs/react-identicon": "^2.16.
|
|
19
|
-
"@xylabs/react-number-status": "^2.16.
|
|
20
|
-
"@xylabs/react-shared": "^2.16.
|
|
21
|
-
"@xyo-network/
|
|
22
|
-
"@xyo-network/
|
|
15
|
+
"@xylabs/react-common": "^2.16.11",
|
|
16
|
+
"@xylabs/react-crypto": "^2.16.11",
|
|
17
|
+
"@xylabs/react-flexbox": "^2.16.11",
|
|
18
|
+
"@xylabs/react-identicon": "^2.16.11",
|
|
19
|
+
"@xylabs/react-number-status": "^2.16.11",
|
|
20
|
+
"@xylabs/react-shared": "^2.16.11",
|
|
21
|
+
"@xyo-network/account": "^2.51.7",
|
|
22
|
+
"@xyo-network/account-model": "^2.51.7",
|
|
23
|
+
"@xyo-network/react-network": "^2.45.0",
|
|
24
|
+
"@xyo-network/react-shared": "^2.45.0"
|
|
23
25
|
},
|
|
24
26
|
"peerDependencies": {
|
|
25
27
|
"@mui/icons-material": "^5",
|
|
@@ -34,10 +36,9 @@
|
|
|
34
36
|
"description": "Common React library for all XYO projects that use React",
|
|
35
37
|
"devDependencies": {
|
|
36
38
|
"@storybook/react": "^6.5.16",
|
|
37
|
-
"@xylabs/ts-scripts-yarn3": "^2.16.
|
|
38
|
-
"@xylabs/tsconfig-react": "^2.16.
|
|
39
|
-
"@xyo-network/
|
|
40
|
-
"@xyo-network/wallet": "^2.51.2",
|
|
39
|
+
"@xylabs/ts-scripts-yarn3": "^2.16.1",
|
|
40
|
+
"@xylabs/tsconfig-react": "^2.16.1",
|
|
41
|
+
"@xyo-network/react-storybook": "^2.45.0",
|
|
41
42
|
"require-from-string": "^2.0.2",
|
|
42
43
|
"typescript": "^4.9.5"
|
|
43
44
|
},
|
|
@@ -83,6 +84,5 @@
|
|
|
83
84
|
},
|
|
84
85
|
"sideEffects": false,
|
|
85
86
|
"types": "dist/types/index.d.ts",
|
|
86
|
-
"version": "2.45.0
|
|
87
|
-
"stableVersion": "2.44.1"
|
|
87
|
+
"version": "2.45.0"
|
|
88
88
|
}
|
|
@@ -17,7 +17,7 @@ export const WalletAccountDetails: React.FC<WalletAccountDetailsProps> = ({
|
|
|
17
17
|
account: accountProp,
|
|
18
18
|
...props
|
|
19
19
|
}) => {
|
|
20
|
-
const
|
|
20
|
+
const [account = accountProp] = useAccount()
|
|
21
21
|
const { network } = useNetwork()
|
|
22
22
|
const exploreAddressUrl = `${exploreUrl}/recent?account=${account?.addressValue.hex}&network=${network?.name ?? 'main'}`
|
|
23
23
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ComponentMeta, ComponentStory } from '@storybook/react'
|
|
2
|
-
import {
|
|
2
|
+
import { HDWallet } from '@xyo-network/account'
|
|
3
|
+
import { DefaultSeedPhrase } from '@xyo-network/react-storybook'
|
|
3
4
|
import { BrowserRouter } from 'react-router-dom'
|
|
4
5
|
|
|
5
6
|
import { WalletProvider } from '../../contexts'
|
|
@@ -19,7 +20,7 @@ const StorybookEntry = {
|
|
|
19
20
|
const Template: ComponentStory<typeof WalletAccountDetails> = (args) => {
|
|
20
21
|
return (
|
|
21
22
|
<BrowserRouter>
|
|
22
|
-
<WalletProvider defaultWallet={
|
|
23
|
+
<WalletProvider defaultWallet={HDWallet.fromMnemonic(DefaultSeedPhrase)}>
|
|
23
24
|
<WalletAccountDetails {...args}></WalletAccountDetails>
|
|
24
25
|
</WalletProvider>
|
|
25
26
|
</BrowserRouter>
|
|
@@ -19,12 +19,12 @@ const arrayRange = (length: number, start = 0) => {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export const WalletAccountSelect: React.FC<WalletAccountSelectProps> = ({ iconOnly, iconSize = 24, icons, maxAccounts = 1, size, ...props }) => {
|
|
22
|
-
const {
|
|
22
|
+
const { activeAccountIndex = 0, setActiveAccountIndex, wallet } = useWallet()
|
|
23
23
|
|
|
24
24
|
return (
|
|
25
25
|
<SelectEx
|
|
26
26
|
renderValue={(selected) => {
|
|
27
|
-
const account = wallet?.
|
|
27
|
+
const account = wallet?.deriveAccount(selected.toString())
|
|
28
28
|
return (
|
|
29
29
|
<FlexRow justifyContent="flex-start" gap={1}>
|
|
30
30
|
{icons ? (
|
|
@@ -44,10 +44,10 @@ export const WalletAccountSelect: React.FC<WalletAccountSelectProps> = ({ iconOn
|
|
|
44
44
|
>
|
|
45
45
|
{wallet
|
|
46
46
|
? arrayRange(maxAccounts).map((index) => {
|
|
47
|
-
const account = wallet?.
|
|
47
|
+
const account = wallet?.deriveAccount(index.toString())
|
|
48
48
|
return (
|
|
49
49
|
<MenuItem key={index} value={index}>
|
|
50
|
-
<EthAccountBox iconSize={iconSize} icon={icons} address={EthAddress.fromString(account
|
|
50
|
+
<EthAccountBox iconSize={iconSize} icon={icons} address={EthAddress.fromString(account?.addressValue.hex)} />
|
|
51
51
|
</MenuItem>
|
|
52
52
|
)
|
|
53
53
|
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/* eslint-disable import/no-internal-modules */
|
|
2
1
|
import { ComponentMeta, ComponentStory } from '@storybook/react'
|
|
3
|
-
import {
|
|
2
|
+
import { HDWallet } from '@xyo-network/account'
|
|
3
|
+
import { DefaultSeedPhrase } from '@xyo-network/react-storybook'
|
|
4
4
|
|
|
5
5
|
import { WalletProvider } from '../../contexts'
|
|
6
6
|
import { WalletAccountSelect } from './Select'
|
|
@@ -17,13 +17,13 @@ const StorybookEntry = {
|
|
|
17
17
|
} as ComponentMeta<typeof WalletAccountSelect>
|
|
18
18
|
|
|
19
19
|
const Template: ComponentStory<typeof WalletAccountSelect> = (args) => {
|
|
20
|
-
return <WalletAccountSelect {...args}
|
|
20
|
+
return <WalletAccountSelect {...args} />
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
const WithWalletTemplate: ComponentStory<typeof WalletAccountSelect> = (args) => {
|
|
24
24
|
return (
|
|
25
|
-
<WalletProvider defaultWallet={
|
|
26
|
-
<WalletAccountSelect {...args}
|
|
25
|
+
<WalletProvider defaultWallet={HDWallet.fromMnemonic(DefaultSeedPhrase)}>
|
|
26
|
+
<WalletAccountSelect {...args} />
|
|
27
27
|
</WalletProvider>
|
|
28
28
|
)
|
|
29
29
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/* eslint-disable import/no-internal-modules */
|
|
2
1
|
import { ComponentMeta, ComponentStory } from '@storybook/react'
|
|
3
|
-
import {
|
|
2
|
+
import { HDWallet } from '@xyo-network/account'
|
|
3
|
+
import { DefaultSeedPhrase } from '@xyo-network/react-storybook'
|
|
4
4
|
|
|
5
5
|
import { WalletProvider } from '../../contexts'
|
|
6
6
|
import { WalletAccountSelectBar } from './SelectBar'
|
|
@@ -22,8 +22,8 @@ const Template: ComponentStory<typeof WalletAccountSelectBar> = (args) => {
|
|
|
22
22
|
|
|
23
23
|
const WithWalletTemplate: ComponentStory<typeof WalletAccountSelectBar> = (args) => {
|
|
24
24
|
return (
|
|
25
|
-
<WalletProvider defaultWallet={
|
|
26
|
-
<WalletAccountSelectBar {...args}
|
|
25
|
+
<WalletProvider defaultWallet={HDWallet.fromMnemonic(DefaultSeedPhrase)}>
|
|
26
|
+
<WalletAccountSelectBar {...args} />
|
|
27
27
|
</WalletProvider>
|
|
28
28
|
)
|
|
29
29
|
}
|
|
@@ -37,7 +37,10 @@ WithWallet.args = {}
|
|
|
37
37
|
const WithWalletIcon = WithWalletTemplate.bind({})
|
|
38
38
|
WithWalletIcon.args = { icons: true }
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
const WithAdditionalAccounts = WithWalletTemplate.bind({})
|
|
41
|
+
WithAdditionalAccounts.args = { icons: true, maxAccounts: 10 }
|
|
42
|
+
|
|
43
|
+
export { Default, WithAdditionalAccounts, WithWallet, WithWalletIcon }
|
|
41
44
|
|
|
42
45
|
// eslint-disable-next-line import/no-default-export
|
|
43
46
|
export default StorybookEntry
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ComponentMeta, ComponentStory } from '@storybook/react'
|
|
2
|
-
import {
|
|
2
|
+
import { HDWallet } from '@xyo-network/account'
|
|
3
|
+
import { DefaultSeedPhrase } from '@xyo-network/react-storybook'
|
|
3
4
|
|
|
4
5
|
import { WalletProvider } from '../../contexts'
|
|
5
6
|
import { WalletAccountSelect } from './Select'
|
|
@@ -17,7 +18,7 @@ const StorybookEntry = {
|
|
|
17
18
|
|
|
18
19
|
const Template: ComponentStory<typeof WalletAccountSelect> = (args) => {
|
|
19
20
|
return (
|
|
20
|
-
<WalletProvider defaultWallet={
|
|
21
|
+
<WalletProvider defaultWallet={HDWallet.fromMnemonic(DefaultSeedPhrase)}>
|
|
21
22
|
<WalletAccountSelect {...args}></WalletAccountSelect>
|
|
22
23
|
</WalletProvider>
|
|
23
24
|
)
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { WithChildren } from '@xylabs/react-shared'
|
|
2
|
-
import {
|
|
2
|
+
import { AccountInstance } from '@xyo-network/account-model'
|
|
3
3
|
import { useState } from 'react'
|
|
4
4
|
|
|
5
5
|
import { AccountContext } from './Context'
|
|
6
6
|
|
|
7
7
|
export interface AccountMemoryProviderProps {
|
|
8
|
-
defaultAccount?:
|
|
8
|
+
defaultAccount?: AccountInstance
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export const AccountMemoryProvider: React.FC<WithChildren<AccountMemoryProviderProps>> = ({ defaultAccount, ...props }) => {
|
|
12
|
-
const [account, setAccount] = useState<
|
|
12
|
+
const [account, setAccount] = useState<AccountInstance | undefined>(defaultAccount)
|
|
13
13
|
|
|
14
14
|
return <AccountContext.Provider value={{ account: account, provided: true, setAccount }} {...props} />
|
|
15
15
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AccountInstance } from '@xyo-network/account-model'
|
|
2
2
|
import { ContextExState } from '@xyo-network/react-shared'
|
|
3
3
|
import { Dispatch } from 'react'
|
|
4
4
|
|
|
5
5
|
export interface AccountContextState extends ContextExState {
|
|
6
|
-
account?:
|
|
7
|
-
setAccount?: Dispatch<
|
|
6
|
+
account?: AccountInstance
|
|
7
|
+
setAccount?: Dispatch<AccountInstance>
|
|
8
8
|
}
|
|
@@ -3,5 +3,6 @@ import { useContextEx } from '@xyo-network/react-shared'
|
|
|
3
3
|
import { AccountContext } from './Context'
|
|
4
4
|
|
|
5
5
|
export const useAccount = (required = false) => {
|
|
6
|
-
|
|
6
|
+
const { account } = useContextEx(AccountContext, 'Account', required)
|
|
7
|
+
return [account]
|
|
7
8
|
}
|
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
import { WithChildren } from '@xylabs/react-shared'
|
|
2
|
-
import {
|
|
2
|
+
import { HDWallet } from '@xyo-network/account'
|
|
3
3
|
import { useEffect, useState } from 'react'
|
|
4
4
|
|
|
5
5
|
import { AccountContext } from '../Account'
|
|
6
6
|
import { WalletContext } from './Context'
|
|
7
7
|
import { useWallet } from './use'
|
|
8
8
|
|
|
9
|
+
const WalletBase = 'm'
|
|
10
|
+
const WalletRootPath = "44'/60'/0'/0"
|
|
11
|
+
|
|
9
12
|
export interface WalletProviderProps {
|
|
10
13
|
defaultActiveAccountIndex?: number
|
|
11
|
-
defaultWallet?:
|
|
14
|
+
defaultWallet?: HDWallet
|
|
12
15
|
}
|
|
13
16
|
|
|
14
17
|
const AccountWalletProvider: React.FC<WithChildren> = (props) => {
|
|
15
18
|
const { wallet, activeAccountIndex = 0 } = useWallet()
|
|
16
19
|
|
|
17
|
-
return <AccountContext.Provider value={{ account: wallet?.
|
|
20
|
+
return <AccountContext.Provider value={{ account: wallet?.deriveAccount(activeAccountIndex.toString()), provided: true }} {...props} />
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
export const WalletProvider: React.FC<WithChildren<WalletProviderProps>> = ({ children, defaultActiveAccountIndex = 0, defaultWallet, ...props }) => {
|
|
21
|
-
const [wallet, setWallet] = useState<
|
|
24
|
+
const [wallet, setWallet] = useState<HDWallet | undefined>(defaultWallet)
|
|
22
25
|
const [activeAccountIndex, setActiveAccountIndex] = useState(defaultActiveAccountIndex)
|
|
23
26
|
|
|
24
27
|
useEffect(() => {
|
|
@@ -28,8 +31,14 @@ export const WalletProvider: React.FC<WithChildren<WalletProviderProps>> = ({ ch
|
|
|
28
31
|
}, [defaultActiveAccountIndex])
|
|
29
32
|
|
|
30
33
|
useEffect(() => {
|
|
34
|
+
// ensure the wallet has the proper base
|
|
31
35
|
if (defaultWallet) {
|
|
32
|
-
|
|
36
|
+
try {
|
|
37
|
+
const walletWithBasePath = defaultWallet?.derivePath(WalletBase).derivePath(WalletRootPath)
|
|
38
|
+
setWallet(walletWithBasePath)
|
|
39
|
+
} catch (e) {
|
|
40
|
+
console.error('Error setting proper wallet base path', e)
|
|
41
|
+
}
|
|
33
42
|
}
|
|
34
43
|
}, [defaultWallet])
|
|
35
44
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { HDWallet } from '@xyo-network/account'
|
|
1
2
|
import { ContextExState } from '@xyo-network/react-shared'
|
|
2
|
-
import {
|
|
3
|
-
import { Dispatch } from 'react'
|
|
3
|
+
import { Dispatch, SetStateAction } from 'react'
|
|
4
4
|
|
|
5
5
|
export interface WalletContextState extends ContextExState {
|
|
6
6
|
activeAccountIndex?: number
|
|
7
7
|
setActiveAccountIndex?: Dispatch<number>
|
|
8
|
-
setWallet?: Dispatch<
|
|
9
|
-
wallet?:
|
|
8
|
+
setWallet?: Dispatch<SetStateAction<HDWallet | undefined>>
|
|
9
|
+
wallet?: HDWallet
|
|
10
10
|
}
|