@sundaeswap/wallet-lite 0.0.47 → 0.0.48
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/react-components/RenderWallet.js +1 -3
- package/dist/cjs/react-components/RenderWallet.js.map +1 -1
- package/dist/cjs/react-components/RenderWalletHandles.js +1 -3
- package/dist/cjs/react-components/RenderWalletHandles.js.map +1 -1
- package/dist/cjs/react-components/RenderWalletPeerConnect.js.map +1 -1
- package/dist/cjs/react-components/RenderWalletState.js +2 -3
- package/dist/cjs/react-components/RenderWalletState.js.map +1 -1
- package/dist/cjs/react-components/WalletObserverProvider/hooks/useWalletObserverState.js +25 -33
- package/dist/cjs/react-components/WalletObserverProvider/hooks/useWalletObserverState.js.map +1 -1
- package/dist/cjs/react-components/hooks/useWalletHandles.js +128 -137
- package/dist/cjs/react-components/hooks/useWalletHandles.js.map +1 -1
- package/dist/cjs/react-components/hooks/useWalletObserver.js +1 -2
- package/dist/cjs/react-components/hooks/useWalletObserver.js.map +1 -1
- package/dist/esm/react-components/RenderWallet.js +1 -3
- package/dist/esm/react-components/RenderWallet.js.map +1 -1
- package/dist/esm/react-components/RenderWalletHandles.js +1 -3
- package/dist/esm/react-components/RenderWalletHandles.js.map +1 -1
- package/dist/esm/react-components/RenderWalletPeerConnect.js.map +1 -1
- package/dist/esm/react-components/RenderWalletState.js +2 -2
- package/dist/esm/react-components/RenderWalletState.js.map +1 -1
- package/dist/esm/react-components/WalletObserverProvider/hooks/useWalletObserverState.js +1 -5
- package/dist/esm/react-components/WalletObserverProvider/hooks/useWalletObserverState.js.map +1 -1
- package/dist/esm/react-components/hooks/useWalletHandles.js +62 -68
- package/dist/esm/react-components/hooks/useWalletHandles.js.map +1 -1
- package/dist/esm/react-components/hooks/useWalletObserver.js +1 -2
- package/dist/esm/react-components/hooks/useWalletObserver.js.map +1 -1
- package/dist/types/react-components/RenderWallet.d.ts +4 -4
- package/dist/types/react-components/RenderWallet.d.ts.map +1 -1
- package/dist/types/react-components/RenderWalletHandles.d.ts +5 -5
- package/dist/types/react-components/RenderWalletHandles.d.ts.map +1 -1
- package/dist/types/react-components/RenderWalletPeerConnect.d.ts +5 -5
- package/dist/types/react-components/RenderWalletPeerConnect.d.ts.map +1 -1
- package/dist/types/react-components/RenderWalletState.d.ts +5 -5
- package/dist/types/react-components/RenderWalletState.d.ts.map +1 -1
- package/dist/types/react-components/WalletObserverProvider/hooks/useWalletObserverState.d.ts +1 -4
- package/dist/types/react-components/WalletObserverProvider/hooks/useWalletObserverState.d.ts.map +1 -1
- package/dist/types/react-components/hooks/useWalletHandles.d.ts +3 -3
- package/dist/types/react-components/hooks/useWalletHandles.d.ts.map +1 -1
- package/dist/types/react-components/hooks/useWalletObserver.d.ts.map +1 -1
- package/dist/types/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +7 -6
- package/src/react-components/RenderWallet.tsx +11 -7
- package/src/react-components/RenderWalletHandles.tsx +15 -11
- package/src/react-components/RenderWalletPeerConnect.tsx +14 -10
- package/src/react-components/RenderWalletState.tsx +16 -12
- package/src/react-components/WalletObserverProvider/hooks/useWalletObserverState.ts +1 -12
- package/src/react-components/__tests__/RenderWalletHandles.test.tsx +7 -3
- package/src/react-components/hooks/useWalletHandles.ts +92 -108
- package/src/react-components/hooks/useWalletObserver.ts +0 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sundaeswap/wallet-lite",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.48",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/cjs/index.js",
|
|
@@ -36,19 +36,20 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@babel/cli": "^7.24.7",
|
|
39
|
-
"@cardano-sdk/core": "^0.33.0",
|
|
40
|
-
"@cardano-sdk/dapp-connector": "^0.12.19",
|
|
41
|
-
"@cardano-sdk/util": "^0.15.1",
|
|
42
39
|
"@fabianbormann/cardano-peer-connect": "^1.2.17",
|
|
43
40
|
"@koralabs/adahandle-sdk": "^1.5.4",
|
|
44
41
|
"@sundaeswap/asset": "^0.7.1",
|
|
45
42
|
"@sundaeswap/fraction": "0.5.9",
|
|
46
|
-
"lodash": "^4.17.21",
|
|
47
43
|
"rxjs": "^7.8.1"
|
|
48
44
|
},
|
|
49
45
|
"peerDependencies": {
|
|
50
46
|
"react": "^18.3.1",
|
|
51
|
-
"react-error-boundary": "^4.0.13"
|
|
47
|
+
"react-error-boundary": "^4.0.13",
|
|
48
|
+
"@tanstack/react-query": "^5.51.11",
|
|
49
|
+
"lodash": "^4.17.21",
|
|
50
|
+
"@cardano-sdk/core": "^0.33.0",
|
|
51
|
+
"@cardano-sdk/dapp-connector": "^0.12.19",
|
|
52
|
+
"@cardano-sdk/util": "^0.15.1"
|
|
52
53
|
},
|
|
53
54
|
"devDependencies": {
|
|
54
55
|
"@babel/core": "^7.24.7",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IAssetAmountMetadata } from "@sundaeswap/asset";
|
|
2
|
-
import {
|
|
2
|
+
import { ReactElement, ReactNode, Suspense } from "react";
|
|
3
3
|
|
|
4
4
|
import { ErrorBoundary } from "react-error-boundary";
|
|
5
5
|
import { useWalletObserver } from "./hooks/useWalletObserver.js";
|
|
@@ -12,8 +12,10 @@ export type TRenderWalletFunction<
|
|
|
12
12
|
T extends IAssetAmountMetadata = IAssetAmountMetadata,
|
|
13
13
|
> = (state: TRenderWalletFunctionState<T>) => JSX.Element | ReactNode;
|
|
14
14
|
|
|
15
|
-
export interface IRenderWalletProps
|
|
16
|
-
|
|
15
|
+
export interface IRenderWalletProps<
|
|
16
|
+
T extends IAssetAmountMetadata = IAssetAmountMetadata,
|
|
17
|
+
> {
|
|
18
|
+
render: TRenderWalletFunction<T>;
|
|
17
19
|
loader?: ReactNode;
|
|
18
20
|
fallback?: ReactElement;
|
|
19
21
|
}
|
|
@@ -24,16 +26,18 @@ export interface IRenderWalletProps {
|
|
|
24
26
|
* compose on this and include state for Handles, PeerConnect (CIP-45),
|
|
25
27
|
* and syncing state (RenderWalletState).
|
|
26
28
|
*/
|
|
27
|
-
export const RenderWallet
|
|
29
|
+
export const RenderWallet = <
|
|
30
|
+
T extends IAssetAmountMetadata = IAssetAmountMetadata,
|
|
31
|
+
>({
|
|
28
32
|
render,
|
|
29
33
|
loader,
|
|
30
34
|
fallback,
|
|
31
|
-
}) => {
|
|
32
|
-
const state = useWalletObserver();
|
|
35
|
+
}: IRenderWalletProps<T>) => {
|
|
36
|
+
const state = useWalletObserver<T>();
|
|
33
37
|
|
|
34
38
|
return (
|
|
35
39
|
<ErrorBoundary
|
|
36
|
-
fallback={fallback ||
|
|
40
|
+
fallback={fallback || null}
|
|
37
41
|
onError={(error) => {
|
|
38
42
|
if (state.observer.getOptions().debug) {
|
|
39
43
|
console.log(error.message, error.stack);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IAssetAmountMetadata } from "@sundaeswap/asset";
|
|
2
|
-
import {
|
|
2
|
+
import { ReactElement, ReactNode, Suspense } from "react";
|
|
3
3
|
|
|
4
4
|
import { ErrorBoundary } from "react-error-boundary";
|
|
5
5
|
import { useWalletHandles } from "./hooks/useWalletHandles.js";
|
|
@@ -10,12 +10,14 @@ export type TRenderWalletHandlesFunctionState<
|
|
|
10
10
|
> = ReturnType<typeof useWalletObserver<T>> &
|
|
11
11
|
ReturnType<typeof useWalletHandles<T>>;
|
|
12
12
|
|
|
13
|
-
export type TRenderWalletHandlesFunction
|
|
14
|
-
|
|
15
|
-
) => JSX.Element | ReactNode;
|
|
13
|
+
export type TRenderWalletHandlesFunction<
|
|
14
|
+
T extends IAssetAmountMetadata = IAssetAmountMetadata,
|
|
15
|
+
> = (state: TRenderWalletHandlesFunctionState<T>) => JSX.Element | ReactNode;
|
|
16
16
|
|
|
17
|
-
export interface IRenderWalletHandlesProps
|
|
18
|
-
|
|
17
|
+
export interface IRenderWalletHandlesProps<
|
|
18
|
+
T extends IAssetAmountMetadata = IAssetAmountMetadata,
|
|
19
|
+
> {
|
|
20
|
+
render: TRenderWalletHandlesFunction<T>;
|
|
19
21
|
loader?: ReactNode;
|
|
20
22
|
fallback?: ReactElement;
|
|
21
23
|
}
|
|
@@ -25,17 +27,19 @@ export interface IRenderWalletHandlesProps {
|
|
|
25
27
|
* fetching and updating wallet Handles with their extra
|
|
26
28
|
* metadata.
|
|
27
29
|
*/
|
|
28
|
-
export const RenderWalletHandles
|
|
30
|
+
export const RenderWalletHandles = <
|
|
31
|
+
T extends IAssetAmountMetadata = IAssetAmountMetadata,
|
|
32
|
+
>({
|
|
29
33
|
render,
|
|
30
34
|
loader,
|
|
31
35
|
fallback,
|
|
32
|
-
}) => {
|
|
33
|
-
const state = useWalletObserver();
|
|
34
|
-
const handleData = useWalletHandles();
|
|
36
|
+
}: IRenderWalletHandlesProps<T>) => {
|
|
37
|
+
const state = useWalletObserver<T>();
|
|
38
|
+
const handleData = useWalletHandles<T>();
|
|
35
39
|
|
|
36
40
|
return (
|
|
37
41
|
<ErrorBoundary
|
|
38
|
-
fallback={fallback ||
|
|
42
|
+
fallback={fallback || null}
|
|
39
43
|
onError={(error) => {
|
|
40
44
|
if (state.observer.getOptions().debug) {
|
|
41
45
|
console.log(error.message, error.stack);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IAssetAmountMetadata } from "@sundaeswap/asset";
|
|
2
|
-
import {
|
|
2
|
+
import { ReactElement, ReactNode, Suspense } from "react";
|
|
3
3
|
import { ErrorBoundary } from "react-error-boundary";
|
|
4
4
|
|
|
5
5
|
import { useWalletObserver } from "./hooks/useWalletObserver.js";
|
|
@@ -10,12 +10,14 @@ export type TRenderWalletPeerConnectFunctionState<
|
|
|
10
10
|
> = ReturnType<typeof useWalletObserver<T>> &
|
|
11
11
|
ReturnType<typeof useWalletPeerConnect<T>>;
|
|
12
12
|
|
|
13
|
-
export type TRenderWalletPeerConnectFunction
|
|
14
|
-
|
|
15
|
-
) => ReactNode;
|
|
13
|
+
export type TRenderWalletPeerConnectFunction<
|
|
14
|
+
T extends IAssetAmountMetadata = IAssetAmountMetadata,
|
|
15
|
+
> = (state: TRenderWalletPeerConnectFunctionState<T>) => ReactNode;
|
|
16
16
|
|
|
17
|
-
export interface IRenderWalletPeerConnectProps
|
|
18
|
-
|
|
17
|
+
export interface IRenderWalletPeerConnectProps<
|
|
18
|
+
T extends IAssetAmountMetadata = IAssetAmountMetadata,
|
|
19
|
+
> {
|
|
20
|
+
render: TRenderWalletPeerConnectFunction<T>;
|
|
19
21
|
loader?: ReactNode;
|
|
20
22
|
fallback?: ReactElement;
|
|
21
23
|
}
|
|
@@ -25,13 +27,15 @@ export interface IRenderWalletPeerConnectProps {
|
|
|
25
27
|
* and exposing them to the render function, including a QR Code
|
|
26
28
|
* element that can be placed in the consuming app.
|
|
27
29
|
*/
|
|
28
|
-
export const RenderWalletPeerConnect
|
|
30
|
+
export const RenderWalletPeerConnect = <
|
|
31
|
+
T extends IAssetAmountMetadata = IAssetAmountMetadata,
|
|
32
|
+
>({
|
|
29
33
|
render,
|
|
30
34
|
loader,
|
|
31
35
|
fallback,
|
|
32
|
-
}) => {
|
|
33
|
-
const state = useWalletObserver();
|
|
34
|
-
const peerConnectState = useWalletPeerConnect();
|
|
36
|
+
}: IRenderWalletPeerConnectProps<T>) => {
|
|
37
|
+
const state = useWalletObserver<T>();
|
|
38
|
+
const peerConnectState = useWalletPeerConnect<T>();
|
|
35
39
|
|
|
36
40
|
if (!peerConnectState.peerConnect) {
|
|
37
41
|
return null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IAssetAmountMetadata } from "@sundaeswap/asset";
|
|
2
|
-
import {
|
|
2
|
+
import { ReactElement, ReactNode, Suspense } from "react";
|
|
3
3
|
|
|
4
4
|
import { ErrorBoundary } from "react-error-boundary";
|
|
5
5
|
import { useWalletLoadingState } from "./hooks/useWalletLoadingState.js";
|
|
@@ -10,12 +10,14 @@ export type TRenderWalletStateFunctionState<
|
|
|
10
10
|
> = ReturnType<typeof useWalletObserver<T>> &
|
|
11
11
|
ReturnType<typeof useWalletLoadingState<T>>;
|
|
12
12
|
|
|
13
|
-
export type TRenderWalletStateFunction
|
|
14
|
-
|
|
15
|
-
) => JSX.Element | ReactNode;
|
|
13
|
+
export type TRenderWalletStateFunction<
|
|
14
|
+
T extends IAssetAmountMetadata = IAssetAmountMetadata,
|
|
15
|
+
> = (state: TRenderWalletStateFunctionState<T>) => JSX.Element | ReactNode;
|
|
16
16
|
|
|
17
|
-
export interface IRenderWalletStateProps
|
|
18
|
-
|
|
17
|
+
export interface IRenderWalletStateProps<
|
|
18
|
+
T extends IAssetAmountMetadata = IAssetAmountMetadata,
|
|
19
|
+
> {
|
|
20
|
+
render: TRenderWalletStateFunction<T>;
|
|
19
21
|
loader?: ReactNode;
|
|
20
22
|
fallback?: ReactElement;
|
|
21
23
|
}
|
|
@@ -26,17 +28,19 @@ export interface IRenderWalletStateProps {
|
|
|
26
28
|
* a sync or connection operation. Useful for displaying
|
|
27
29
|
* internal operation states of the wallet.
|
|
28
30
|
*/
|
|
29
|
-
export const RenderWalletState
|
|
31
|
+
export const RenderWalletState = <
|
|
32
|
+
T extends IAssetAmountMetadata = IAssetAmountMetadata,
|
|
33
|
+
>({
|
|
30
34
|
render,
|
|
31
35
|
loader,
|
|
32
|
-
fallback
|
|
33
|
-
}) => {
|
|
34
|
-
const state = useWalletObserver();
|
|
35
|
-
const loadingState = useWalletLoadingState();
|
|
36
|
+
fallback,
|
|
37
|
+
}: IRenderWalletStateProps<T>) => {
|
|
38
|
+
const state = useWalletObserver<T>();
|
|
39
|
+
const loadingState = useWalletLoadingState<T>();
|
|
36
40
|
|
|
37
41
|
return (
|
|
38
42
|
<ErrorBoundary
|
|
39
|
-
fallback={fallback}
|
|
43
|
+
fallback={fallback || null}
|
|
40
44
|
onError={(error) => {
|
|
41
45
|
if (state.observer.getOptions().debug) {
|
|
42
46
|
console.log(error.message, error.stack);
|
|
@@ -2,15 +2,10 @@ import type { TransactionUnspentOutput } from "@cardano-sdk/core/dist/cjs/Serial
|
|
|
2
2
|
import { AssetAmount, IAssetAmountMetadata } from "@sundaeswap/asset";
|
|
3
3
|
import { useCallback, useEffect, useState, useTransition } from "react";
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
TAssetAmountMap,
|
|
7
|
-
TSupportedWalletExtensions,
|
|
8
|
-
} from "../../../@types/observer.js";
|
|
9
|
-
import { WalletAssetMap } from "../../../classes/WalletAssetMap.class.js";
|
|
5
|
+
import { TSupportedWalletExtensions } from "../../../@types/observer.js";
|
|
10
6
|
import { WalletBalanceMap } from "../../../classes/WalletBalanceMap.class.js";
|
|
11
7
|
import { WalletObserver } from "../../../classes/WalletObserver.class.js";
|
|
12
8
|
import { areAssetMapsEqual } from "../../../utils/comparisons.js";
|
|
13
|
-
import { THandleMetadata } from "../../contexts/observer/index.js";
|
|
14
9
|
|
|
15
10
|
/**
|
|
16
11
|
* Internal use only. The main action that sync WalletObserver api responses with
|
|
@@ -28,9 +23,6 @@ export const useWalletObserverState = <
|
|
|
28
23
|
const [adaBalance, setAdaBalance] = useState<AssetAmount<AssetMetadata>>(
|
|
29
24
|
new AssetAmount<AssetMetadata>(0n),
|
|
30
25
|
);
|
|
31
|
-
const [handleMetadata, setHandleMetadata] = useState<
|
|
32
|
-
TAssetAmountMap<THandleMetadata<AssetMetadata>>
|
|
33
|
-
>(new WalletAssetMap<THandleMetadata<AssetMetadata>>());
|
|
34
26
|
const [balance, setBalance] = useState<WalletBalanceMap<AssetMetadata>>(
|
|
35
27
|
new WalletBalanceMap<AssetMetadata>(observer),
|
|
36
28
|
);
|
|
@@ -56,7 +48,6 @@ export const useWalletObserverState = <
|
|
|
56
48
|
// Reset state.
|
|
57
49
|
setAdaBalance(new AssetAmount(0n));
|
|
58
50
|
setBalance(new WalletBalanceMap(observer));
|
|
59
|
-
setHandleMetadata(new WalletAssetMap());
|
|
60
51
|
setUsedAddresses([]);
|
|
61
52
|
setUnusedAddresses([]);
|
|
62
53
|
setActiveWallet(undefined);
|
|
@@ -174,8 +165,6 @@ export const useWalletObserverState = <
|
|
|
174
165
|
setAdaBalance,
|
|
175
166
|
balance,
|
|
176
167
|
setBalance,
|
|
177
|
-
handles: handleMetadata,
|
|
178
|
-
setHandles: setHandleMetadata,
|
|
179
168
|
isCip45,
|
|
180
169
|
setIsCip45,
|
|
181
170
|
network,
|
|
@@ -3,6 +3,7 @@ import { render } from "@testing-library/react";
|
|
|
3
3
|
import { userEvent } from "@testing-library/user-event";
|
|
4
4
|
import { describe, expect, it, spyOn } from "bun:test";
|
|
5
5
|
|
|
6
|
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
6
7
|
import { mockHandleMetadata } from "../../__data__/handles.js";
|
|
7
8
|
import {
|
|
8
9
|
RenderWalletHandles,
|
|
@@ -53,7 +54,11 @@ describe("RenderWalletHandles", () => {
|
|
|
53
54
|
<RenderWalletHandles render={TestComponent} />,
|
|
54
55
|
{
|
|
55
56
|
wrapper(props) {
|
|
56
|
-
return
|
|
57
|
+
return (
|
|
58
|
+
<QueryClientProvider client={new QueryClient()}>
|
|
59
|
+
<WalletObserverProvider {...props} />
|
|
60
|
+
</QueryClientProvider>
|
|
61
|
+
);
|
|
57
62
|
},
|
|
58
63
|
},
|
|
59
64
|
);
|
|
@@ -65,10 +70,9 @@ describe("RenderWalletHandles", () => {
|
|
|
65
70
|
|
|
66
71
|
const button = getByTestId("connect-with-handles");
|
|
67
72
|
await user.click(button);
|
|
68
|
-
|
|
69
73
|
expect(spiedOnGetAllDataBatch).toHaveBeenCalled();
|
|
70
|
-
rerender(<RenderWalletHandles render={TestComponent} />);
|
|
71
74
|
|
|
75
|
+
rerender(<RenderWalletHandles render={TestComponent} />);
|
|
72
76
|
expect(queryByTestId("calvin")).not.toBeNull();
|
|
73
77
|
expect(queryByTestId("pi")).not.toBeNull();
|
|
74
78
|
expect(container.innerHTML).toMatchSnapshot();
|
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
startTransition,
|
|
3
|
-
useCallback,
|
|
4
|
-
useDeferredValue,
|
|
5
|
-
useEffect,
|
|
6
|
-
useMemo,
|
|
7
|
-
useState,
|
|
8
|
-
} from "react";
|
|
9
|
-
|
|
10
1
|
import { IHandle } from "@koralabs/adahandle-sdk";
|
|
11
2
|
import { IAssetAmountMetadata } from "@sundaeswap/asset";
|
|
3
|
+
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
4
|
+
import { useMemo } from "react";
|
|
5
|
+
|
|
12
6
|
import { TAssetAmountMap } from "../../@types/observer.js";
|
|
13
7
|
import { WalletAssetMap } from "../../classes/WalletAssetMap.class.js";
|
|
14
8
|
import { normalizeAssetIdWithDot } from "../../utils/assets.js";
|
|
@@ -18,117 +12,107 @@ import { useWalletObserver } from "./useWalletObserver.js";
|
|
|
18
12
|
export const useWalletHandles = <
|
|
19
13
|
AssetMetadata extends IAssetAmountMetadata = IAssetAmountMetadata,
|
|
20
14
|
>() => {
|
|
15
|
+
const queryClient = useQueryClient();
|
|
21
16
|
const state = useWalletObserver<THandleMetadata<AssetMetadata>>();
|
|
22
|
-
const [handles, setHandles] = useState<
|
|
23
|
-
TAssetAmountMap<THandleMetadata<AssetMetadata>>
|
|
24
|
-
>(state.handles);
|
|
25
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
26
|
-
const deferredHandles = useDeferredValue(handles);
|
|
27
|
-
|
|
28
17
|
const memoizedHandleDep = useMemo(
|
|
29
18
|
() => [...state.balance.getHandles().keys()],
|
|
30
19
|
[state.balance],
|
|
31
20
|
);
|
|
32
21
|
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
22
|
+
const queryKey = [memoizedHandleDep, state.mainAddress];
|
|
23
|
+
const { data: handles, isLoading } = useQuery({
|
|
24
|
+
queryKey,
|
|
25
|
+
queryFn: async () => {
|
|
26
|
+
const currentWalletHandles: TAssetAmountMap<
|
|
27
|
+
THandleMetadata<AssetMetadata>
|
|
28
|
+
> = new WalletAssetMap<THandleMetadata<AssetMetadata>>([
|
|
38
29
|
...state.balance.getHandles(),
|
|
39
30
|
]);
|
|
40
31
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const context =
|
|
54
|
-
state.network === 1
|
|
55
|
-
? HandleClientContext.MAINNET
|
|
56
|
-
: HandleClientContext.PREVIEW;
|
|
57
|
-
|
|
58
|
-
const sdk = new HandleClient({
|
|
59
|
-
context,
|
|
60
|
-
provider: new KoraLabsProvider(context),
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
const walletHandlesWithDataArray = [...walletHandles.entries()];
|
|
64
|
-
const walletHandleDataArray: IHandle[] = await sdk
|
|
65
|
-
.provider()
|
|
66
|
-
.getAllDataBatch(
|
|
67
|
-
walletHandlesWithDataArray.map(([key]) => ({
|
|
68
|
-
value: key.split(".")[1],
|
|
69
|
-
})),
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
walletHandlesWithDataArray.forEach(([key, asset]) => {
|
|
73
|
-
const matchingData = walletHandleDataArray.find(
|
|
74
|
-
({ hex }) => hex === key.split(".")[1],
|
|
75
|
-
) as IHandle;
|
|
76
|
-
|
|
77
|
-
walletHandles.set(
|
|
78
|
-
normalizeAssetIdWithDot(key),
|
|
79
|
-
asset
|
|
80
|
-
.withMetadata({
|
|
81
|
-
...matchingData,
|
|
82
|
-
...asset.metadata,
|
|
83
|
-
assetId: normalizeAssetIdWithDot(asset.metadata.assetId),
|
|
84
|
-
decimals: 0,
|
|
85
|
-
})
|
|
86
|
-
.withAmount(1n),
|
|
87
|
-
);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
return walletHandles;
|
|
91
|
-
} catch (e) {
|
|
92
|
-
console.error(e);
|
|
93
|
-
return walletHandles;
|
|
94
|
-
}
|
|
95
|
-
}, [state.balance, state.network]);
|
|
96
|
-
|
|
97
|
-
useEffect(() => {
|
|
98
|
-
const fetchHandles = async () => {
|
|
99
|
-
const newHandles = await syncHandles();
|
|
100
|
-
startTransition(() => {
|
|
101
|
-
setHandles((prevHandles) => {
|
|
102
|
-
let handleMetadataChanged = false;
|
|
103
|
-
|
|
104
|
-
if (newHandles.size !== prevHandles?.size) {
|
|
105
|
-
handleMetadataChanged = true;
|
|
106
|
-
} else {
|
|
107
|
-
for (const [key, val] of newHandles) {
|
|
108
|
-
if (
|
|
109
|
-
!prevHandles.has(key) ||
|
|
110
|
-
prevHandles.get(key)?.amount !== val?.amount
|
|
111
|
-
) {
|
|
112
|
-
handleMetadataChanged = true;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (!handleMetadataChanged) {
|
|
118
|
-
return prevHandles;
|
|
32
|
+
const cachedMetadata =
|
|
33
|
+
queryClient.getQueryData<
|
|
34
|
+
TAssetAmountMap<THandleMetadata<AssetMetadata>>
|
|
35
|
+
>(queryKey);
|
|
36
|
+
|
|
37
|
+
let updateMetadata = false;
|
|
38
|
+
if (cachedMetadata) {
|
|
39
|
+
for (const [, val] of cachedMetadata) {
|
|
40
|
+
if (!val?.metadata?.rarity) {
|
|
41
|
+
updateMetadata = true;
|
|
42
|
+
break;
|
|
119
43
|
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (!updateMetadata && cachedMetadata) {
|
|
48
|
+
return cachedMetadata;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
const {
|
|
53
|
+
default: HandleClient,
|
|
54
|
+
HandleClientContext,
|
|
55
|
+
KoraLabsProvider,
|
|
56
|
+
} = await import("@koralabs/adahandle-sdk");
|
|
57
|
+
|
|
58
|
+
const context =
|
|
59
|
+
state.network === 1
|
|
60
|
+
? HandleClientContext.MAINNET
|
|
61
|
+
: HandleClientContext.PREVIEW;
|
|
62
|
+
|
|
63
|
+
const sdk = new HandleClient({
|
|
64
|
+
context,
|
|
65
|
+
provider: new KoraLabsProvider(context),
|
|
66
|
+
});
|
|
120
67
|
|
|
121
|
-
|
|
68
|
+
const walletHandlesWithDataArray = [...currentWalletHandles.entries()];
|
|
69
|
+
const walletHandleDataArray: IHandle[] = await sdk
|
|
70
|
+
.provider()
|
|
71
|
+
.getAllDataBatch(
|
|
72
|
+
walletHandlesWithDataArray.map(([key]) => ({
|
|
73
|
+
value: key.split(".")[1],
|
|
74
|
+
})),
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
walletHandlesWithDataArray.forEach(([key, asset]) => {
|
|
78
|
+
const matchingData = walletHandleDataArray.find(
|
|
79
|
+
({ hex }) => hex === key.split(".")[1],
|
|
80
|
+
) as IHandle;
|
|
81
|
+
|
|
82
|
+
currentWalletHandles.set(
|
|
83
|
+
normalizeAssetIdWithDot(key),
|
|
84
|
+
asset
|
|
85
|
+
.withMetadata({
|
|
86
|
+
...matchingData,
|
|
87
|
+
...asset.metadata,
|
|
88
|
+
assetId: normalizeAssetIdWithDot(asset.metadata.assetId),
|
|
89
|
+
decimals: 0,
|
|
90
|
+
})
|
|
91
|
+
.withAmount(1n),
|
|
92
|
+
);
|
|
122
93
|
});
|
|
123
|
-
setIsLoading(() => false);
|
|
124
|
-
});
|
|
125
|
-
};
|
|
126
94
|
|
|
127
|
-
|
|
128
|
-
|
|
95
|
+
return currentWalletHandles;
|
|
96
|
+
} catch (e) {
|
|
97
|
+
console.error(e);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return currentWalletHandles;
|
|
101
|
+
},
|
|
102
|
+
refetchInterval: false,
|
|
103
|
+
notifyOnChangeProps: ["data", "isLoading"],
|
|
104
|
+
initialData: new WalletAssetMap<THandleMetadata<AssetMetadata>>([
|
|
105
|
+
...state.balance.getHandles(),
|
|
106
|
+
]),
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const memoizedResult = useMemo(
|
|
110
|
+
() => ({
|
|
111
|
+
handles,
|
|
112
|
+
loadingHandles: isLoading,
|
|
113
|
+
}),
|
|
114
|
+
[handles, isLoading],
|
|
115
|
+
);
|
|
129
116
|
|
|
130
|
-
return
|
|
131
|
-
handles: deferredHandles,
|
|
132
|
-
loadingHandles: isLoading,
|
|
133
|
-
};
|
|
117
|
+
return memoizedResult;
|
|
134
118
|
};
|
|
@@ -41,7 +41,6 @@ export const useWalletObserver = <
|
|
|
41
41
|
connectWallet: state.connectWallet,
|
|
42
42
|
switching: state.switching,
|
|
43
43
|
isPending: state.isPending,
|
|
44
|
-
handles: state.handles,
|
|
45
44
|
willAutoConnect: state.willAutoConnect,
|
|
46
45
|
}),
|
|
47
46
|
[
|
|
@@ -62,7 +61,6 @@ export const useWalletObserver = <
|
|
|
62
61
|
state.connectWallet,
|
|
63
62
|
state.switching,
|
|
64
63
|
state.isPending,
|
|
65
|
-
state.handles,
|
|
66
64
|
state.willAutoConnect,
|
|
67
65
|
],
|
|
68
66
|
);
|