@sundaeswap/wallet-lite 0.0.34 → 0.0.35
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/classes/WalletObserver.class.js +11 -12
- package/dist/cjs/classes/WalletObserver.class.js.map +1 -1
- package/dist/cjs/react-components/RenderWallet.js +18 -3
- package/dist/cjs/react-components/RenderWallet.js.map +1 -1
- package/dist/cjs/react-components/RenderWalletHandles.js +18 -3
- package/dist/cjs/react-components/RenderWalletHandles.js.map +1 -1
- package/dist/cjs/react-components/RenderWalletPeerConnect.js +14 -3
- package/dist/cjs/react-components/RenderWalletPeerConnect.js.map +1 -1
- package/dist/cjs/react-components/RenderWalletState.js +17 -3
- package/dist/cjs/react-components/RenderWalletState.js.map +1 -1
- package/dist/cjs/react-components/WalletObserverProvider/hooks/useWalletObserverState.js +52 -45
- package/dist/cjs/react-components/WalletObserverProvider/hooks/useWalletObserverState.js.map +1 -1
- package/dist/cjs/react-components/contexts/observer/types.js.map +1 -1
- package/dist/cjs/react-components/hooks/useWalletHandles.js +111 -107
- package/dist/cjs/react-components/hooks/useWalletHandles.js.map +1 -1
- package/dist/cjs/react-components/hooks/useWalletLoadingState.js +1 -1
- package/dist/cjs/react-components/hooks/useWalletLoadingState.js.map +1 -1
- package/dist/cjs/react-components/hooks/useWalletObserver.js +3 -1
- package/dist/cjs/react-components/hooks/useWalletObserver.js.map +1 -1
- package/dist/cjs/react-components/hooks/useWalletPeerConnect.js +13 -4
- package/dist/cjs/react-components/hooks/useWalletPeerConnect.js.map +1 -1
- package/dist/cjs/utils/getLibs.js +18 -35
- package/dist/cjs/utils/getLibs.js.map +1 -1
- package/dist/esm/classes/WalletObserver.class.js +7 -19
- package/dist/esm/classes/WalletObserver.class.js.map +1 -1
- package/dist/esm/react-components/RenderWallet.js +19 -4
- package/dist/esm/react-components/RenderWallet.js.map +1 -1
- package/dist/esm/react-components/RenderWalletHandles.js +21 -6
- package/dist/esm/react-components/RenderWalletHandles.js.map +1 -1
- package/dist/esm/react-components/RenderWalletPeerConnect.js +16 -5
- package/dist/esm/react-components/RenderWalletPeerConnect.js.map +1 -1
- package/dist/esm/react-components/RenderWalletState.js +19 -6
- package/dist/esm/react-components/RenderWalletState.js.map +1 -1
- package/dist/esm/react-components/WalletObserverProvider/hooks/useWalletObserverState.js +30 -26
- package/dist/esm/react-components/WalletObserverProvider/hooks/useWalletObserverState.js.map +1 -1
- package/dist/esm/react-components/contexts/observer/types.js.map +1 -1
- package/dist/esm/react-components/hooks/useWalletHandles.js +46 -51
- package/dist/esm/react-components/hooks/useWalletHandles.js.map +1 -1
- package/dist/esm/react-components/hooks/useWalletLoadingState.js +1 -1
- package/dist/esm/react-components/hooks/useWalletLoadingState.js.map +1 -1
- package/dist/esm/react-components/hooks/useWalletObserver.js +3 -1
- package/dist/esm/react-components/hooks/useWalletObserver.js.map +1 -1
- package/dist/esm/react-components/hooks/useWalletPeerConnect.js +13 -3
- package/dist/esm/react-components/hooks/useWalletPeerConnect.js.map +1 -1
- package/dist/esm/utils/getLibs.js +12 -20
- package/dist/esm/utils/getLibs.js.map +1 -1
- package/dist/types/classes/WalletObserver.class.d.ts +2 -2
- package/dist/types/classes/WalletObserver.class.d.ts.map +1 -1
- package/dist/types/react-components/RenderWallet.d.ts +3 -1
- package/dist/types/react-components/RenderWallet.d.ts.map +1 -1
- package/dist/types/react-components/RenderWalletHandles.d.ts +3 -1
- package/dist/types/react-components/RenderWalletHandles.d.ts.map +1 -1
- package/dist/types/react-components/RenderWalletPeerConnect.d.ts +3 -1
- package/dist/types/react-components/RenderWalletPeerConnect.d.ts.map +1 -1
- package/dist/types/react-components/RenderWalletState.d.ts +3 -1
- package/dist/types/react-components/RenderWalletState.d.ts.map +1 -1
- package/dist/types/react-components/WalletObserverProvider/hooks/useWalletObserverState.d.ts +9 -8
- package/dist/types/react-components/WalletObserverProvider/hooks/useWalletObserverState.d.ts.map +1 -1
- package/dist/types/react-components/contexts/observer/types.d.ts +9 -31
- package/dist/types/react-components/contexts/observer/types.d.ts.map +1 -1
- 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/react-components/hooks/useWalletPeerConnect.d.ts +1 -0
- package/dist/types/react-components/hooks/useWalletPeerConnect.d.ts.map +1 -1
- package/dist/types/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/utils/getLibs.d.ts +2 -6
- package/dist/types/utils/getLibs.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/classes/WalletObserver.class.ts +8 -8
- package/src/react-components/RenderWallet.tsx +21 -3
- package/src/react-components/RenderWalletHandles.tsx +20 -2
- package/src/react-components/RenderWalletPeerConnect.tsx +16 -3
- package/src/react-components/RenderWalletState.tsx +24 -8
- package/src/react-components/WalletObserverProvider/hooks/useWalletObserverState.ts +66 -56
- package/src/react-components/contexts/observer/types.ts +13 -38
- package/src/react-components/hooks/useWalletHandles.ts +82 -76
- package/src/react-components/hooks/useWalletLoadingState.ts +1 -1
- package/src/react-components/hooks/useWalletObserver.ts +2 -0
- package/src/react-components/hooks/useWalletPeerConnect.tsx +18 -5
- package/src/utils/getLibs.ts +12 -11
|
@@ -2,10 +2,6 @@ export declare const getCardanoCore: () => Promise<{
|
|
|
2
2
|
Serialization: typeof import("@cardano-sdk/core/dist/cjs/Serialization");
|
|
3
3
|
Cardano: typeof import("@cardano-sdk/core/dist/cjs/Cardano");
|
|
4
4
|
}>;
|
|
5
|
-
export declare const getCardanoUtil: () => Promise<
|
|
6
|
-
|
|
7
|
-
}>;
|
|
8
|
-
export declare const getPeerConnect: () => Promise<{
|
|
9
|
-
DAppPeerConnect: typeof import("@fabianbormann/cardano-peer-connect").DAppPeerConnect;
|
|
10
|
-
}>;
|
|
5
|
+
export declare const getCardanoUtil: () => Promise<(<T>(value: string, length?: number | undefined) => T)>;
|
|
6
|
+
export declare const getPeerConnect: () => Promise<typeof import("@fabianbormann/cardano-peer-connect").DAppPeerConnect>;
|
|
11
7
|
//# sourceMappingURL=getLibs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLibs.d.ts","sourceRoot":"","sources":["../../../src/utils/getLibs.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc;;;
|
|
1
|
+
{"version":3,"file":"getLibs.d.ts","sourceRoot":"","sources":["../../../src/utils/getLibs.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc;;;EAO1B,CAAC;AAEF,eAAO,MAAM,cAAc,uEAI1B,CAAC;AAEF,eAAO,MAAM,cAAc,qFAI1B,CAAC"}
|
package/package.json
CHANGED
|
@@ -123,9 +123,9 @@ export class WalletObserver<
|
|
|
123
123
|
* In the event that a promise will not resolve due to external issues,
|
|
124
124
|
* after 7 seconds, a timeout function will fire that resets the API and tries again.
|
|
125
125
|
*
|
|
126
|
-
* @returns {Promise<IWalletObserverSync
|
|
126
|
+
* @returns {Promise<IWalletObserverSync<AssetMetadata>>} - A promise that resolves to the wallet sync data.
|
|
127
127
|
*/
|
|
128
|
-
sync = async (): Promise<IWalletObserverSync
|
|
128
|
+
sync = async (): Promise<IWalletObserverSync<AssetMetadata>> => {
|
|
129
129
|
if (!this.api) {
|
|
130
130
|
throw new Error(
|
|
131
131
|
"Attempted to perform a sync operation without a connected wallet."
|
|
@@ -338,7 +338,7 @@ export class WalletObserver<
|
|
|
338
338
|
getCip45Instance = async () => {
|
|
339
339
|
const start = performance.now();
|
|
340
340
|
if (!this.peerConnectInstance) {
|
|
341
|
-
const
|
|
341
|
+
const DAppPeerConnect = await getPeerConnect();
|
|
342
342
|
this.peerConnectInstance = new DAppPeerConnect(
|
|
343
343
|
this._options.peerConnectArgs
|
|
344
344
|
);
|
|
@@ -398,7 +398,7 @@ export class WalletObserver<
|
|
|
398
398
|
const start = performance.now();
|
|
399
399
|
|
|
400
400
|
this.dispatch(EWalletObserverEvents.GET_BALANCE_MAP_START);
|
|
401
|
-
const [cbor, { Serialization },
|
|
401
|
+
const [cbor, { Serialization }, typedHex] = await Promise.all([
|
|
402
402
|
this.api.getBalance(),
|
|
403
403
|
getCardanoCore(),
|
|
404
404
|
getCardanoUtil(),
|
|
@@ -475,7 +475,7 @@ export class WalletObserver<
|
|
|
475
475
|
|
|
476
476
|
const start = performance.now();
|
|
477
477
|
|
|
478
|
-
const [cbor, { Cardano },
|
|
478
|
+
const [cbor, { Cardano }, typedHex] = await Promise.all([
|
|
479
479
|
this.api.getUsedAddresses(),
|
|
480
480
|
getCardanoCore(),
|
|
481
481
|
getCardanoUtil(),
|
|
@@ -506,7 +506,7 @@ export class WalletObserver<
|
|
|
506
506
|
|
|
507
507
|
const start = performance.now();
|
|
508
508
|
|
|
509
|
-
const [cbor, { Cardano },
|
|
509
|
+
const [cbor, { Cardano }, typedHex] = await Promise.all([
|
|
510
510
|
this.api.getUnusedAddresses(),
|
|
511
511
|
getCardanoCore(),
|
|
512
512
|
getCardanoUtil(),
|
|
@@ -535,7 +535,7 @@ export class WalletObserver<
|
|
|
535
535
|
|
|
536
536
|
const start = performance.now();
|
|
537
537
|
|
|
538
|
-
const [cbor, { Serialization },
|
|
538
|
+
const [cbor, { Serialization }, typedHex] = await Promise.all([
|
|
539
539
|
this.api.getUtxos(),
|
|
540
540
|
getCardanoCore(),
|
|
541
541
|
getCardanoUtil(),
|
|
@@ -571,7 +571,7 @@ export class WalletObserver<
|
|
|
571
571
|
|
|
572
572
|
const start = performance.now();
|
|
573
573
|
|
|
574
|
-
const [cbor, { Serialization },
|
|
574
|
+
const [cbor, { Serialization }, typedHex] = await Promise.all([
|
|
575
575
|
(async () => {
|
|
576
576
|
const funcCall =
|
|
577
577
|
this.api?.getCollateral ||
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IAssetAmountMetadata } from "@sundaeswap/asset";
|
|
2
|
-
import { FC, ReactNode } from "react";
|
|
2
|
+
import { FC, ReactElement, ReactNode, Suspense } from "react";
|
|
3
3
|
|
|
4
|
+
import { ErrorBoundary } from "react-error-boundary";
|
|
4
5
|
import { useWalletObserver } from "./hooks/useWalletObserver.js";
|
|
5
6
|
|
|
6
7
|
export type TRenderWalletFunctionState<
|
|
@@ -13,6 +14,8 @@ export type TRenderWalletFunction = (
|
|
|
13
14
|
|
|
14
15
|
export interface IRenderWalletProps {
|
|
15
16
|
render: TRenderWalletFunction;
|
|
17
|
+
loader?: ReactNode;
|
|
18
|
+
fallback?: ReactElement;
|
|
16
19
|
}
|
|
17
20
|
|
|
18
21
|
/**
|
|
@@ -21,8 +24,23 @@ export interface IRenderWalletProps {
|
|
|
21
24
|
* compose on this and include state for Handles, PeerConnect (CIP-45),
|
|
22
25
|
* and syncing state (RenderWalletState).
|
|
23
26
|
*/
|
|
24
|
-
export const RenderWallet: FC<IRenderWalletProps> = ({
|
|
27
|
+
export const RenderWallet: FC<IRenderWalletProps> = ({
|
|
28
|
+
render,
|
|
29
|
+
loader,
|
|
30
|
+
fallback,
|
|
31
|
+
}) => {
|
|
25
32
|
const state = useWalletObserver();
|
|
26
33
|
|
|
27
|
-
return
|
|
34
|
+
return (
|
|
35
|
+
<ErrorBoundary
|
|
36
|
+
fallback={fallback || <p>Error.</p>}
|
|
37
|
+
onError={(error) => {
|
|
38
|
+
if (state.observer.getOptions().debug) {
|
|
39
|
+
console.log(error.message, error.stack);
|
|
40
|
+
}
|
|
41
|
+
}}
|
|
42
|
+
>
|
|
43
|
+
<Suspense fallback={loader}>{render(state)}</Suspense>
|
|
44
|
+
</ErrorBoundary>
|
|
45
|
+
);
|
|
28
46
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IAssetAmountMetadata } from "@sundaeswap/asset";
|
|
2
|
-
import { FC, ReactNode } from "react";
|
|
2
|
+
import { FC, ReactElement, ReactNode, Suspense } from "react";
|
|
3
3
|
|
|
4
|
+
import { ErrorBoundary } from "react-error-boundary";
|
|
4
5
|
import { useWalletHandles } from "./hooks/useWalletHandles.js";
|
|
5
6
|
import { useWalletObserver } from "./hooks/useWalletObserver.js";
|
|
6
7
|
|
|
@@ -15,6 +16,8 @@ export type TRenderWalletHandlesFunction = (
|
|
|
15
16
|
|
|
16
17
|
export interface IRenderWalletHandlesProps {
|
|
17
18
|
render: TRenderWalletHandlesFunction;
|
|
19
|
+
loader?: ReactNode;
|
|
20
|
+
fallback?: ReactElement;
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
/**
|
|
@@ -24,9 +27,24 @@ export interface IRenderWalletHandlesProps {
|
|
|
24
27
|
*/
|
|
25
28
|
export const RenderWalletHandles: FC<IRenderWalletHandlesProps> = ({
|
|
26
29
|
render,
|
|
30
|
+
loader,
|
|
31
|
+
fallback,
|
|
27
32
|
}) => {
|
|
28
33
|
const state = useWalletObserver();
|
|
29
34
|
const handleData = useWalletHandles();
|
|
30
35
|
|
|
31
|
-
return
|
|
36
|
+
return (
|
|
37
|
+
<ErrorBoundary
|
|
38
|
+
fallback={fallback || <p>Error.</p>}
|
|
39
|
+
onError={(error) => {
|
|
40
|
+
if (state.observer.getOptions().debug) {
|
|
41
|
+
console.log(error.message, error.stack);
|
|
42
|
+
}
|
|
43
|
+
}}
|
|
44
|
+
>
|
|
45
|
+
<Suspense fallback={loader}>
|
|
46
|
+
{render({ ...state, ...handleData })}
|
|
47
|
+
</Suspense>
|
|
48
|
+
</ErrorBoundary>
|
|
49
|
+
);
|
|
32
50
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IAssetAmountMetadata } from "@sundaeswap/asset";
|
|
2
|
-
import { FC, ReactNode } from "react";
|
|
2
|
+
import { FC, ReactElement, ReactNode, Suspense } from "react";
|
|
3
3
|
import { ErrorBoundary } from "react-error-boundary";
|
|
4
4
|
|
|
5
5
|
import { useWalletObserver } from "./hooks/useWalletObserver.js";
|
|
@@ -16,6 +16,8 @@ export type TRenderWalletPeerConnectFunction = (
|
|
|
16
16
|
|
|
17
17
|
export interface IRenderWalletPeerConnectProps {
|
|
18
18
|
render: TRenderWalletPeerConnectFunction;
|
|
19
|
+
loader?: ReactNode;
|
|
20
|
+
fallback?: ReactElement;
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
/**
|
|
@@ -25,6 +27,8 @@ export interface IRenderWalletPeerConnectProps {
|
|
|
25
27
|
*/
|
|
26
28
|
export const RenderWalletPeerConnect: FC<IRenderWalletPeerConnectProps> = ({
|
|
27
29
|
render,
|
|
30
|
+
loader,
|
|
31
|
+
fallback,
|
|
28
32
|
}) => {
|
|
29
33
|
const state = useWalletObserver();
|
|
30
34
|
const peerConnectState = useWalletPeerConnect();
|
|
@@ -34,8 +38,17 @@ export const RenderWalletPeerConnect: FC<IRenderWalletPeerConnectProps> = ({
|
|
|
34
38
|
}
|
|
35
39
|
|
|
36
40
|
return (
|
|
37
|
-
<ErrorBoundary
|
|
38
|
-
{
|
|
41
|
+
<ErrorBoundary
|
|
42
|
+
fallback={fallback || <p>{peerConnectState.error}</p>}
|
|
43
|
+
onError={(error) => {
|
|
44
|
+
if (state.observer.getOptions().debug) {
|
|
45
|
+
console.log(error.message, error.stack);
|
|
46
|
+
}
|
|
47
|
+
}}
|
|
48
|
+
>
|
|
49
|
+
<Suspense fallback={loader}>
|
|
50
|
+
{render({ ...state, ...peerConnectState })}
|
|
51
|
+
</Suspense>
|
|
39
52
|
</ErrorBoundary>
|
|
40
53
|
);
|
|
41
54
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IAssetAmountMetadata } from "@sundaeswap/asset";
|
|
2
|
-
import { FC, ReactNode } from "react";
|
|
2
|
+
import { FC, ReactElement, ReactNode, Suspense } from "react";
|
|
3
3
|
|
|
4
|
+
import { ErrorBoundary } from "react-error-boundary";
|
|
4
5
|
import { useWalletLoadingState } from "./hooks/useWalletLoadingState.js";
|
|
5
6
|
import { useWalletObserver } from "./hooks/useWalletObserver.js";
|
|
6
7
|
|
|
@@ -15,6 +16,8 @@ export type TRenderWalletStateFunction = (
|
|
|
15
16
|
|
|
16
17
|
export interface IRenderWalletStateProps {
|
|
17
18
|
render: TRenderWalletStateFunction;
|
|
19
|
+
loader?: ReactNode;
|
|
20
|
+
fallback?: ReactElement;
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
/**
|
|
@@ -23,16 +26,29 @@ export interface IRenderWalletStateProps {
|
|
|
23
26
|
* a sync or connection operation. Useful for displaying
|
|
24
27
|
* internal operation states of the wallet.
|
|
25
28
|
*/
|
|
26
|
-
export const RenderWalletState: FC<IRenderWalletStateProps> = ({
|
|
29
|
+
export const RenderWalletState: FC<IRenderWalletStateProps> = ({
|
|
30
|
+
render,
|
|
31
|
+
loader,
|
|
32
|
+
fallback = null,
|
|
33
|
+
}) => {
|
|
27
34
|
const state = useWalletObserver();
|
|
28
35
|
const loadingState = useWalletLoadingState();
|
|
29
36
|
|
|
30
37
|
return (
|
|
31
|
-
|
|
32
|
-
{
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
<ErrorBoundary
|
|
39
|
+
fallback={fallback}
|
|
40
|
+
onError={(error) => {
|
|
41
|
+
if (state.observer.getOptions().debug) {
|
|
42
|
+
console.log(error.message, error.stack);
|
|
43
|
+
}
|
|
44
|
+
}}
|
|
45
|
+
>
|
|
46
|
+
<Suspense fallback={loader}>
|
|
47
|
+
{render({
|
|
48
|
+
...state,
|
|
49
|
+
...loadingState,
|
|
50
|
+
})}
|
|
51
|
+
</Suspense>
|
|
52
|
+
</ErrorBoundary>
|
|
37
53
|
);
|
|
38
54
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { TransactionUnspentOutput } from "@cardano-sdk/core/dist/cjs/Serialization/index.js";
|
|
2
|
-
import { AssetAmount } from "@sundaeswap/asset";
|
|
3
|
-
import { useCallback, useState } from "react";
|
|
2
|
+
import { AssetAmount, IAssetAmountMetadata } from "@sundaeswap/asset";
|
|
3
|
+
import { useCallback, useState, useTransition } from "react";
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
6
|
TAssetAmountMap,
|
|
@@ -18,17 +18,21 @@ import { THandleMetadata } from "../../contexts/observer/index.js";
|
|
|
18
18
|
*
|
|
19
19
|
* @param {WalletObserver} observer
|
|
20
20
|
*/
|
|
21
|
-
export const useWalletObserverState =
|
|
21
|
+
export const useWalletObserverState = <
|
|
22
|
+
AssetMetadata extends IAssetAmountMetadata = IAssetAmountMetadata
|
|
23
|
+
>(
|
|
24
|
+
observer: WalletObserver<AssetMetadata>
|
|
25
|
+
) => {
|
|
22
26
|
const [activeWallet, setActiveWallet] =
|
|
23
27
|
useState<TSupportedWalletExtensions>();
|
|
24
28
|
const [adaBalance, setAdaBalance] = useState<AssetAmount>(
|
|
25
|
-
new AssetAmount(0n)
|
|
29
|
+
new AssetAmount<AssetMetadata>(0n)
|
|
26
30
|
);
|
|
27
31
|
const [handleMetadata, setHandleMetadata] = useState<
|
|
28
|
-
TAssetAmountMap<THandleMetadata
|
|
29
|
-
>(new WalletAssetMap());
|
|
30
|
-
const [balance, setBalance] = useState<WalletBalanceMap
|
|
31
|
-
new WalletBalanceMap(observer)
|
|
32
|
+
TAssetAmountMap<THandleMetadata<AssetMetadata>>
|
|
33
|
+
>(new WalletAssetMap<THandleMetadata<AssetMetadata>>());
|
|
34
|
+
const [balance, setBalance] = useState<WalletBalanceMap<AssetMetadata>>(
|
|
35
|
+
new WalletBalanceMap<AssetMetadata>(observer)
|
|
32
36
|
);
|
|
33
37
|
const [network, setNetwork] = useState<number | undefined>();
|
|
34
38
|
const [usedAddresses, setUsedAddresses] = useState<string[]>([]);
|
|
@@ -37,6 +41,7 @@ export const useWalletObserverState = (observer: WalletObserver) => {
|
|
|
37
41
|
const [collateral, setCollateral] = useState<TransactionUnspentOutput[]>();
|
|
38
42
|
const [isCip45, setIsCip45] = useState(false);
|
|
39
43
|
const [switching, setSwitching] = useState(false);
|
|
44
|
+
const [isPending, startTransition] = useTransition();
|
|
40
45
|
|
|
41
46
|
const disconnect = useCallback(() => {
|
|
42
47
|
// Reset observer state.
|
|
@@ -68,62 +73,66 @@ export const useWalletObserverState = (observer: WalletObserver) => {
|
|
|
68
73
|
|
|
69
74
|
const freshData = await observer.sync();
|
|
70
75
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
76
|
+
startTransition(() => {
|
|
77
|
+
setActiveWallet((prevWallet) =>
|
|
78
|
+
newWallet === prevWallet ? prevWallet : newWallet
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const newAdaBalance = freshData.balanceMap.get(
|
|
82
|
+
WalletObserver.ADA_ASSET_ID
|
|
83
|
+
);
|
|
84
|
+
if (newAdaBalance) {
|
|
85
|
+
setAdaBalance((prevBalance) =>
|
|
86
|
+
prevBalance.amount === newAdaBalance.amount
|
|
87
|
+
? prevBalance
|
|
88
|
+
: newAdaBalance
|
|
89
|
+
);
|
|
90
|
+
}
|
|
74
91
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
setAdaBalance((prevBalance) =>
|
|
78
|
-
prevBalance.amount === newAdaBalance.amount
|
|
92
|
+
setBalance((prevBalance) =>
|
|
93
|
+
areAssetMapsEqual(prevBalance, freshData.balanceMap)
|
|
79
94
|
? prevBalance
|
|
80
|
-
:
|
|
95
|
+
: freshData.balanceMap
|
|
81
96
|
);
|
|
82
|
-
}
|
|
83
97
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
setUsedAddresses((prevValue) =>
|
|
91
|
-
JSON.stringify(prevValue) === JSON.stringify(freshData.usedAddresses)
|
|
92
|
-
? prevValue
|
|
93
|
-
: freshData.usedAddresses
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
setUnusedAddresses((prevValue) =>
|
|
97
|
-
JSON.stringify(prevValue) === JSON.stringify(freshData.unusedAddresses)
|
|
98
|
-
? prevValue
|
|
99
|
-
: freshData.unusedAddresses
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
setNetwork((prevValue) =>
|
|
103
|
-
prevValue === freshData.network ? prevValue : freshData.network
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
setUtxos((prevValue) => {
|
|
107
|
-
const prevValueRep = prevValue?.map((v) => v.toCbor());
|
|
108
|
-
const newValueRep = freshData.utxos?.map((v) => v.toCbor());
|
|
109
|
-
if (prevValueRep !== newValueRep) {
|
|
110
|
-
return freshData.utxos;
|
|
111
|
-
}
|
|
98
|
+
setUsedAddresses((prevValue) =>
|
|
99
|
+
JSON.stringify(prevValue) === JSON.stringify(freshData.usedAddresses)
|
|
100
|
+
? prevValue
|
|
101
|
+
: freshData.usedAddresses
|
|
102
|
+
);
|
|
112
103
|
|
|
113
|
-
|
|
114
|
-
|
|
104
|
+
setUnusedAddresses((prevValue) =>
|
|
105
|
+
JSON.stringify(prevValue) === JSON.stringify(freshData.unusedAddresses)
|
|
106
|
+
? prevValue
|
|
107
|
+
: freshData.unusedAddresses
|
|
108
|
+
);
|
|
115
109
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if (prevValueRep !== newValueRep) {
|
|
120
|
-
return freshData.utxos;
|
|
121
|
-
}
|
|
110
|
+
setNetwork((prevValue) =>
|
|
111
|
+
prevValue === freshData.network ? prevValue : freshData.network
|
|
112
|
+
);
|
|
122
113
|
|
|
123
|
-
|
|
124
|
-
|
|
114
|
+
setUtxos((prevValue) => {
|
|
115
|
+
const prevValueRep = prevValue?.map((v) => v.toCbor());
|
|
116
|
+
const newValueRep = freshData.utxos?.map((v) => v.toCbor());
|
|
117
|
+
if (prevValueRep !== newValueRep) {
|
|
118
|
+
return freshData.utxos;
|
|
119
|
+
}
|
|
125
120
|
|
|
126
|
-
|
|
121
|
+
return prevValue;
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
setCollateral((prevValue) => {
|
|
125
|
+
const prevValueRep = prevValue?.map((v) => v.toCbor());
|
|
126
|
+
const newValueRep = freshData.utxos?.map((v) => v.toCbor());
|
|
127
|
+
if (prevValueRep !== newValueRep) {
|
|
128
|
+
return freshData.utxos;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return prevValue;
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
setIsCip45(newWallet.includes("p2p"));
|
|
135
|
+
});
|
|
127
136
|
}, [observer, disconnect]);
|
|
128
137
|
|
|
129
138
|
const connectWallet = useCallback(
|
|
@@ -165,5 +174,6 @@ export const useWalletObserverState = (observer: WalletObserver) => {
|
|
|
165
174
|
connectWallet,
|
|
166
175
|
switching,
|
|
167
176
|
setSwitching,
|
|
177
|
+
isPending,
|
|
168
178
|
};
|
|
169
179
|
};
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import type { TransactionUnspentOutput } from "@cardano-sdk/core/dist/cjs/Serialization/index.js";
|
|
2
1
|
import type { IHandle } from "@koralabs/adahandle-sdk";
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
2
|
+
import type { IAssetAmountMetadata } from "@sundaeswap/asset";
|
|
3
|
+
import type { MutableRefObject } from "react";
|
|
5
4
|
|
|
6
|
-
import type {
|
|
7
|
-
TSupportedWalletExtensions,
|
|
8
|
-
TWalletObserverOptions,
|
|
9
|
-
} from "../../../@types/observer.js";
|
|
10
|
-
import { WalletBalanceMap } from "../../../classes/WalletBalanceMap.class.js";
|
|
5
|
+
import type { TWalletObserverOptions } from "../../../@types/observer.js";
|
|
11
6
|
import type { WalletObserver } from "../../../classes/WalletObserver.class.js";
|
|
7
|
+
import { useDerivedState } from "../../WalletObserverProvider/hooks/effects/useDerivedState.js";
|
|
8
|
+
import { useWalletObserverState } from "../../WalletObserverProvider/hooks/useWalletObserverState.js";
|
|
12
9
|
|
|
13
10
|
/**
|
|
14
11
|
* Available hooks to apply at various events.
|
|
@@ -48,36 +45,11 @@ export interface IWalletObserverState<
|
|
|
48
45
|
> {
|
|
49
46
|
observerRef: MutableRefObject<WalletObserver<AssetMetadata>>;
|
|
50
47
|
refreshInterval: number | false;
|
|
51
|
-
state:
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
SetStateAction<TSupportedWalletExtensions | undefined>
|
|
57
|
-
>;
|
|
58
|
-
adaBalance: AssetAmount<AssetMetadata>;
|
|
59
|
-
balance: WalletBalanceMap<AssetMetadata>;
|
|
60
|
-
utxos?: TransactionUnspentOutput[];
|
|
61
|
-
setUtxos: Dispatch<SetStateAction<TransactionUnspentOutput[] | undefined>>;
|
|
62
|
-
collateral?: TransactionUnspentOutput[];
|
|
63
|
-
setCollateral: Dispatch<
|
|
64
|
-
SetStateAction<TransactionUnspentOutput[] | undefined>
|
|
65
|
-
>;
|
|
66
|
-
setBalance: Dispatch<SetStateAction<WalletBalanceMap<AssetMetadata>>>;
|
|
67
|
-
observer: WalletObserver;
|
|
68
|
-
mainAddress?: string;
|
|
69
|
-
stakeAddress?: string;
|
|
70
|
-
network?: number;
|
|
71
|
-
setNetwork: Dispatch<SetStateAction<number | undefined>>;
|
|
72
|
-
unusedAddresses: string[];
|
|
73
|
-
setUnusedAddresses: Dispatch<SetStateAction<string[]>>;
|
|
74
|
-
usedAddresses: string[];
|
|
75
|
-
setUsedAddresses: Dispatch<SetStateAction<string[]>>;
|
|
76
|
-
switching: boolean;
|
|
77
|
-
syncWallet: () => Promise<void>;
|
|
78
|
-
disconnect: () => void;
|
|
79
|
-
connectWallet: (wallet: TSupportedWalletExtensions) => Promise<void>;
|
|
80
|
-
};
|
|
48
|
+
state: ReturnType<typeof useWalletObserverState<AssetMetadata>> &
|
|
49
|
+
ReturnType<typeof useDerivedState> & {
|
|
50
|
+
isPending: boolean;
|
|
51
|
+
observer: WalletObserver<AssetMetadata>;
|
|
52
|
+
};
|
|
81
53
|
}
|
|
82
54
|
|
|
83
55
|
/**
|
|
@@ -97,6 +69,9 @@ export type TUseWalletObserverState<
|
|
|
97
69
|
> = Omit<
|
|
98
70
|
IWalletObserverState<AssetMetadata>["state"],
|
|
99
71
|
| "setActiveWallet"
|
|
72
|
+
| "setAdaBalance"
|
|
73
|
+
| "setHandles"
|
|
74
|
+
| "setSwitching"
|
|
100
75
|
| "setBalance"
|
|
101
76
|
| "setNetwork"
|
|
102
77
|
| "setUnusedAddresses"
|