@ledgerhq/live-countervalues-react 0.1.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/.eslintrc.js +38 -0
- package/.turbo/turbo-build.log +4 -0
- package/.unimportedrc.json +4 -0
- package/CHANGELOG.md +1 -0
- package/LICENSE.txt +21 -0
- package/jest.config.js +14 -0
- package/lib/index.d.ts +48 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +215 -0
- package/lib/index.js.map +1 -0
- package/lib/react.test.d.ts +2 -0
- package/lib/react.test.d.ts.map +1 -0
- package/lib/react.test.js +107 -0
- package/lib/react.test.js.map +1 -0
- package/lib-es/index.d.ts +48 -0
- package/lib-es/index.d.ts.map +1 -0
- package/lib-es/index.js +181 -0
- package/lib-es/index.js.map +1 -0
- package/lib-es/react.test.d.ts +2 -0
- package/lib-es/react.test.d.ts.map +1 -0
- package/lib-es/react.test.js +105 -0
- package/lib-es/react.test.js.map +1 -0
- package/package.json +71 -0
- package/src/index.tsx +329 -0
- package/src/react.test.ts +117 -0
- package/tsconfig.json +15 -0
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
settings: {
|
|
3
|
+
react: {
|
|
4
|
+
version: "detect",
|
|
5
|
+
},
|
|
6
|
+
},
|
|
7
|
+
env: {
|
|
8
|
+
browser: true,
|
|
9
|
+
es6: true,
|
|
10
|
+
},
|
|
11
|
+
globals: {
|
|
12
|
+
Atomics: "readonly",
|
|
13
|
+
SharedArrayBuffer: "readonly",
|
|
14
|
+
},
|
|
15
|
+
extends: [
|
|
16
|
+
"plugin:import/typescript",
|
|
17
|
+
"plugin:jsx-a11y/recommended",
|
|
18
|
+
"plugin:react/recommended",
|
|
19
|
+
"plugin:react-hooks/recommended",
|
|
20
|
+
],
|
|
21
|
+
plugins: ["react", "react-hooks", "import", "jsx-a11y"],
|
|
22
|
+
rules: {
|
|
23
|
+
"no-console": ["error", { allow: ["warn", "error"] }],
|
|
24
|
+
"linebreak-style": ["error", "unix"],
|
|
25
|
+
"@typescript-eslint/no-empty-function": "off",
|
|
26
|
+
"@typescript-eslint/no-namespace": ["error", { allowDeclarations: true }],
|
|
27
|
+
"@typescript-eslint/no-explicit-any": "warn",
|
|
28
|
+
},
|
|
29
|
+
overrides: [
|
|
30
|
+
{
|
|
31
|
+
files: ["src/**/*.test.{ts,tsx}"],
|
|
32
|
+
env: {
|
|
33
|
+
"jest/globals": true,
|
|
34
|
+
},
|
|
35
|
+
plugins: ["jest"],
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
};
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @ledgerhq/live-countervalues-react
|
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017-present Ledger https://www.ledger.com/
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/jest.config.js
ADDED
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import React, { ReactElement } from "react";
|
|
3
|
+
import type { CounterValuesState, CounterValuesStateRaw, CountervaluesSettings, TrackingPair } from "@ledgerhq/live-countervalues/types";
|
|
4
|
+
import type { Account, AccountLike } from "@ledgerhq/types-live";
|
|
5
|
+
import type { Currency, Unit } from "@ledgerhq/types-cryptoassets";
|
|
6
|
+
export type Polling = {
|
|
7
|
+
wipe: () => void;
|
|
8
|
+
poll: () => void;
|
|
9
|
+
start: () => void;
|
|
10
|
+
stop: () => void;
|
|
11
|
+
pending: boolean;
|
|
12
|
+
error: Error | null | undefined;
|
|
13
|
+
};
|
|
14
|
+
export type Props = {
|
|
15
|
+
children: React.ReactNode;
|
|
16
|
+
userSettings: CountervaluesSettings;
|
|
17
|
+
pollInitDelay?: number;
|
|
18
|
+
autopollInterval?: number;
|
|
19
|
+
debounceDelay?: number;
|
|
20
|
+
savedState?: CounterValuesStateRaw;
|
|
21
|
+
};
|
|
22
|
+
export declare function useTrackingPairForAccounts(accounts: Account[], countervalue: Currency): TrackingPair[];
|
|
23
|
+
export declare function Countervalues({ children, userSettings, pollInitDelay, autopollInterval, debounceDelay, savedState, }: Props): ReactElement;
|
|
24
|
+
export declare function useCountervaluesPolling(): Polling;
|
|
25
|
+
export declare function useCountervaluesState(): CounterValuesState;
|
|
26
|
+
export declare function useCountervaluesExport(): CounterValuesStateRaw;
|
|
27
|
+
export declare function useCalculate(query: {
|
|
28
|
+
value: number;
|
|
29
|
+
from: Currency;
|
|
30
|
+
to: Currency;
|
|
31
|
+
disableRounding?: boolean;
|
|
32
|
+
date?: Date | null | undefined;
|
|
33
|
+
reverse?: boolean;
|
|
34
|
+
}): number | null | undefined;
|
|
35
|
+
export declare function useCalculateCountervalueCallback({ to, }: {
|
|
36
|
+
to: Currency;
|
|
37
|
+
}): (from: Currency, value: BigNumber) => BigNumber | null | undefined;
|
|
38
|
+
export declare function useSendAmount({ account, fiatCurrency, cryptoAmount, }: {
|
|
39
|
+
account: AccountLike;
|
|
40
|
+
fiatCurrency: Currency;
|
|
41
|
+
cryptoAmount: BigNumber;
|
|
42
|
+
}): {
|
|
43
|
+
cryptoUnit: Unit;
|
|
44
|
+
fiatAmount: BigNumber;
|
|
45
|
+
fiatUnit: Unit;
|
|
46
|
+
calculateCryptoAmount: (fiatAmount: BigNumber) => BigNumber;
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,EAAE,EAQZ,YAAY,EACb,MAAM,OAAO,CAAC;AAUf,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACrB,qBAAqB,EACrB,YAAY,EACb,MAAM,oCAAoC,CAAC;AAE5C,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AAGnE,MAAM,MAAM,OAAO,GAAG;IAEpB,IAAI,EAAE,MAAM,IAAI,CAAC;IAIjB,IAAI,EAAE,MAAM,IAAI,CAAC;IAEjB,KAAK,EAAE,MAAM,IAAI,CAAC;IAElB,IAAI,EAAE,MAAM,IAAI,CAAC;IAEjB,OAAO,EAAE,OAAO,CAAC;IAEjB,KAAK,EAAE,KAAK,GAAG,IAAI,GAAG,SAAS,CAAC;CACjC,CAAC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,WAAW,CAAC;IACrB,YAAY,EAAE,QAAQ,CAAC;IACvB,YAAY,EAAE,SAAS,CAAC;CACzB,GAAG;IACF,UAAU,EAAE,IAAI,CAAC;IACjB,UAAU,EAAE,SAAS,CAAC;IACtB,QAAQ,EAAE,IAAI,CAAC;IACf,qBAAqB,EAAE,CAAC,UAAU,EAAE,SAAS,KAAK,SAAS,CAAC;CAC7D,CAgCA"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.useSendAmount = exports.useCalculateCountervalueCallback = exports.useCalculate = exports.useCountervaluesExport = exports.useCountervaluesState = exports.useCountervaluesPolling = exports.Countervalues = exports.useTrackingPairForAccounts = void 0;
|
|
27
|
+
const bignumber_js_1 = require("bignumber.js");
|
|
28
|
+
const react_1 = __importStar(require("react"));
|
|
29
|
+
const helpers_1 = require("@ledgerhq/coin-framework/account/helpers");
|
|
30
|
+
const logic_1 = require("@ledgerhq/live-countervalues/logic");
|
|
31
|
+
const useDebounce_1 = require("@ledgerhq/live-hooks/useDebounce");
|
|
32
|
+
const CountervaluesPollingContext = (0, react_1.createContext)({
|
|
33
|
+
wipe: () => { },
|
|
34
|
+
poll: () => { },
|
|
35
|
+
start: () => { },
|
|
36
|
+
stop: () => { },
|
|
37
|
+
pending: false,
|
|
38
|
+
error: null,
|
|
39
|
+
});
|
|
40
|
+
const CountervaluesContext = (0, react_1.createContext)(logic_1.initialState);
|
|
41
|
+
function trackingPairsHash(a) {
|
|
42
|
+
return a
|
|
43
|
+
.map(p => `${p.from.ticker}:${p.to.ticker}:${p.startDate.toISOString().slice(0, 10) || ""}`)
|
|
44
|
+
.sort()
|
|
45
|
+
.join("|");
|
|
46
|
+
}
|
|
47
|
+
function useTrackingPairForAccounts(accounts, countervalue) {
|
|
48
|
+
// first we cache the tracking pairs with its hash
|
|
49
|
+
const c = (0, react_1.useMemo)(() => {
|
|
50
|
+
const pairs = (0, logic_1.inferTrackingPairForAccounts)(accounts, countervalue);
|
|
51
|
+
return { pairs, hash: trackingPairsHash(pairs) };
|
|
52
|
+
}, [accounts, countervalue]);
|
|
53
|
+
// we only want to return the pairs when the hash changes
|
|
54
|
+
// to not recalculate pairs as fast as accounts resynchronizes
|
|
55
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
56
|
+
return (0, react_1.useMemo)(() => c.pairs, [c.hash]);
|
|
57
|
+
}
|
|
58
|
+
exports.useTrackingPairForAccounts = useTrackingPairForAccounts;
|
|
59
|
+
function Countervalues({ children, userSettings, pollInitDelay = 3 * 1000, autopollInterval = 8 * 60 * 1000, debounceDelay = 1000, savedState, }) {
|
|
60
|
+
const debouncedUserSettings = (0, useDebounce_1.useDebounce)(userSettings, debounceDelay);
|
|
61
|
+
const [{ state, pending, error }, dispatch] = (0, react_1.useReducer)(fetchReducer, initialFetchState);
|
|
62
|
+
// flag used to trigger a loadCountervalues
|
|
63
|
+
const [triggerLoad, setTriggerLoad] = (0, react_1.useState)(false);
|
|
64
|
+
// trigger poll only when userSettings changes. in a debounced way.
|
|
65
|
+
(0, react_1.useEffect)(() => {
|
|
66
|
+
setTriggerLoad(true);
|
|
67
|
+
}, [debouncedUserSettings]);
|
|
68
|
+
// loadCountervalues logic
|
|
69
|
+
(0, react_1.useEffect)(() => {
|
|
70
|
+
if (pending || !triggerLoad)
|
|
71
|
+
return;
|
|
72
|
+
setTriggerLoad(false);
|
|
73
|
+
dispatch({
|
|
74
|
+
type: "pending",
|
|
75
|
+
});
|
|
76
|
+
(0, logic_1.loadCountervalues)(state, userSettings).then(state => {
|
|
77
|
+
dispatch({
|
|
78
|
+
type: "success",
|
|
79
|
+
payload: state,
|
|
80
|
+
});
|
|
81
|
+
}, error => {
|
|
82
|
+
dispatch({
|
|
83
|
+
type: "error",
|
|
84
|
+
payload: error,
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
}, [pending, state, userSettings, triggerLoad]);
|
|
88
|
+
// save the state when it changes
|
|
89
|
+
(0, react_1.useEffect)(() => {
|
|
90
|
+
if (!(savedState === null || savedState === void 0 ? void 0 : savedState.status) || !Object.keys(savedState.status).length)
|
|
91
|
+
return;
|
|
92
|
+
dispatch({
|
|
93
|
+
type: "setCounterValueState",
|
|
94
|
+
payload: (0, logic_1.importCountervalues)(savedState, userSettings),
|
|
95
|
+
}); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
96
|
+
}, [savedState]);
|
|
97
|
+
// manage the auto polling loop and the interface for user land to trigger a reload
|
|
98
|
+
const [isPolling, setIsPolling] = (0, react_1.useState)(true);
|
|
99
|
+
(0, react_1.useEffect)(() => {
|
|
100
|
+
if (!isPolling)
|
|
101
|
+
return;
|
|
102
|
+
let pollingTimeout;
|
|
103
|
+
function pollingLoop() {
|
|
104
|
+
setTriggerLoad(true);
|
|
105
|
+
pollingTimeout = setTimeout(pollingLoop, autopollInterval);
|
|
106
|
+
}
|
|
107
|
+
pollingTimeout = setTimeout(pollingLoop, pollInitDelay);
|
|
108
|
+
return () => clearTimeout(pollingTimeout);
|
|
109
|
+
}, [autopollInterval, pollInitDelay, isPolling]);
|
|
110
|
+
const polling = (0, react_1.useMemo)(() => ({
|
|
111
|
+
wipe: () => {
|
|
112
|
+
dispatch({
|
|
113
|
+
type: "wipe",
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
poll: () => setTriggerLoad(true),
|
|
117
|
+
start: () => setIsPolling(true),
|
|
118
|
+
stop: () => setIsPolling(false),
|
|
119
|
+
pending,
|
|
120
|
+
error,
|
|
121
|
+
}), [pending, error]);
|
|
122
|
+
return (react_1.default.createElement(CountervaluesPollingContext.Provider, { value: polling },
|
|
123
|
+
react_1.default.createElement(CountervaluesContext.Provider, { value: state }, children)));
|
|
124
|
+
}
|
|
125
|
+
exports.Countervalues = Countervalues;
|
|
126
|
+
const initialFetchState = {
|
|
127
|
+
state: logic_1.initialState,
|
|
128
|
+
pending: false,
|
|
129
|
+
};
|
|
130
|
+
function fetchReducer(state, action) {
|
|
131
|
+
switch (action.type) {
|
|
132
|
+
case "success":
|
|
133
|
+
return {
|
|
134
|
+
state: action.payload,
|
|
135
|
+
pending: false,
|
|
136
|
+
error: undefined,
|
|
137
|
+
};
|
|
138
|
+
case "error":
|
|
139
|
+
return Object.assign(Object.assign({}, state), { pending: false, error: action.payload });
|
|
140
|
+
case "pending":
|
|
141
|
+
return Object.assign(Object.assign({}, state), { pending: true, error: undefined });
|
|
142
|
+
case "wipe":
|
|
143
|
+
return {
|
|
144
|
+
state: logic_1.initialState,
|
|
145
|
+
pending: false,
|
|
146
|
+
error: undefined,
|
|
147
|
+
};
|
|
148
|
+
case "setCounterValueState":
|
|
149
|
+
return Object.assign(Object.assign({}, state), { state: action.payload });
|
|
150
|
+
default:
|
|
151
|
+
return state;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function useCountervaluesPolling() {
|
|
155
|
+
return (0, react_1.useContext)(CountervaluesPollingContext);
|
|
156
|
+
}
|
|
157
|
+
exports.useCountervaluesPolling = useCountervaluesPolling;
|
|
158
|
+
function useCountervaluesState() {
|
|
159
|
+
return (0, react_1.useContext)(CountervaluesContext);
|
|
160
|
+
}
|
|
161
|
+
exports.useCountervaluesState = useCountervaluesState;
|
|
162
|
+
function useCountervaluesExport() {
|
|
163
|
+
const state = (0, react_1.useContext)(CountervaluesContext);
|
|
164
|
+
return (0, react_1.useMemo)(() => (0, logic_1.exportCountervalues)(state), [state]);
|
|
165
|
+
}
|
|
166
|
+
exports.useCountervaluesExport = useCountervaluesExport;
|
|
167
|
+
function useCalculate(query) {
|
|
168
|
+
const state = useCountervaluesState();
|
|
169
|
+
return (0, logic_1.calculate)(state, query);
|
|
170
|
+
}
|
|
171
|
+
exports.useCalculate = useCalculate;
|
|
172
|
+
function useCalculateCountervalueCallback({ to, }) {
|
|
173
|
+
const state = useCountervaluesState();
|
|
174
|
+
return (0, react_1.useCallback)((from, value) => {
|
|
175
|
+
const countervalue = (0, logic_1.calculate)(state, {
|
|
176
|
+
value: value.toNumber(),
|
|
177
|
+
from,
|
|
178
|
+
to,
|
|
179
|
+
disableRounding: true,
|
|
180
|
+
});
|
|
181
|
+
return typeof countervalue === "number" ? new bignumber_js_1.BigNumber(countervalue) : countervalue;
|
|
182
|
+
}, [to, state]);
|
|
183
|
+
}
|
|
184
|
+
exports.useCalculateCountervalueCallback = useCalculateCountervalueCallback;
|
|
185
|
+
function useSendAmount({ account, fiatCurrency, cryptoAmount, }) {
|
|
186
|
+
const cryptoCurrency = (0, helpers_1.getAccountCurrency)(account);
|
|
187
|
+
const fiatCountervalue = useCalculate({
|
|
188
|
+
from: cryptoCurrency,
|
|
189
|
+
to: fiatCurrency,
|
|
190
|
+
value: cryptoAmount.toNumber(),
|
|
191
|
+
disableRounding: true,
|
|
192
|
+
});
|
|
193
|
+
const fiatAmount = new bignumber_js_1.BigNumber(fiatCountervalue !== null && fiatCountervalue !== void 0 ? fiatCountervalue : 0);
|
|
194
|
+
const fiatUnit = fiatCurrency.units[0];
|
|
195
|
+
const cryptoUnit = (0, helpers_1.getAccountUnit)(account);
|
|
196
|
+
const state = useCountervaluesState();
|
|
197
|
+
const calculateCryptoAmount = (0, react_1.useCallback)((fiatAmount) => {
|
|
198
|
+
var _a;
|
|
199
|
+
const cryptoAmount = new bignumber_js_1.BigNumber((_a = (0, logic_1.calculate)(state, {
|
|
200
|
+
from: cryptoCurrency,
|
|
201
|
+
to: fiatCurrency,
|
|
202
|
+
value: fiatAmount.toNumber(),
|
|
203
|
+
reverse: true,
|
|
204
|
+
})) !== null && _a !== void 0 ? _a : 0);
|
|
205
|
+
return cryptoAmount;
|
|
206
|
+
}, [state, cryptoCurrency, fiatCurrency]);
|
|
207
|
+
return {
|
|
208
|
+
cryptoUnit,
|
|
209
|
+
fiatAmount,
|
|
210
|
+
fiatUnit,
|
|
211
|
+
calculateCryptoAmount,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
exports.useSendAmount = useSendAmount;
|
|
215
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAyC;AACzC,+CASe;AACf,sEAA8F;AAC9F,8DAO4C;AAO5C,kEAA+D;AAiC/D,MAAM,2BAA2B,GAAG,IAAA,qBAAa,EAAU;IACzD,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;IACd,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;IACd,KAAK,EAAE,GAAG,EAAE,GAAE,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A,wBAAc,EAAC,OAAO,CAAC,CAAC;IAC3C,MAAM,KAAK,GAAG,qBAAqB,EAAE,CAAC;IACtC,MAAM,qBAAqB,GAAG,IAAA,mBAAW,EACvC,CAAC,UAAqB,EAAE,EAAE;;QACxB,MAAM,YAAY,GAAG,IAAI,wBAAS,CAChC,MAAA,IAAA,iBAAS,EAAC,KAAK,EAAE;YACf,IAAI,EAAE,cAAc;YACpB,EAAE,EAAE,YAAY;YAChB,KAAK,EAAE,UAAU,CAAC,QAAQ,EAAE;YAC5B,OAAO,EAAE,IAAI;SACd,CAAC,mCAAI,CAAC,CACR,CAAC;QACF,OAAO,YAAY,CAAC;IACtB,CAAC,EACD,CAAC,KAAK,EAAE,cAAc,EAAE,YAAY,CAAC,CACtC,CAAC;IACF,OAAO;QACL,UAAU;QACV,UAAU;QACV,QAAQ;QACR,qBAAqB;KACtB,CAAC;AACJ,CAAC;AA7CD,sCA6CC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.test.d.ts","sourceRoot":"","sources":["../src/react.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const _1 = require(".");
|
|
13
|
+
const account_1 = require("@ledgerhq/coin-framework/mocks/account");
|
|
14
|
+
const react_1 = require("@testing-library/react");
|
|
15
|
+
const cryptoassets_1 = require("@ledgerhq/cryptoassets");
|
|
16
|
+
const logic_1 = require("@ledgerhq/live-countervalues/logic");
|
|
17
|
+
describe("useTrackingPairForAccounts", () => {
|
|
18
|
+
const accounts = Array(20)
|
|
19
|
+
.fill(null)
|
|
20
|
+
.map((_, i) => (0, account_1.genAccount)("test" + i));
|
|
21
|
+
const usd = (0, cryptoassets_1.getFiatCurrencyByTicker)("USD");
|
|
22
|
+
const eur = (0, cryptoassets_1.getFiatCurrencyByTicker)("EUR");
|
|
23
|
+
const trackingPairs = (0, logic_1.inferTrackingPairForAccounts)(accounts, usd);
|
|
24
|
+
test("it returns same tracking pairs as when using inferTrackingPairForAccounts", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
const { result } = (0, react_1.renderHook)(() => (0, _1.useTrackingPairForAccounts)(accounts, usd));
|
|
26
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
expect(result.current).toEqual(trackingPairs);
|
|
28
|
+
}));
|
|
29
|
+
}));
|
|
30
|
+
test("a re-render preserve the reference", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
+
const { result, rerender } = (0, react_1.renderHook)(() => (0, _1.useTrackingPairForAccounts)(accounts, usd));
|
|
32
|
+
let initial;
|
|
33
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
initial = result.current;
|
|
35
|
+
}));
|
|
36
|
+
rerender();
|
|
37
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
expect(result.current).toBe(initial);
|
|
39
|
+
}));
|
|
40
|
+
}));
|
|
41
|
+
test("a re-render preserve the reference even when accounts change", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
+
const { result, rerender } = (0, react_1.renderHook)(() => (0, _1.useTrackingPairForAccounts)(accounts.slice(0), usd));
|
|
43
|
+
let initial;
|
|
44
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
+
initial = result.current;
|
|
46
|
+
}));
|
|
47
|
+
rerender();
|
|
48
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
+
expect(result.current).toBe(initial);
|
|
50
|
+
}));
|
|
51
|
+
}));
|
|
52
|
+
test("when accounts appears, it properly converge to the trackingPairs", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
+
const { result, rerender } = (0, react_1.renderHook)(added => (0, _1.useTrackingPairForAccounts)(!added ? [] : accounts, usd));
|
|
54
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
+
expect(result.current).toEqual([]);
|
|
56
|
+
}));
|
|
57
|
+
rerender(true);
|
|
58
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
|
+
expect(result.current).toEqual(trackingPairs);
|
|
60
|
+
}));
|
|
61
|
+
}));
|
|
62
|
+
test("when accounts changes fundamentally, pairs change", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
+
const { result, rerender } = (0, react_1.renderHook)(empty => (0, _1.useTrackingPairForAccounts)(empty ? [] : accounts, usd));
|
|
64
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
+
expect(result.current).toEqual(trackingPairs);
|
|
66
|
+
}));
|
|
67
|
+
rerender(true);
|
|
68
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
69
|
+
expect(result.current).toEqual([]);
|
|
70
|
+
}));
|
|
71
|
+
}));
|
|
72
|
+
test("when currency changes, pairs change", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
73
|
+
const { result, rerender } = (0, react_1.renderHook)(usesEur => (0, _1.useTrackingPairForAccounts)(accounts, usesEur ? eur : usd));
|
|
74
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
75
|
+
expect(result.current).toEqual(trackingPairs);
|
|
76
|
+
}));
|
|
77
|
+
rerender(true);
|
|
78
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
79
|
+
expect(result.current).not.toEqual(trackingPairs);
|
|
80
|
+
}));
|
|
81
|
+
}));
|
|
82
|
+
test("if accounts reorder, it doesn't change", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
83
|
+
const reverse = accounts.slice(0).reverse();
|
|
84
|
+
const { result, rerender } = (0, react_1.renderHook)(rev => (0, _1.useTrackingPairForAccounts)(rev ? reverse : accounts, usd));
|
|
85
|
+
let initial;
|
|
86
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
87
|
+
initial = result.current;
|
|
88
|
+
}));
|
|
89
|
+
rerender(true);
|
|
90
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
91
|
+
expect(result.current).toBe(initial);
|
|
92
|
+
}));
|
|
93
|
+
}));
|
|
94
|
+
test("if accounts doubles, it doesn't change", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
95
|
+
const doubled = accounts.concat(accounts);
|
|
96
|
+
const { result, rerender } = (0, react_1.renderHook)(d => (0, _1.useTrackingPairForAccounts)(d ? doubled : accounts, usd));
|
|
97
|
+
let initial;
|
|
98
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
99
|
+
initial = result.current;
|
|
100
|
+
}));
|
|
101
|
+
rerender(true);
|
|
102
|
+
yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
103
|
+
expect(result.current).toBe(initial);
|
|
104
|
+
}));
|
|
105
|
+
}));
|
|
106
|
+
});
|
|
107
|
+
//# sourceMappingURL=react.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.test.js","sourceRoot":"","sources":["../src/react.test.ts"],"names":[],"mappings":";;;;;;;;;;;AA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C,CAAA,CAAC,CAAC;QACH,QAAQ,CAAC,IAAI,CAAC,CAAC;QACf,MAAM,IAAA,WAAG,EAAC,GAAS,EAAE;YACnB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvC,CAAC,CAAA,CAAC,CAAC;IACL,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import React, { ReactElement } from "react";
|
|
3
|
+
import type { CounterValuesState, CounterValuesStateRaw, CountervaluesSettings, TrackingPair } from "@ledgerhq/live-countervalues/types";
|
|
4
|
+
import type { Account, AccountLike } from "@ledgerhq/types-live";
|
|
5
|
+
import type { Currency, Unit } from "@ledgerhq/types-cryptoassets";
|
|
6
|
+
export type Polling = {
|
|
7
|
+
wipe: () => void;
|
|
8
|
+
poll: () => void;
|
|
9
|
+
start: () => void;
|
|
10
|
+
stop: () => void;
|
|
11
|
+
pending: boolean;
|
|
12
|
+
error: Error | null | undefined;
|
|
13
|
+
};
|
|
14
|
+
export type Props = {
|
|
15
|
+
children: React.ReactNode;
|
|
16
|
+
userSettings: CountervaluesSettings;
|
|
17
|
+
pollInitDelay?: number;
|
|
18
|
+
autopollInterval?: number;
|
|
19
|
+
debounceDelay?: number;
|
|
20
|
+
savedState?: CounterValuesStateRaw;
|
|
21
|
+
};
|
|
22
|
+
export declare function useTrackingPairForAccounts(accounts: Account[], countervalue: Currency): TrackingPair[];
|
|
23
|
+
export declare function Countervalues({ children, userSettings, pollInitDelay, autopollInterval, debounceDelay, savedState, }: Props): ReactElement;
|
|
24
|
+
export declare function useCountervaluesPolling(): Polling;
|
|
25
|
+
export declare function useCountervaluesState(): CounterValuesState;
|
|
26
|
+
export declare function useCountervaluesExport(): CounterValuesStateRaw;
|
|
27
|
+
export declare function useCalculate(query: {
|
|
28
|
+
value: number;
|
|
29
|
+
from: Currency;
|
|
30
|
+
to: Currency;
|
|
31
|
+
disableRounding?: boolean;
|
|
32
|
+
date?: Date | null | undefined;
|
|
33
|
+
reverse?: boolean;
|
|
34
|
+
}): number | null | undefined;
|
|
35
|
+
export declare function useCalculateCountervalueCallback({ to, }: {
|
|
36
|
+
to: Currency;
|
|
37
|
+
}): (from: Currency, value: BigNumber) => BigNumber | null | undefined;
|
|
38
|
+
export declare function useSendAmount({ account, fiatCurrency, cryptoAmount, }: {
|
|
39
|
+
account: AccountLike;
|
|
40
|
+
fiatCurrency: Currency;
|
|
41
|
+
cryptoAmount: BigNumber;
|
|
42
|
+
}): {
|
|
43
|
+
cryptoUnit: Unit;
|
|
44
|
+
fiatAmount: BigNumber;
|
|
45
|
+
fiatUnit: Unit;
|
|
46
|
+
calculateCryptoAmount: (fiatAmount: BigNumber) => BigNumber;
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,EAAE,EAQZ,YAAY,EACb,MAAM,OAAO,CAAC;AAUf,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACrB,qBAAqB,EACrB,YAAY,EACb,MAAM,oCAAoC,CAAC;AAE5C,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AAGnE,MAAM,MAAM,OAAO,GAAG;IAEpB,IAAI,EAAE,MAAM,IAAI,CAAC;IAIjB,IAAI,EAAE,MAAM,IAAI,CAAC;IAEjB,KAAK,EAAE,MAAM,IAAI,CAAC;IAElB,IAAI,EAAE,MAAM,IAAI,CAAC;IAEjB,OAAO,EAAE,OAAO,CAAC;IAEj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