From 50a2347700b3f03e193f596fe295855b2aec5478 Mon Sep 17 00:00:00 2001 From: L Date: Tue, 29 Mar 2022 14:13:29 +0200 Subject: [PATCH 1/3] (MarketProvider): updated for better ux and seperation of data sections single vs list market data (#1820) * (MarketProvider): updated for better ux and seperation of data sections single vs list market data * (Market): fix loading issue --- src/market/MarketDataProvider.tsx | 171 +++++++++++++----------------- 1 file changed, 73 insertions(+), 98 deletions(-) diff --git a/src/market/MarketDataProvider.tsx b/src/market/MarketDataProvider.tsx index aadc354e35..4d076e717d 100644 --- a/src/market/MarketDataProvider.tsx +++ b/src/market/MarketDataProvider.tsx @@ -7,7 +7,6 @@ import React, { ReactElement, useReducer, useEffect, - useState, } from "react"; import { useDebounce } from "../hooks/useDebounce"; @@ -19,9 +18,9 @@ import { MarketCurrencyChartDataRequestParams, CurrencyData, SingleCoinState, + SupportedCoins, } from "./types"; import defaultFetchApi from "./api/api"; - type Props = { children: React.ReactNode; fetchApi?: MarketDataApi; @@ -31,7 +30,7 @@ type Props = { type API = { refresh: (param?: MarketListRequestParams) => void; refreshChart: (param?: MarketCurrencyChartDataRequestParams) => void; - selectCurrency: (key: string) => void; + selectCurrency: (id?: string, data?: CurrencyData, range?: string) => void; loadNextPage: () => Promise; setCounterCurrency: (counterCurrency: string) => void; }; @@ -113,23 +112,25 @@ function marketDataReducer(state, action) { }; } case ACTIONS.UPDATE_SINGLE_MARKET_DATA: { - const marketData = [...state.marketData.map((data) => ({ ...data }))]; - const index = marketData.findIndex(({ id }) => id === action.payload.id); - if (index >= 0) { - marketData[index] = { ...marketData[index], ...action.payload }; - } - return { ...state, marketData, loading: false }; + return { + ...state, + selectedCoinData: { ...state.selectedCoinData, ...action.payload }, + loading: false, + }; } case ACTIONS.UPDATE_SINGLE_CHART_DATA: { - const marketData = [...state.marketData.map((data) => ({ ...data }))]; - const index = marketData.findIndex(({ id }) => id === action.payload.id); - if (index >= 0) { - marketData[index].chartData = { - ...marketData[index].chartData, - ...action.payload.chartData, - }; - } - return { ...state, marketData, loading: false }; + const chartRequestParams = { + ...state.chartRequestParams, + loadingChart: false, + }; + const selectedCoinData = { ...state.selectedCoinData }; + + selectedCoinData.chartData = { + ...selectedCoinData.chartData, + ...action.payload.chartData, + }; + + return { ...state, selectedCoinData, chartRequestParams }; } case ACTIONS.REFRESH_MARKET_DATA: { @@ -184,12 +185,23 @@ function marketDataReducer(state, action) { return { ...state, loadingChart: action.payload }; case ACTIONS.SET_ERROR: return { ...state, error: action.payload, loading: false }; - case ACTIONS.SELECT_CURRENCY: + case ACTIONS.SELECT_CURRENCY: { + const chartRequestParams = { + ...state.chartRequestParams, + counterCurrency: state.requestParams.counterCurrency, + range: action.payload.range || state.requestParams.range, + id: action.payload.id, + loadingChart: !!action.payload.id, + lastRequestTime: Date.now(), + }; return { ...state, - selectedCurrency: action.payload, - loading: !!action.payload, + selectedCurrency: action.payload.id, + selectedCoinData: action.payload.data, + loading: !!action.payload.id, + chartRequestParams, }; + } default: return state; } @@ -207,15 +219,15 @@ export const MarketDataProvider = ({ }); const api = fetchApi || defaultFetchApi; const { - marketData, requestParams, chartRequestParams, loading, loadingChart, page, + selectedCoinData, } = useDebounce(state, 300); - const handleError = useCallback((payload) => { + const handleError = useCallback((payload: Error) => { dispatch({ type: ACTIONS.SET_ERROR, payload }); }, []); @@ -224,7 +236,7 @@ export const MarketDataProvider = ({ const ticker = countervalue.ticker.toLowerCase(); api.supportedCounterCurrencies().then( (supportedCounterCurrencies) => - api.setSupportedCoinsList().then((coins) => { + api.setSupportedCoinsList().then((coins: SupportedCoins) => { dispatch({ type: ACTIONS.IS_READY, payload: { @@ -250,12 +262,9 @@ export const MarketDataProvider = ({ chartRequestParams?.counterCurrency && !loadingChart ) { - const currentMarketData = marketData.find( - ({ id }: CurrencyData) => id === chartRequestParams.id - ); const range = chartRequestParams.range; - if (currentMarketData && !currentMarketData?.chartData?.[range]) { + if (selectedCoinData && !selectedCoinData?.chartData?.[range]) { api.currencyChartData(chartRequestParams).then( (chartData) => dispatch({ @@ -270,14 +279,10 @@ export const MarketDataProvider = ({ payload: false, }); } - }, [chartRequestParams, marketData, loadingChart, api, handleError]); + }, [chartRequestParams, selectedCoinData, api, handleError, loadingChart]); useEffect(() => { - if ( - chartRequestParams?.id && - chartRequestParams?.counterCurrency && - !loading - ) { + if (chartRequestParams?.id && chartRequestParams?.counterCurrency) { dispatch({ type: ACTIONS.SET_LOADING, payload: true }); api .listPaginated({ @@ -321,37 +326,34 @@ export const MarketDataProvider = ({ dispatch({ type: ACTIONS.REFRESH_CHART_DATA, payload }); }, []); - const selectCurrency = useCallback((id) => { - dispatch({ - type: ACTIONS.REFRESH_CHART_DATA, - payload: { - id, - }, - }); + const selectCurrency = useCallback((id, data, range) => { + dispatch({ type: ACTIONS.SELECT_CURRENCY, payload: { id, data, range } }); }, []); - const loadNextPage = useCallback(() => { - return new Promise((resolve, reject) => { - if (loading) { - reject(new Error()); - } else { - const newPage = page + 1; - api.listPaginated({ ...requestParams, page: newPage }).then( - (marketData) => { - dispatch({ - type: ACTIONS.UPDATE_MARKET_DATA, - payload: { marketData, page: newPage }, - }); - resolve(true); - }, - (err) => { - handleError(err); - reject(new Error(err)); - } - ); - } - }); - }, [loading, page, api, requestParams, handleError]); + const loadNextPage = useCallback( + () => + new Promise((resolve, reject) => { + if (loading) { + reject(new Error()); + } else { + const newPage = page + 1; + api.listPaginated({ ...requestParams, page: newPage }).then( + (marketData) => { + dispatch({ + type: ACTIONS.UPDATE_MARKET_DATA, + payload: { marketData, page: newPage }, + }); + resolve(true); + }, + (err) => { + handleError(err); + reject(new Error(err)); + } + ); + } + }), + [loading, page, api, requestParams, handleError] + ); const setCounterCurrency = useCallback( (payload) => dispatch({ type: ACTIONS.UPDATE_COUNTERVALUE, payload }), @@ -379,16 +381,16 @@ export function useMarketData(): MarketDataContextType { } type SingleCoinProviderData = SingleCoinState & { + selectCurrency: (id?: string, data?: CurrencyData, range?: string) => void; refreshChart: (param?: MarketCurrencyChartDataRequestParams) => void; setCounterCurrency: (counterCurrency: string) => void; }; -export function useSingleCoinMarketData( - currencyId: string -): SingleCoinProviderData { +export function useSingleCoinMarketData(): SingleCoinProviderData { const { - marketData, selectedCurrency, + selectedCoinData, + selectCurrency, chartRequestParams, loading, loadingChart, @@ -399,9 +401,10 @@ export function useSingleCoinMarketData( supportedCounterCurrencies, } = useContext(MarketDataContext); - const [state, setState] = useState({ - selectedCoinData: undefined, + return { selectedCurrency, + selectedCoinData, + selectCurrency, chartRequestParams, loading, loadingChart, @@ -410,33 +413,5 @@ export function useSingleCoinMarketData( refreshChart, setCounterCurrency, supportedCounterCurrencies, - }); - - useEffect(() => { - if (marketData) - setState((s) => ({ - ...s, - selectedCoinData: - marketData.find(({ id }) => id === currencyId) || s.selectedCoinData, - selectedCurrency, - chartRequestParams, - loading, - loadingChart, - error, - counterCurrency, - supportedCounterCurrencies, - })); - }, [ - marketData, - currencyId, - selectedCurrency, - chartRequestParams, - loading, - loadingChart, - error, - counterCurrency, - supportedCounterCurrencies, - ]); - - return state; + }; } From 08445df9247a00e0f8aa89b0f9f1d6fec60ef561 Mon Sep 17 00:00:00 2001 From: Hakim <59644786+haammar-ledger@users.noreply.github.com> Date: Tue, 29 Mar 2022 14:16:32 +0200 Subject: [PATCH 2/3] LIVE-1157 New scan accounts mode (#1747) * New scanAccounts mode allowing to fetch addresses * Adapt to makeScanAccounts new signature * Extend device check to seedIdentifier in addition to address * (bonus) better signature for makeSync * Replace Array with string[] Co-authored-by: @greweb * Generalize the concept of IterateResult (#1777) * Generalize the concept of IterateResult * comment * Update src/bridge/jsHelpers.ts Co-authored-by: Hakim <59644786+haammar-ledger@users.noreply.github.com> * Update src/bridge/jsHelpers.ts Co-authored-by: Hakim <59644786+haammar-ledger@users.noreply.github.com> Co-authored-by: Hakim <59644786+haammar-ledger@users.noreply.github.com> * Update cosmos-js integration * lint * Fix merge issue Co-authored-by: @greweb --- src/bridge/jsHelpers.ts | 198 +++++++++++------- src/families/algorand/js-synchronization.ts | 8 +- src/families/bitcoin/js-synchronisation.ts | 7 +- src/families/celo/js-synchronisation.ts | 9 +- src/families/cosmos/bridge/js.ts | 9 +- src/families/cosmos/js-synchronisation.ts | 14 +- src/families/crypto_org/js-synchronisation.ts | 7 +- src/families/elrond/js-synchronisation.ts | 7 +- src/families/ethereum/bridge/js.ts | 4 +- src/families/filecoin/bridge/account.ts | 2 +- src/families/filecoin/bridge/currency.ts | 2 +- src/families/neo/bridge/js.ts | 4 +- src/families/polkadot/js-synchronisation.ts | 8 +- src/families/solana/bridge/bridge.ts | 4 +- src/families/stellar/js-synchronization.ts | 9 +- src/families/tezos/bridge/js.ts | 4 +- src/families/tron/bridge/js.ts | 4 +- src/hw/actions/app.ts | 3 +- 18 files changed, 169 insertions(+), 134 deletions(-) diff --git a/src/bridge/jsHelpers.ts b/src/bridge/jsHelpers.ts index d06e3b83b5..53020d3d37 100644 --- a/src/bridge/jsHelpers.ts +++ b/src/bridge/jsHelpers.ts @@ -42,6 +42,22 @@ import type { Result, GetAddressOptions } from "../hw/getAddress/types"; import { open, close } from "../hw"; import { withDevice } from "../hw/deviceAccess"; +// Customize the way to iterate on the keychain derivation +type IterateResult = ({ + transport: Transport, + index: number, + derivationsCache: Object, + derivationScheme: string, + derivationMode: DerivationMode, + currency: CryptoCurrency, +}) => Promise; + +export type IterateResultBuilder = ({ + result: Result, // derivation on the "root" of the derivation + derivationMode: DerivationMode, // identify the current derivation scheme + derivationScheme: string, +}) => Promise; + export type GetAccountShapeArg0 = { currency: CryptoCurrency; address: string; @@ -151,10 +167,13 @@ export const mergeNfts = (oldNfts: NFT[], newNfts: NFT[]): NFT[] => { }; export const makeSync = - ( - getAccountShape: GetAccountShape, - postSync: (initial: Account, synced: Account) => Account = (_, a) => a - ): AccountBridge["sync"] => + ({ + getAccountShape, + postSync = (_, a) => a, + }: { + getAccountShape: GetAccountShape; + postSync?: (initial: Account, synced: Account) => Account; + }): AccountBridge["sync"] => (initial, syncConfig): Observable => Observable.create((o) => { async function main() { @@ -217,13 +236,45 @@ export const makeSync = main(); }); +const iterateResultWithAddressDerivation: IterateResult = async ({ + transport, + index, + derivationsCache, + derivationScheme, + derivationMode, + currency, +}) => { + let res; + const freshAddressPath = runDerivationScheme(derivationScheme, currency, { + account: index, + }); + res = derivationsCache[freshAddressPath]; + if (!res) { + res = await getAddress(transport, { + currency, + path: freshAddressPath, + derivationMode, + }); + derivationsCache[freshAddressPath] = res; + } + return res; +}; + +const defaultIterateResultBuilder = () => + Promise.resolve(iterateResultWithAddressDerivation); + export const makeScanAccounts = - ( - getAccountShape: GetAccountShape, + ({ + getAccountShape, + buildIterateResult = defaultIterateResultBuilder, + getAddressFn, + }: { + getAccountShape: GetAccountShape; + buildIterateResult?: IterateResultBuilder; getAddressFn?: ( transport: Transport - ) => (opts: GetAddressOptions) => Promise - ): CurrencyBridge["scanAccounts"] => + ) => (opts: GetAddressOptions) => Promise; + }): CurrencyBridge["scanAccounts"] => ({ currency, deviceId, syncConfig }): Observable => Observable.create((o) => { let finished = false; @@ -234,17 +285,17 @@ export const makeScanAccounts = const derivationsCache = {}; - // in future ideally what we want is: - // return mergeMap(addressesObservable, address => fetchAccount(address)) async function stepAccount( index, - { address, path: freshAddressPath, ...rest }, + res: Result, derivationMode, seedIdentifier, transport ): Promise { if (finished) return; + const { address, path: freshAddressPath, ...rest } = res; + const accountShape: Partial = await getAccountShape( { transport, @@ -313,6 +364,51 @@ export const makeScanAccounts = account.used = !isAccountEmpty(account); } + // Bitcoin needs to compute the freshAddressPath itself, + // so we update it afterwards + if (account?.freshAddressPath) { + res.address = account.freshAddress; + derivationsCache[account.freshAddressPath] = res; + } + + log("scanAccounts", "derivationsCache", res); + + log( + "scanAccounts", + `scanning ${currency.id} at ${freshAddressPath}: ${ + res.address + } resulted of ${ + account + ? `Account with ${account.operations.length} txs` + : "no account" + }` + ); + if (!account) return; + account.name = !account.used + ? getNewAccountPlaceholderName({ + currency, + index, + derivationMode, + }) + : getAccountPlaceholderName({ + currency, + index, + derivationMode, + }); + + const showNewAccount = shouldShowNewAccount(currency, derivationMode); + + if (account.used || showNewAccount) { + log( + "debug", + `Emit 'discovered' event for a new account found. AccountUsed: ${account.used} - showNewAccount: ${showNewAccount}` + ); + o.next({ + type: "discovered", + account, + }); + } + return account; } @@ -334,7 +430,7 @@ export const makeScanAccounts = "scanAccounts", `scanning ${currency.id} on derivationMode=${derivationMode}` ); - let result = derivationsCache[path]; + let result: Result = derivationsCache[path]; if (!result) { try { @@ -343,6 +439,7 @@ export const makeScanAccounts = path, derivationMode, }); + derivationsCache[path] = result; } catch (e) { if (e instanceof UnsupportedDerivation) { @@ -365,10 +462,7 @@ export const makeScanAccounts = derivationMode, currency, }); - const showNewAccount = shouldShowNewAccount( - currency, - derivationMode - ); + const stopAt = isIterableDerivationMode(derivationMode) ? 255 : 1; const startsAt = getDerivationModeStartsAt(derivationMode); @@ -377,6 +471,12 @@ export const makeScanAccounts = `start scanning account process. MandatoryEmptyAccountSkip ${mandatoryEmptyAccountSkip} / StartsAt: ${startsAt} - StopAt: ${stopAt}` ); + const iterateResult = await buildIterateResult({ + result, + derivationMode, + derivationScheme, + }); + for (let index = startsAt; index < stopAt; index++) { log("debug", `start to scan a new account. Index: ${index}`); @@ -386,23 +486,17 @@ export const makeScanAccounts = } if (!derivationModeSupportsIndex(derivationMode, index)) continue; - const freshAddressPath = runDerivationScheme( + + const res = await iterateResult({ + transport, + index, + derivationsCache, + derivationMode, derivationScheme, currency, - { - account: index, - } - ); - let res = derivationsCache[freshAddressPath]; + }); - if (!res) { - res = await getAddress(transport, { - currency, - path: freshAddressPath, - derivationMode, - }); - derivationsCache[freshAddressPath] = res; - } + if (!res) break; const account = await stepAccount( index, @@ -411,54 +505,14 @@ export const makeScanAccounts = seedIdentifier, transport ); - // Bitcoin needs to compute the freshAddressPath itself, - // so we update it afterwards - if (account?.freshAddressPath) { - res.address = account.freshAddress; - derivationsCache[account.freshAddressPath] = res; - } - log("scanAccounts", "derivationsCache", res); - - log( - "scanAccounts", - `scanning ${currency.id} at ${freshAddressPath}: ${ - res.address - } resulted of ${ - account - ? `Account with ${account.operations.length} txs` - : "no account" - }` - ); - if (!account) return; - account.name = !account.used - ? getNewAccountPlaceholderName({ - currency, - index, - derivationMode, - }) - : getAccountPlaceholderName({ - currency, - index, - derivationMode, - }); - - if (account.used || showNewAccount) { - log( - "debug", - `Emit 'discovered' event for a new account found. AccountUsed: ${account.used} - showNewAccount: ${showNewAccount}` - ); - o.next({ - type: "discovered", - account, - }); - } - if (!account.used) { + if (account && !account.used) { if (emptyCount >= mandatoryEmptyAccountSkip) break; emptyCount++; } } } + // } o.complete(); } catch (e) { diff --git a/src/families/algorand/js-synchronization.ts b/src/families/algorand/js-synchronization.ts index dbda6e803d..87ff839148 100644 --- a/src/families/algorand/js-synchronization.ts +++ b/src/families/algorand/js-synchronization.ts @@ -426,9 +426,5 @@ async function buildSubAccounts({ return tokenAccounts; } -const postSync = (_initial: Account, parent: Account) => { - return parent; -}; - -export const scanAccounts = makeScanAccounts(getAccountShape); -export const sync = makeSync(getAccountShape, postSync); +export const scanAccounts = makeScanAccounts({ getAccountShape }); +export const sync = makeSync({ getAccountShape }); diff --git a/src/families/bitcoin/js-synchronisation.ts b/src/families/bitcoin/js-synchronisation.ts index 54c8fd3ead..4de338bcf9 100644 --- a/src/families/bitcoin/js-synchronisation.ts +++ b/src/families/bitcoin/js-synchronisation.ts @@ -408,5 +408,8 @@ const getAddressFn = (transport) => { return (opts) => getAddressWithBtcInstance(transport, btc, opts); }; -export const scanAccounts = makeScanAccounts(getAccountShape, getAddressFn); -export const sync = makeSync(getAccountShape, postSync); +export const scanAccounts = makeScanAccounts({ + getAccountShape, + getAddressFn, +}); +export const sync = makeSync({ getAccountShape, postSync }); diff --git a/src/families/celo/js-synchronisation.ts b/src/families/celo/js-synchronisation.ts index a633f314a3..302bbba406 100644 --- a/src/families/celo/js-synchronisation.ts +++ b/src/families/celo/js-synchronisation.ts @@ -1,4 +1,3 @@ -import type { Account } from "../../types"; import { encodeAccountId } from "../../account"; import type { GetAccountShape } from "../../bridge/jsHelpers"; import { makeSync, makeScanAccounts, mergeOps } from "../../bridge/jsHelpers"; @@ -32,9 +31,5 @@ const getAccountShape: GetAccountShape = async (info) => { return { ...shape, operations }; }; -const postSync = (_initial: Account, parent: Account) => { - return parent; -}; - -export const scanAccounts = makeScanAccounts(getAccountShape); -export const sync = makeSync(getAccountShape, postSync); +export const scanAccounts = makeScanAccounts({ getAccountShape }); +export const sync = makeSync({ getAccountShape }); diff --git a/src/families/cosmos/bridge/js.ts b/src/families/cosmos/bridge/js.ts index 022199942f..4223fb5b91 100644 --- a/src/families/cosmos/bridge/js.ts +++ b/src/families/cosmos/bridge/js.ts @@ -3,15 +3,12 @@ import estimateMaxSpendable from "../js-estimateMaxSpendable"; import getTransactionStatus from "../js-getTransactionStatus"; import prepareTransaction from "../js-prepareTransaction"; import signOperation from "../js-signOperation"; -import { sync, getAccountShape } from "../js-synchronisation"; +import { sync, scanAccounts } from "../js-synchronisation"; import updateTransaction from "../js-updateTransaction"; import { AccountBridge, CurrencyBridge, CryptoCurrency } from "../../../types"; import type { CosmosValidatorItem, Transaction } from "../types"; import { getValidators, hydrateValidators } from "../validators"; -import { - makeAccountBridgeReceive, - makeScanAccounts, -} from "../../../bridge/jsHelpers"; +import { makeAccountBridgeReceive } from "../../../bridge/jsHelpers"; import { broadcast } from "../api/Cosmos"; import { asSafeCosmosPreloadData, @@ -47,7 +44,7 @@ const currencyBridge: CurrencyBridge = { hydrateValidators(validators); setCosmosPreloadData(asSafeCosmosPreloadData(data)); }, - scanAccounts: makeScanAccounts(getAccountShape), + scanAccounts, }; const accountBridge: AccountBridge = { diff --git a/src/families/cosmos/js-synchronisation.ts b/src/families/cosmos/js-synchronisation.ts index a9491b52ca..b91c18a04e 100644 --- a/src/families/cosmos/js-synchronisation.ts +++ b/src/families/cosmos/js-synchronisation.ts @@ -1,6 +1,11 @@ -import { Account, Operation, OperationType } from "../../types"; +import { Operation, OperationType } from "../../types"; import { BigNumber } from "bignumber.js"; -import { makeSync, GetAccountShape, mergeOps } from "../../bridge/jsHelpers"; +import { + makeSync, + makeScanAccounts, + GetAccountShape, + mergeOps, +} from "../../bridge/jsHelpers"; import { encodeAccountId } from "../../account"; import { getAccountInfo } from "./api/Cosmos"; import { pubkeyToAddress, decodeBech32Pubkey } from "@cosmjs/amino"; @@ -153,8 +158,6 @@ const txToOps = (info: any, id: string, txs: any): Operation[] => { return ops; }; -const postSync = (initial: Account, parent: Account) => parent; - export const getAccountShape: GetAccountShape = async (info) => { const { address, currency, derivationMode, initialAccount } = info; let xpubOrAddress = address; @@ -235,4 +238,5 @@ export const getAccountShape: GetAccountShape = async (info) => { return { ...shape, operations }; }; -export const sync = makeSync(getAccountShape, postSync); +export const scanAccounts = makeScanAccounts({ getAccountShape }); +export const sync = makeSync({ getAccountShape }); diff --git a/src/families/crypto_org/js-synchronisation.ts b/src/families/crypto_org/js-synchronisation.ts index 0519c480e6..27dac77ed6 100644 --- a/src/families/crypto_org/js-synchronisation.ts +++ b/src/families/crypto_org/js-synchronisation.ts @@ -1,4 +1,3 @@ -import type { Account } from "../../types"; import { encodeAccountId } from "../../account"; import type { GetAccountShape } from "../../bridge/jsHelpers"; import { makeSync, makeScanAccounts, mergeOps } from "../../bridge/jsHelpers"; @@ -59,7 +58,5 @@ const getAccountShape: GetAccountShape = async (info) => { return { ...shape, operations }; }; -const postSync = (initial: Account, parent: Account) => parent; - -export const scanAccounts = makeScanAccounts(getAccountShape); -export const sync = makeSync(getAccountShape, postSync); +export const scanAccounts = makeScanAccounts({ getAccountShape }); +export const sync = makeSync({ getAccountShape }); diff --git a/src/families/elrond/js-synchronisation.ts b/src/families/elrond/js-synchronisation.ts index 5fdd19a53e..0189f4e6a4 100644 --- a/src/families/elrond/js-synchronisation.ts +++ b/src/families/elrond/js-synchronisation.ts @@ -1,4 +1,3 @@ -import type { Account } from "../../types"; import { encodeAccountId } from "../../account"; import type { GetAccountShape } from "../../bridge/jsHelpers"; import { makeSync, makeScanAccounts, mergeOps } from "../../bridge/jsHelpers"; @@ -36,7 +35,5 @@ const getAccountShape: GetAccountShape = async (info) => { return { ...shape, operations }; }; -const postSync = (initial: Account, parent: Account) => parent; - -export const scanAccounts = makeScanAccounts(getAccountShape); -export const sync = makeSync(getAccountShape, postSync); +export const scanAccounts = makeScanAccounts({ getAccountShape }); +export const sync = makeSync({ getAccountShape }); diff --git a/src/families/ethereum/bridge/js.ts b/src/families/ethereum/bridge/js.ts index 601a772ec7..6a225e59c3 100644 --- a/src/families/ethereum/bridge/js.ts +++ b/src/families/ethereum/bridge/js.ts @@ -45,8 +45,8 @@ const broadcast = async ({ return patchOperationWithHash(operation, hash); }; -const scanAccounts = makeScanAccounts(getAccountShape); -const sync = makeSync(getAccountShape, postSyncPatch); +const scanAccounts = makeScanAccounts({ getAccountShape }); +const sync = makeSync({ getAccountShape, postSync: postSyncPatch }); const createTransaction = (): Transaction => ({ family: "ethereum", diff --git a/src/families/filecoin/bridge/account.ts b/src/families/filecoin/bridge/account.ts index f5b53cecd9..858e30e8a3 100644 --- a/src/families/filecoin/bridge/account.ts +++ b/src/families/filecoin/bridge/account.ts @@ -173,7 +173,7 @@ const prepareTransaction = async ( return t; }; -const sync = makeSync(getAccountShape); +const sync = makeSync({ getAccountShape }); const broadcast: BroadcastFnSignature = async ({ signedOperation: { operation, signature }, diff --git a/src/families/filecoin/bridge/currency.ts b/src/families/filecoin/bridge/currency.ts index 44aeb97648..86bddd86b2 100644 --- a/src/families/filecoin/bridge/currency.ts +++ b/src/families/filecoin/bridge/currency.ts @@ -2,7 +2,7 @@ import { makeScanAccounts } from "../../../bridge/jsHelpers"; import { getAccountShape } from "./utils/utils"; import { CurrencyBridge } from "../../../types"; -const scanAccounts = makeScanAccounts(getAccountShape); +const scanAccounts = makeScanAccounts({ getAccountShape }); export const currencyBridge: CurrencyBridge = { preload: () => Promise.resolve({}), diff --git a/src/families/neo/bridge/js.ts b/src/families/neo/bridge/js.ts index 5bd4dcd5ae..9d03b63181 100644 --- a/src/families/neo/bridge/js.ts +++ b/src/families/neo/bridge/js.ts @@ -132,8 +132,8 @@ const getAccountShape = async (info) => { }; }; -const scanAccounts = makeScanAccounts(getAccountShape); -const sync = makeSync(getAccountShape); +const scanAccounts = makeScanAccounts({ getAccountShape }); +const sync = makeSync({ getAccountShape }); const currencyBridge: CurrencyBridge = { preload: () => Promise.resolve({}), hydrate: () => {}, diff --git a/src/families/polkadot/js-synchronisation.ts b/src/families/polkadot/js-synchronisation.ts index 39ac4e6169..47f62677fa 100644 --- a/src/families/polkadot/js-synchronisation.ts +++ b/src/families/polkadot/js-synchronisation.ts @@ -54,9 +54,5 @@ const getAccountShape: GetAccountShape = async (info) => { return { ...shape, operations } as Partial; }; -const postSync = (_initial: Account, parent: Account) => { - return parent; -}; - -export const scanAccounts = makeScanAccounts(getAccountShape); -export const sync = makeSync(getAccountShape, postSync); +export const scanAccounts = makeScanAccounts({ getAccountShape }); +export const sync = makeSync({ getAccountShape }); diff --git a/src/families/solana/bridge/bridge.ts b/src/families/solana/bridge/bridge.ts index f58204c603..aa9a28f4a9 100644 --- a/src/families/solana/bridge/bridge.ts +++ b/src/families/solana/bridge/bridge.ts @@ -69,8 +69,8 @@ function makeSyncAndScan(getChainAPI: (config: Config) => Promise) { return getAccountShapeWithAPI(info, chainAPI); }; return { - sync: makeSyncHelper(getAccountShape), - scan: makeScanHelper(getAccountShape), + sync: makeSyncHelper({ getAccountShape }), + scan: makeScanHelper({ getAccountShape }), }; } diff --git a/src/families/stellar/js-synchronization.ts b/src/families/stellar/js-synchronization.ts index 9c4609f075..37e78661b5 100644 --- a/src/families/stellar/js-synchronization.ts +++ b/src/families/stellar/js-synchronization.ts @@ -1,4 +1,3 @@ -import type { Account } from "../../types"; import { encodeAccountId } from "../../account"; import type { GetAccountShape } from "../../bridge/jsHelpers"; import { makeScanAccounts, makeSync, mergeOps } from "../../bridge/jsHelpers"; @@ -32,9 +31,5 @@ const getAccountShape: GetAccountShape = async (info) => { return { ...shape, operations }; }; -const postSync = (initial: Account, parent: Account) => { - return parent; -}; - -export const sync = makeSync(getAccountShape, postSync); -export const scanAccounts = makeScanAccounts(getAccountShape); +export const sync = makeSync({ getAccountShape }); +export const scanAccounts = makeScanAccounts({ getAccountShape }); diff --git a/src/families/tezos/bridge/js.ts b/src/families/tezos/bridge/js.ts index 153112e434..76159807a7 100644 --- a/src/families/tezos/bridge/js.ts +++ b/src/families/tezos/bridge/js.ts @@ -344,9 +344,9 @@ const broadcast = async ({ signedOperation: { operation, signature } }) => { return patchOperationWithHash(operation, hash); }; -const scanAccounts = makeScanAccounts(getAccountShape); +const scanAccounts = makeScanAccounts({ getAccountShape }); -const sync = makeSync(getAccountShape); +const sync = makeSync({ getAccountShape }); const getPreloadStrategy = (_currency) => ({ preloadMaxAge: 30 * 1000, diff --git a/src/families/tron/bridge/js.ts b/src/families/tron/bridge/js.ts index b4d7eb07d8..1baf993173 100644 --- a/src/families/tron/bridge/js.ts +++ b/src/families/tron/bridge/js.ts @@ -466,7 +466,7 @@ const getAccountShape = async (info: GetAccountShapeArg0, syncConfig) => { }; }; -const scanAccounts = makeScanAccounts(getAccountShape); +const scanAccounts = makeScanAccounts({ getAccountShape }); // the balance does not update straightaway so we should ignore recent operations if they are in pending for a bit const preferPendingOperationsUntilBlockValidation = 35; @@ -490,7 +490,7 @@ const postSync = (initial: Account, parent: Account): Account => { return parent; }; -const sync = makeSync(getAccountShape, postSync); +const sync = makeSync({ getAccountShape, postSync }); const currencyBridge: CurrencyBridge = { preload: async () => { diff --git a/src/hw/actions/app.ts b/src/hw/actions/app.ts index 3b3ed6986c..0daf77375d 100644 --- a/src/hw/actions/app.ts +++ b/src/hw/actions/app.ts @@ -634,7 +634,8 @@ export const createAction = ( ...state, inWrongDeviceForAccount: state.derivation && appRequest.account - ? state.derivation.address !== appRequest.account.freshAddress + ? state.derivation.address !== appRequest.account.freshAddress && + state.derivation.address !== appRequest.account.seedIdentifier // Use-case added for Hedera ? { accountName: getAccountName(appRequest.account), } From 81f0a256d84aae86131af240ff6d202c6394e7ec Mon Sep 17 00:00:00 2001 From: LFBarreto Date: Tue, 29 Mar 2022 14:34:29 +0200 Subject: [PATCH 3/3] v21.36.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 539c5908dc..183d7e1cd5 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "type": "git", "url": "https://github.com/LedgerHQ/ledger-live-common" }, - "version": "21.35.0", + "version": "21.36.0", "main": "lib/index.js", "types": "lib/index.d.ts", "license": "Apache-2.0",