@ledgerhq/live-countervalues-react 0.3.0-next.0 → 0.3.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/.turbo/turbo-build.log +2 -2
- package/CHANGELOG.md +694 -3
- package/jest.config.js +5 -0
- package/lib/index.d.ts +29 -13
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +95 -127
- package/lib/index.js.map +1 -1
- package/lib/react.test.js +46 -55
- package/lib/react.test.js.map +1 -1
- package/lib-es/index.d.ts +29 -13
- package/lib-es/index.d.ts.map +1 -1
- package/lib-es/index.js +88 -120
- package/lib-es/index.js.map +1 -1
- package/lib-es/react.test.js +46 -55
- package/lib-es/react.test.js.map +1 -1
- package/package.json +11 -10
- package/src/index.tsx +137 -174
- package/tsconfig.json +0 -1
package/lib/react.test.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.test.js","sourceRoot":"","sources":["../src/react.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"react.test.js","sourceRoot":"","sources":["../src/react.test.ts"],"names":[],"mappings":";;AAAA,wBAA+C;AAC/C,oEAAoE;AACpE,kDAAyD;AACzD,yDAAiE;AACjE,8DAAkF;AAGlF,QAAQ,CAAC,4BAA4B,EAAE,GAAG,EAAE;IAC1C,MAAM,QAAQ,GAAG,KAAK,CAAC,EAAE,CAAC;SACvB,IAAI,CAAC,IAAI,CAAC;SACV,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,IAAA,oBAAU,EAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IACzC,MAAM,GAAG,GAAG,IAAA,sCAAuB,EAAC,KAAK,CAAC,CAAC;IAC3C,MAAM,GAAG,GAAG,IAAA,sCAAuB,EAAC,KAAK,CAAC,CAAC;IAC3C,MAAM,aAAa,GAAG,IAAA,oCAA4B,EAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAElE,IAA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nB,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC3B,CAAC,CAAC,CAAC;QACH,QAAQ,CAAC,IAAI,CAAC,CAAC;QACf,MAAM,IAAA,WAAG,EAAC,KAAK,IAAI,EAAE;YACnB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,wCAAwC,EAAE,KAAK,IAAI,EAAE;QACxD,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC1C,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAA,kBAAU,EAAC,CAAC,CAAC,EAAE,CAC1C,IAAA,6BAA0B,EAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,EAAE,GAAG,CAAC,CACxD,CAAC;QACF,IAAI,OAAmC,CAAC;QACxC,MAAM,IAAA,WAAG,EAAC,KAAK,IAAI,EAAE;YACnB,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC3B,CAAC,CAAC,CAAC;QACH,QAAQ,CAAC,IAAI,CAAC,CAAC;QACf,MAAM,IAAA,WAAG,EAAC,KAAK,IAAI,EAAE;YACnB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/lib-es/index.d.ts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
import { BigNumber } from "bignumber.js";
|
|
2
|
-
import React, { ReactElement } from "react";
|
|
3
1
|
import type { CounterValuesState, CounterValuesStateRaw, CountervaluesSettings, TrackingPair } from "@ledgerhq/live-countervalues/types";
|
|
4
|
-
import type { Account, AccountLike } from "@ledgerhq/types-live";
|
|
5
2
|
import type { Currency, Unit } from "@ledgerhq/types-cryptoassets";
|
|
3
|
+
import type { Account, AccountLike } from "@ledgerhq/types-live";
|
|
4
|
+
import { BigNumber } from "bignumber.js";
|
|
5
|
+
import React, { ReactElement } from "react";
|
|
6
|
+
/** Bridge enabling platform-specific persistence of market-cap ids. */
|
|
7
|
+
export interface CountervaluesMarketcapBridge {
|
|
8
|
+
useIds(): string[];
|
|
9
|
+
useLastUpdated(): number | undefined;
|
|
10
|
+
setLoading(loading: boolean): void;
|
|
11
|
+
setIds(ids: string[]): void;
|
|
12
|
+
setError(message: string): void;
|
|
13
|
+
}
|
|
6
14
|
export type Polling = {
|
|
7
15
|
wipe: () => void;
|
|
8
16
|
poll: () => void;
|
|
@@ -19,20 +27,21 @@ export type Props = {
|
|
|
19
27
|
debounceDelay?: number;
|
|
20
28
|
savedState?: CounterValuesStateRaw;
|
|
21
29
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
to: Currency;
|
|
25
|
-
startDate: Date;
|
|
26
|
-
}[];
|
|
27
|
-
export declare function useTrackingPairForAccounts(accounts: Account[], countervalue: Currency): TrackingPair[];
|
|
28
|
-
export declare function CountervaluesMarketcap({ children }: {
|
|
30
|
+
/** Provides market-cap ids via the supplied bridge. */
|
|
31
|
+
export declare function CountervaluesMarketcapProvider({ children, bridge, }: {
|
|
29
32
|
children: React.ReactNode;
|
|
33
|
+
bridge: CountervaluesMarketcapBridge;
|
|
30
34
|
}): ReactElement;
|
|
31
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Root countervalues provider (polling + calculation).
|
|
37
|
+
*/
|
|
38
|
+
export declare function CountervaluesProvider({ children, userSettings, pollInitDelay, debounceDelay, savedState, }: Props): ReactElement;
|
|
39
|
+
/** Returns market-cap ids. */
|
|
40
|
+
export declare function useMarketcapIds(): string[];
|
|
41
|
+
/** Returns the full countervalues state. */
|
|
42
|
+
export declare function useCountervaluesState(): CounterValuesState;
|
|
32
43
|
export declare function useCountervaluesPolling(): Polling;
|
|
33
44
|
export declare function useCountervaluesUserSettingsContext(): CountervaluesSettings;
|
|
34
|
-
export declare function useCountervaluesState(): CounterValuesState;
|
|
35
|
-
export declare function useMarketcapIds(): string[];
|
|
36
45
|
export declare function useCountervaluesExport(): CounterValuesStateRaw;
|
|
37
46
|
export declare function useCalculate(query: {
|
|
38
47
|
value: number;
|
|
@@ -45,6 +54,7 @@ export declare function useCalculate(query: {
|
|
|
45
54
|
export declare function useCalculateCountervalueCallback({ to, }: {
|
|
46
55
|
to: Currency;
|
|
47
56
|
}): (from: Currency, value: BigNumber) => BigNumber | null | undefined;
|
|
57
|
+
/** Helper for send-flow: returns fiat amount and reverse calculation. */
|
|
48
58
|
export declare function useSendAmount({ account, fiatCurrency, cryptoAmount, }: {
|
|
49
59
|
account: AccountLike;
|
|
50
60
|
fiatCurrency: Currency;
|
|
@@ -54,4 +64,10 @@ export declare function useSendAmount({ account, fiatCurrency, cryptoAmount, }:
|
|
|
54
64
|
fiatUnit: Unit;
|
|
55
65
|
calculateCryptoAmount: (fiatAmount: BigNumber) => BigNumber;
|
|
56
66
|
};
|
|
67
|
+
export declare function useTrackingPairsForTopCoins(marketcapIds: string[], countervalue: Currency, size: number, startDate: Date | undefined): {
|
|
68
|
+
from: import("@ledgerhq/types-cryptoassets").CryptoCurrency;
|
|
69
|
+
to: Currency;
|
|
70
|
+
startDate: Date;
|
|
71
|
+
}[];
|
|
72
|
+
export declare function useTrackingPairForAccounts(accounts: Account[], countervalue: Currency): TrackingPair[];
|
|
57
73
|
//# sourceMappingURL=index.d.ts.map
|
package/lib-es/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACrB,qBAAqB,EACrB,YAAY,EACb,MAAM,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E,SAAS,KAAK,SAAS,CAAC;CAC7D,CAwBA;AAID,wBAAgB,2BAA2B,CACzC,YAAY,EAAE,MAAM,EAAE,EACtB,YAAY,EAAE,QAAQ,EACtB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,IAAI,GAAG,SAAS;;;;IAU5B;AAED,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,OAAO,EAAE,EACnB,YAAY,EAAE,QAAQ,GACrB,YAAY,EAAE,CAUhB"}
|
package/lib-es/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { BigNumber } from "bignumber.js";
|
|
2
|
-
import React, { createContext, useMemo, useContext, useEffect, useReducer, useState, useCallback, } from "react";
|
|
3
1
|
import { getAccountCurrency } from "@ledgerhq/coin-framework/account/helpers";
|
|
4
|
-
import { initialState, calculate, loadCountervalues, exportCountervalues, importCountervalues, inferTrackingPairForAccounts, trackingPairForTopCoins, } from "@ledgerhq/live-countervalues/logic";
|
|
5
2
|
import api from "@ledgerhq/live-countervalues/api/index";
|
|
3
|
+
import { calculate, exportCountervalues, importCountervalues, inferTrackingPairForAccounts, initialState, loadCountervalues, trackingPairForTopCoins, } from "@ledgerhq/live-countervalues/logic";
|
|
6
4
|
import { useDebounce } from "@ledgerhq/live-hooks/useDebounce";
|
|
7
5
|
import { log } from "@ledgerhq/logs";
|
|
6
|
+
import { BigNumber } from "bignumber.js";
|
|
7
|
+
import React, { createContext, useCallback, useContext, useEffect, useMemo, useReducer, useState, } from "react";
|
|
8
8
|
const CountervaluesPollingContext = createContext({
|
|
9
9
|
wipe: () => { },
|
|
10
10
|
poll: () => { },
|
|
@@ -30,70 +30,53 @@ function trackingPairsHash(a) {
|
|
|
30
30
|
}
|
|
31
31
|
const marketcapRefresh = 30 * 60000;
|
|
32
32
|
const marketcapRefreshOnError = 60000;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
function useMarketcap() {
|
|
39
|
-
const [ids, setIds] = useState(initialIds);
|
|
40
|
-
const [fetchNonce, setFetchNonce] = useState(0);
|
|
33
|
+
/** Provides market-cap ids via the supplied bridge. */
|
|
34
|
+
export function CountervaluesMarketcapProvider({ children, bridge, }) {
|
|
35
|
+
const ids = bridge.useIds();
|
|
36
|
+
const lastUpdated = bridge.useLastUpdated();
|
|
37
|
+
const [, forceUpdate] = useReducer(x => x + 1, 0);
|
|
41
38
|
useEffect(() => {
|
|
42
39
|
let timeout = null;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
40
|
+
const now = Date.now();
|
|
41
|
+
if (!lastUpdated || now - lastUpdated > marketcapRefresh) {
|
|
42
|
+
bridge.setLoading(true);
|
|
43
|
+
api.fetchIdsSortedByMarketcap().then(fetchedIds => {
|
|
44
|
+
bridge.setIds(fetchedIds);
|
|
45
|
+
timeout = setTimeout(() => forceUpdate(), marketcapRefresh);
|
|
46
|
+
}, error => {
|
|
47
|
+
log("countervalues", "error fetching marketcap ids " + error);
|
|
48
|
+
bridge.setError(error.message);
|
|
49
|
+
timeout = setTimeout(() => forceUpdate(), marketcapRefreshOnError);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
timeout = setTimeout(() => forceUpdate(), marketcapRefresh - (now - lastUpdated));
|
|
54
|
+
}
|
|
50
55
|
return () => {
|
|
51
|
-
if (timeout)
|
|
56
|
+
if (timeout)
|
|
52
57
|
clearTimeout(timeout);
|
|
53
|
-
}
|
|
54
58
|
};
|
|
55
|
-
}, [
|
|
56
|
-
return ids;
|
|
59
|
+
}, [lastUpdated, bridge]);
|
|
60
|
+
return (React.createElement(CountervaluesMarketcapIdsContext.Provider, { value: ids }, children));
|
|
57
61
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return useMemo(() => dateTimestamp
|
|
63
|
-
? trackingPairForTopCoins(marketcapIds, size, countervalue, new Date(dateTimestamp))
|
|
64
|
-
: [], [marketcapIds, countervalue, dateTimestamp, size]);
|
|
65
|
-
}
|
|
66
|
-
export function useTrackingPairForAccounts(accounts, countervalue) {
|
|
67
|
-
// first we cache the tracking pairs with its hash
|
|
68
|
-
const c = useMemo(() => {
|
|
69
|
-
const pairs = inferTrackingPairForAccounts(accounts, countervalue);
|
|
70
|
-
return { pairs, hash: trackingPairsHash(pairs) };
|
|
71
|
-
}, [accounts, countervalue]);
|
|
72
|
-
// we only want to return the pairs when the hash changes
|
|
73
|
-
// to not recalculate pairs as fast as accounts resynchronizes
|
|
74
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
75
|
-
return useMemo(() => c.pairs, [c.hash]);
|
|
76
|
-
}
|
|
77
|
-
export function CountervaluesMarketcap({ children }) {
|
|
78
|
-
const marketcapIds = useMarketcap();
|
|
79
|
-
return (React.createElement(CountervaluesMarketcapIdsContext.Provider, { value: marketcapIds }, children));
|
|
80
|
-
}
|
|
81
|
-
export function Countervalues({ children, userSettings, pollInitDelay = 3 * 1000, debounceDelay = 1000, savedState, }) {
|
|
62
|
+
/**
|
|
63
|
+
* Root countervalues provider (polling + calculation).
|
|
64
|
+
*/
|
|
65
|
+
export function CountervaluesProvider({ children, userSettings, pollInitDelay = 3 * 1000, debounceDelay = 1000, savedState, }) {
|
|
82
66
|
const autopollInterval = userSettings.refreshRate;
|
|
83
67
|
const debouncedUserSettings = useDebounce(userSettings, debounceDelay);
|
|
84
68
|
const [{ state, pending, error }, dispatch] = useReducer(fetchReducer, initialFetchState);
|
|
69
|
+
// TODO this is always using the initial value, doesn't react to changes.
|
|
85
70
|
const marketcapIds = useContext(CountervaluesMarketcapIdsContext);
|
|
86
71
|
const { marketCapBatchingAfterRank } = userSettings;
|
|
87
|
-
const batchStrategySolver = useMemo(() => {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
};
|
|
96
|
-
}, [marketCapBatchingAfterRank, marketcapIds]);
|
|
72
|
+
const batchStrategySolver = useMemo(() => ({
|
|
73
|
+
shouldBatchCurrencyFrom: (currency) => {
|
|
74
|
+
if (currency.type === "FiatCurrency")
|
|
75
|
+
return false;
|
|
76
|
+
const i = marketcapIds.indexOf(currency.id);
|
|
77
|
+
return i === -1 || i > marketCapBatchingAfterRank;
|
|
78
|
+
},
|
|
79
|
+
}), [marketCapBatchingAfterRank, marketcapIds]);
|
|
97
80
|
// flag used to trigger a loadCountervalues
|
|
98
81
|
const [triggerLoad, setTriggerLoad] = useState(false);
|
|
99
82
|
// trigger poll only when userSettings changes. in a debounced way.
|
|
@@ -105,30 +88,18 @@ export function Countervalues({ children, userSettings, pollInitDelay = 3 * 1000
|
|
|
105
88
|
if (pending || !triggerLoad)
|
|
106
89
|
return;
|
|
107
90
|
setTriggerLoad(false);
|
|
108
|
-
dispatch({
|
|
109
|
-
|
|
110
|
-
});
|
|
111
|
-
loadCountervalues(state, userSettings, batchStrategySolver, userSettings.granularitiesRates).then(state => {
|
|
112
|
-
dispatch({
|
|
113
|
-
type: "success",
|
|
114
|
-
payload: state,
|
|
115
|
-
});
|
|
116
|
-
}, error => {
|
|
117
|
-
dispatch({
|
|
118
|
-
type: "error",
|
|
119
|
-
payload: error,
|
|
120
|
-
});
|
|
121
|
-
});
|
|
91
|
+
dispatch({ type: "pending" });
|
|
92
|
+
loadCountervalues(state, userSettings, batchStrategySolver, userSettings.granularitiesRates).then(newState => dispatch({ type: "success", payload: newState }), e => dispatch({ type: "error", payload: e }));
|
|
122
93
|
}, [pending, state, userSettings, triggerLoad, batchStrategySolver]);
|
|
123
94
|
// save the state when it changes
|
|
124
95
|
useEffect(() => {
|
|
125
|
-
if (!
|
|
96
|
+
if (!savedState?.status || !Object.keys(savedState.status).length)
|
|
126
97
|
return;
|
|
127
98
|
dispatch({
|
|
128
99
|
type: "setCounterValueState",
|
|
129
100
|
payload: importCountervalues(savedState, userSettings),
|
|
130
|
-
});
|
|
131
|
-
}, [savedState]);
|
|
101
|
+
});
|
|
102
|
+
}, [savedState, userSettings]);
|
|
132
103
|
// manage the auto polling loop and the interface for user land to trigger a reload
|
|
133
104
|
const [isPolling, setIsPolling] = useState(true);
|
|
134
105
|
useEffect(() => {
|
|
@@ -143,11 +114,7 @@ export function Countervalues({ children, userSettings, pollInitDelay = 3 * 1000
|
|
|
143
114
|
return () => clearTimeout(pollingTimeout);
|
|
144
115
|
}, [autopollInterval, pollInitDelay, isPolling]);
|
|
145
116
|
const polling = useMemo(() => ({
|
|
146
|
-
wipe: () => {
|
|
147
|
-
dispatch({
|
|
148
|
-
type: "wipe",
|
|
149
|
-
});
|
|
150
|
-
},
|
|
117
|
+
wipe: () => dispatch({ type: "wipe" }),
|
|
151
118
|
poll: () => setTriggerLoad(true),
|
|
152
119
|
start: () => setIsPolling(true),
|
|
153
120
|
stop: () => setIsPolling(false),
|
|
@@ -158,34 +125,31 @@ export function Countervalues({ children, userSettings, pollInitDelay = 3 * 1000
|
|
|
158
125
|
React.createElement(CountervaluesUserSettingsContext.Provider, { value: userSettings },
|
|
159
126
|
React.createElement(CountervaluesContext.Provider, { value: state }, children))));
|
|
160
127
|
}
|
|
161
|
-
const initialFetchState = {
|
|
162
|
-
state: initialState,
|
|
163
|
-
pending: false,
|
|
164
|
-
};
|
|
128
|
+
const initialFetchState = { state: initialState, pending: false };
|
|
165
129
|
function fetchReducer(state, action) {
|
|
166
130
|
switch (action.type) {
|
|
167
131
|
case "success":
|
|
168
|
-
return {
|
|
169
|
-
state: action.payload,
|
|
170
|
-
pending: false,
|
|
171
|
-
error: undefined,
|
|
172
|
-
};
|
|
132
|
+
return { state: action.payload, pending: false, error: undefined };
|
|
173
133
|
case "error":
|
|
174
|
-
return
|
|
134
|
+
return { ...state, pending: false, error: action.payload };
|
|
175
135
|
case "pending":
|
|
176
|
-
return
|
|
136
|
+
return { ...state, pending: true, error: undefined };
|
|
177
137
|
case "wipe":
|
|
178
|
-
return {
|
|
179
|
-
state: initialState,
|
|
180
|
-
pending: false,
|
|
181
|
-
error: undefined,
|
|
182
|
-
};
|
|
138
|
+
return { state: initialState, pending: false, error: undefined };
|
|
183
139
|
case "setCounterValueState":
|
|
184
|
-
return
|
|
140
|
+
return { ...state, state: action.payload };
|
|
185
141
|
default:
|
|
186
142
|
return state;
|
|
187
143
|
}
|
|
188
144
|
}
|
|
145
|
+
/** Returns market-cap ids. */
|
|
146
|
+
export function useMarketcapIds() {
|
|
147
|
+
return useContext(CountervaluesMarketcapIdsContext);
|
|
148
|
+
}
|
|
149
|
+
/** Returns the full countervalues state. */
|
|
150
|
+
export function useCountervaluesState() {
|
|
151
|
+
return useContext(CountervaluesContext);
|
|
152
|
+
}
|
|
189
153
|
// allows consumer to access the countervalues polling control object
|
|
190
154
|
export function useCountervaluesPolling() {
|
|
191
155
|
return useContext(CountervaluesPollingContext);
|
|
@@ -194,17 +158,9 @@ export function useCountervaluesPolling() {
|
|
|
194
158
|
export function useCountervaluesUserSettingsContext() {
|
|
195
159
|
return useContext(CountervaluesUserSettingsContext);
|
|
196
160
|
}
|
|
197
|
-
// allows consumer to access the countervalues state
|
|
198
|
-
export function useCountervaluesState() {
|
|
199
|
-
return useContext(CountervaluesContext);
|
|
200
|
-
}
|
|
201
|
-
// allows consumer to access the coins ids sorted by marketcap. It's basically all the coins that the API supports.
|
|
202
|
-
export function useMarketcapIds() {
|
|
203
|
-
return useContext(CountervaluesMarketcapIdsContext);
|
|
204
|
-
}
|
|
205
161
|
// provides an export of the countervalues state
|
|
206
162
|
export function useCountervaluesExport() {
|
|
207
|
-
const state =
|
|
163
|
+
const state = useCountervaluesState();
|
|
208
164
|
return useMemo(() => exportCountervalues(state), [state]);
|
|
209
165
|
}
|
|
210
166
|
// provides a way to calculate a countervalue from a value
|
|
@@ -225,6 +181,7 @@ export function useCalculateCountervalueCallback({ to, }) {
|
|
|
225
181
|
return typeof countervalue === "number" ? new BigNumber(countervalue) : countervalue;
|
|
226
182
|
}, [to, state]);
|
|
227
183
|
}
|
|
184
|
+
/** Helper for send-flow: returns fiat amount and reverse calculation. */
|
|
228
185
|
export function useSendAmount({ account, fiatCurrency, cryptoAmount, }) {
|
|
229
186
|
const cryptoCurrency = getAccountCurrency(account);
|
|
230
187
|
const fiatCountervalue = useCalculate({
|
|
@@ -233,23 +190,34 @@ export function useSendAmount({ account, fiatCurrency, cryptoAmount, }) {
|
|
|
233
190
|
value: cryptoAmount.toNumber(),
|
|
234
191
|
disableRounding: true,
|
|
235
192
|
});
|
|
236
|
-
const fiatAmount = new BigNumber(fiatCountervalue
|
|
193
|
+
const fiatAmount = new BigNumber(fiatCountervalue ?? 0);
|
|
237
194
|
const fiatUnit = fiatCurrency.units[0];
|
|
238
195
|
const state = useCountervaluesState();
|
|
239
|
-
const calculateCryptoAmount = useCallback((fiatAmount) => {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
196
|
+
const calculateCryptoAmount = useCallback((fiatAmount) => new BigNumber(calculate(state, {
|
|
197
|
+
from: cryptoCurrency,
|
|
198
|
+
to: fiatCurrency,
|
|
199
|
+
value: fiatAmount.toNumber(),
|
|
200
|
+
reverse: true,
|
|
201
|
+
}) ?? 0), [state, cryptoCurrency, fiatCurrency]);
|
|
202
|
+
return { fiatAmount, fiatUnit, calculateCryptoAmount };
|
|
203
|
+
}
|
|
204
|
+
// infer the tracking pairs for the top coins that the portfolio needs to display itself
|
|
205
|
+
// if startDate is undefined, the feature is disabled
|
|
206
|
+
export function useTrackingPairsForTopCoins(marketcapIds, countervalue, size, startDate) {
|
|
207
|
+
const dateTimestamp = startDate?.getTime();
|
|
208
|
+
return useMemo(() => dateTimestamp
|
|
209
|
+
? trackingPairForTopCoins(marketcapIds, size, countervalue, new Date(dateTimestamp))
|
|
210
|
+
: [], [marketcapIds, countervalue, dateTimestamp, size]);
|
|
211
|
+
}
|
|
212
|
+
export function useTrackingPairForAccounts(accounts, countervalue) {
|
|
213
|
+
// first we cache the tracking pairs with its hash
|
|
214
|
+
const c = useMemo(() => {
|
|
215
|
+
const pairs = inferTrackingPairForAccounts(accounts, countervalue);
|
|
216
|
+
return { pairs, hash: trackingPairsHash(pairs) };
|
|
217
|
+
}, [accounts, countervalue]);
|
|
218
|
+
// we only want to return the pairs when the hash changes
|
|
219
|
+
// to not recalculate pairs as fast as accounts resynchronizes
|
|
220
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
221
|
+
return useMemo(() => c.pairs, [c.hash]);
|
|
254
222
|
}
|
|
255
223
|
//# sourceMappingURL=index.js.map
|
package/lib-es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0CAA0C,CAAC;AAC9E,OAAO,GAAG,MAAM,wCAAwC,CAAC;AACzD,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,mBAAmB,EACnB,4BAA4B,EAC5B,YAAY,EACZ,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,oCAAoC,CAAC;AAO5C,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAC/D,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAGrC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,EAAE,EAEZ,aAAa,EACb,WAAW,EACX,UAAU,EACV,SAAS,EACT,OAAO,EACP,UAAU,EACV,QAAQ,GACT,MAAM,OAAO,CAAC;AAyCf,MAAM,2BAA2B,GAAG,aAAa,C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AAwF;AACxF,qDAAqD;AACrD,MAAM,UAAU,2BAA2B,CACzC,YAAsB,EACtB,YAAsB,EACtB,IAAY,EACZ,SAA2B;IAE3B,MAAM,aAAa,GAAG,SAAS,EAAE,OAAO,EAAE,CAAC;IAC3C,OAAO,OAAO,CACZ,GAAG,EAAE,CACH,aAAa;QACX,CAAC,CAAC,uBAAuB,CAAC,YAAY,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,IAAI,CAAC,aAAa,CAAC,CAAC;QACpF,CAAC,CAAC,EAAE,EACR,CAAC,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,IAAI,CAAC,CAClD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,0BAA0B,CACxC,QAAmB,EACnB,YAAsB;IAEtB,kDAAkD;IAClD,MAAM,CAAC,GAAG,OAAO,CAAC,GAAG,EAAE;QACrB,MAAM,KAAK,GAAG,4BAA4B,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;QACnE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,iBAAiB,CAAC,KAAK,CAAC,EAAE,CAAC;IACnD,CAAC,EAAE,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC;IAC7B,yDAAyD;IACzD,8DAA8D;IAC9D,uDAAuD;IACvD,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AAC1C,CAAC"}
|
package/lib-es/react.test.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { useTrackingPairForAccounts } from ".";
|
|
11
2
|
import { genAccount } from "@ledgerhq/coin-framework/mocks/account";
|
|
12
3
|
import { renderHook, act } from "@testing-library/react";
|
|
@@ -19,87 +10,87 @@ describe("useTrackingPairForAccounts", () => {
|
|
|
19
10
|
const usd = getFiatCurrencyByTicker("USD");
|
|
20
11
|
const eur = getFiatCurrencyByTicker("EUR");
|
|
21
12
|
const trackingPairs = inferTrackingPairForAccounts(accounts, usd);
|
|
22
|
-
test("it returns same tracking pairs as when using inferTrackingPairForAccounts", () =>
|
|
13
|
+
test("it returns same tracking pairs as when using inferTrackingPairForAccounts", async () => {
|
|
23
14
|
const { result } = renderHook(() => useTrackingPairForAccounts(accounts, usd));
|
|
24
|
-
|
|
15
|
+
await act(async () => {
|
|
25
16
|
expect(result.current).toEqual(trackingPairs);
|
|
26
|
-
})
|
|
27
|
-
})
|
|
28
|
-
test("a re-render preserve the reference", () =>
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
test("a re-render preserve the reference", async () => {
|
|
29
20
|
const { result, rerender } = renderHook(() => useTrackingPairForAccounts(accounts, usd));
|
|
30
21
|
let initial;
|
|
31
|
-
|
|
22
|
+
await act(async () => {
|
|
32
23
|
initial = result.current;
|
|
33
|
-
})
|
|
24
|
+
});
|
|
34
25
|
rerender();
|
|
35
|
-
|
|
26
|
+
await act(async () => {
|
|
36
27
|
expect(result.current).toBe(initial);
|
|
37
|
-
})
|
|
38
|
-
})
|
|
39
|
-
test("a re-render preserve the reference even when accounts change", () =>
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
test("a re-render preserve the reference even when accounts change", async () => {
|
|
40
31
|
const { result, rerender } = renderHook(() => useTrackingPairForAccounts(accounts.slice(0), usd));
|
|
41
32
|
let initial;
|
|
42
|
-
|
|
33
|
+
await act(async () => {
|
|
43
34
|
initial = result.current;
|
|
44
|
-
})
|
|
35
|
+
});
|
|
45
36
|
rerender();
|
|
46
|
-
|
|
37
|
+
await act(async () => {
|
|
47
38
|
expect(result.current).toBe(initial);
|
|
48
|
-
})
|
|
49
|
-
})
|
|
50
|
-
test("when accounts appears, it properly converge to the trackingPairs", () =>
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
test("when accounts appears, it properly converge to the trackingPairs", async () => {
|
|
51
42
|
const { result, rerender } = renderHook(added => useTrackingPairForAccounts(!added ? [] : accounts, usd));
|
|
52
|
-
|
|
43
|
+
await act(async () => {
|
|
53
44
|
expect(result.current).toEqual([]);
|
|
54
|
-
})
|
|
45
|
+
});
|
|
55
46
|
rerender(true);
|
|
56
|
-
|
|
47
|
+
await act(async () => {
|
|
57
48
|
expect(result.current).toEqual(trackingPairs);
|
|
58
|
-
})
|
|
59
|
-
})
|
|
60
|
-
test("when accounts changes fundamentally, pairs change", () =>
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
test("when accounts changes fundamentally, pairs change", async () => {
|
|
61
52
|
const { result, rerender } = renderHook(empty => useTrackingPairForAccounts(empty ? [] : accounts, usd));
|
|
62
|
-
|
|
53
|
+
await act(async () => {
|
|
63
54
|
expect(result.current).toEqual(trackingPairs);
|
|
64
|
-
})
|
|
55
|
+
});
|
|
65
56
|
rerender(true);
|
|
66
|
-
|
|
57
|
+
await act(async () => {
|
|
67
58
|
expect(result.current).toEqual([]);
|
|
68
|
-
})
|
|
69
|
-
})
|
|
70
|
-
test("when currency changes, pairs change", () =>
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
test("when currency changes, pairs change", async () => {
|
|
71
62
|
const { result, rerender } = renderHook(usesEur => useTrackingPairForAccounts(accounts, usesEur ? eur : usd));
|
|
72
|
-
|
|
63
|
+
await act(async () => {
|
|
73
64
|
expect(result.current).toEqual(trackingPairs);
|
|
74
|
-
})
|
|
65
|
+
});
|
|
75
66
|
rerender(true);
|
|
76
|
-
|
|
67
|
+
await act(async () => {
|
|
77
68
|
expect(result.current).not.toEqual(trackingPairs);
|
|
78
|
-
})
|
|
79
|
-
})
|
|
80
|
-
test("if accounts reorder, it doesn't change", () =>
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
test("if accounts reorder, it doesn't change", async () => {
|
|
81
72
|
const reverse = accounts.slice(0).reverse();
|
|
82
73
|
const { result, rerender } = renderHook(rev => useTrackingPairForAccounts(rev ? reverse : accounts, usd));
|
|
83
74
|
let initial;
|
|
84
|
-
|
|
75
|
+
await act(async () => {
|
|
85
76
|
initial = result.current;
|
|
86
|
-
})
|
|
77
|
+
});
|
|
87
78
|
rerender(true);
|
|
88
|
-
|
|
79
|
+
await act(async () => {
|
|
89
80
|
expect(result.current).toBe(initial);
|
|
90
|
-
})
|
|
91
|
-
})
|
|
92
|
-
test("if accounts doubles, it doesn't change", () =>
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
test("if accounts doubles, it doesn't change", async () => {
|
|
93
84
|
const doubled = accounts.concat(accounts);
|
|
94
85
|
const { result, rerender } = renderHook(d => useTrackingPairForAccounts(d ? doubled : accounts, usd));
|
|
95
86
|
let initial;
|
|
96
|
-
|
|
87
|
+
await act(async () => {
|
|
97
88
|
initial = result.current;
|
|
98
|
-
})
|
|
89
|
+
});
|
|
99
90
|
rerender(true);
|
|
100
|
-
|
|
91
|
+
await act(async () => {
|
|
101
92
|
expect(result.current).toBe(initial);
|
|
102
|
-
})
|
|
103
|
-
})
|
|
93
|
+
});
|
|
94
|
+
});
|
|
104
95
|
});
|
|
105
96
|
//# sourceMappingURL=react.test.js.map
|