diff --git a/libs/coin-framework/src/config.ts b/libs/coin-framework/src/config.ts index d108a2de171b..7a86ba7a090d 100644 --- a/libs/coin-framework/src/config.ts +++ b/libs/coin-framework/src/config.ts @@ -1,3 +1,4 @@ +import { CryptoCurrency } from "@ledgerhq/types-cryptoassets"; import { MissingCoinConfig } from "./errors"; type ConfigStatus = @@ -21,7 +22,8 @@ export type CurrencyConfig = { [key: string]: unknown; }; -export type CoinConfig = () => T; +// export type CoinConfig = () => T; +export type CoinConfig = (currency?: CryptoCurrency) => T; function buildCoinConfig() { let coinConfig: CoinConfig | undefined; @@ -30,12 +32,12 @@ function buildCoinConfig() { coinConfig = config; }; - const getCoinConfig = (): T => { + const getCoinConfig = (currency?: CryptoCurrency): T => { if (!coinConfig) { throw new MissingCoinConfig(); } - return coinConfig(); + return coinConfig(currency); }; return { diff --git a/libs/coin-modules/coin-cosmos/src/bridge/index.ts b/libs/coin-modules/coin-cosmos/src/bridge/index.ts index 53c9e9e8f9b9..fc8e68946c52 100644 --- a/libs/coin-modules/coin-cosmos/src/bridge/index.ts +++ b/libs/coin-modules/coin-cosmos/src/bridge/index.ts @@ -9,7 +9,7 @@ import type { AccountBridge, CurrencyBridge } from "@ledgerhq/types-live"; import { CoinConfig } from "@ledgerhq/coin-framework/lib/config"; import { CosmosAPI } from "../api/Cosmos"; -import cosmosCoinConfig, { CosmosCoinConfig } from "../config"; +import cosmosCoinConfig, { CosmosCoinConfig, CosmosCoinConfigGetter } from "../config"; import { createTransaction } from "../createTransaction"; import { estimateMaxSpendable } from "../estimateMaxSpendable"; import getTransactionStatus from "../getTransactionStatus"; @@ -80,6 +80,7 @@ function buildAccountBridge( } export function createBridges(signerContext: SignerContext, coinConfig: CoinConfig) { +// export function createBridges(signerContext: SignerContext, coinConfig: CosmosCoinConfigGetter) { cosmosCoinConfig.setCoinConfig(coinConfig); return { currencyBridge: buildCurrencyBridge(signerContext), diff --git a/libs/coin-modules/coin-cosmos/src/bridge/preload.ts b/libs/coin-modules/coin-cosmos/src/bridge/preload.ts index f485f97d3caa..312aebc77c97 100644 --- a/libs/coin-modules/coin-cosmos/src/bridge/preload.ts +++ b/libs/coin-modules/coin-cosmos/src/bridge/preload.ts @@ -12,7 +12,7 @@ export const getPreloadStrategy = () => ({ }); export const preload = async (currency: CryptoCurrency) => { - const config = cosmosCoinConfig.getCoinConfig(); + const config = cosmosCoinConfig.getCoinConfig(currency); const cosmosValidatorsManager = new CosmosValidatorsManager(getCryptoCurrencyById(currency.id), { endPoint: (config as unknown as CosmosCurrencyConfig).lcd, }); diff --git a/libs/coin-modules/coin-cosmos/src/cli.ts b/libs/coin-modules/coin-cosmos/src/cli.ts index 40ca14617b01..d1ed789b58d7 100644 --- a/libs/coin-modules/coin-cosmos/src/cli.ts +++ b/libs/coin-modules/coin-cosmos/src/cli.ts @@ -1,14 +1,14 @@ -import { from, Observable } from "rxjs"; -import { map } from "rxjs/operators"; +import { BigNumber } from "bignumber.js"; import invariant from "invariant"; import flatMap from "lodash/flatMap"; import zipWith from "lodash/zipWith"; -import { BigNumber } from "bignumber.js"; -import { Transaction as CosmosTransaction } from "./types"; -import type { CosmosDelegationInfo } from "./types"; -import { AccountLike } from "@ledgerhq/types-live"; +import { from, Observable } from "rxjs"; +import { map } from "rxjs/operators"; import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/index"; +import { AccountLike } from "@ledgerhq/types-live"; import { CosmosValidatorsManager } from "./CosmosValidatorsManager"; +import type { CosmosDelegationInfo } from "./types"; +import { Transaction as CosmosTransaction } from "./types"; const options = [ { diff --git a/libs/coin-modules/coin-cosmos/src/config.ts b/libs/coin-modules/coin-cosmos/src/config.ts index ceebf80d9ba0..a89ab6dda605 100644 --- a/libs/coin-modules/coin-cosmos/src/config.ts +++ b/libs/coin-modules/coin-cosmos/src/config.ts @@ -167,6 +167,7 @@ import { CryptoCurrency } from "@ledgerhq/types-cryptoassets"; // export type CosmosCoinConfig = CurrencyConfig & CosmosConfig; // export type CoinConfig = (currency: CryptoCurrency) => CosmosCoinConfig; +export type CosmosCoinConfigGetter = (currency: CryptoCurrency) => CosmosCoinConfig; // export type CoinConfig = (currency: CryptoCurrency) => CosmosCoinConfig; // let coinConfig: CoinConfig | undefined; @@ -185,7 +186,7 @@ import { CryptoCurrency } from "@ledgerhq/types-cryptoassets"; // export { cosmosConfig }; -import buildConConfig, { type CurrencyConfig } from "@ledgerhq/coin-framework/config"; +import buildCoinConfig, { type CurrencyConfig } from "@ledgerhq/coin-framework/config"; // export type XrpConfig = { // node: string; @@ -196,7 +197,7 @@ export type CosmosCoinConfig = CurrencyConfig & CosmosConfig; // const coinConfig = buildConConfig(); // export const {setCoinConfig, getCoinConfig} = buildConConfig(); -const coinConfig = buildConConfig(); +const coinConfig = buildCoinConfig(); export default coinConfig; // export default coinConfig; diff --git a/libs/ledger-live-common/src/families/cosmos/setup.ts b/libs/ledger-live-common/src/families/cosmos/setup.ts index ae93629c0cd8..d7d43de1c270 100644 --- a/libs/ledger-live-common/src/families/cosmos/setup.ts +++ b/libs/ledger-live-common/src/families/cosmos/setup.ts @@ -24,13 +24,27 @@ const createSigner: CreateSigner = (transport: Transport) => { getAddress: hwCosmos.getAddress.bind(hwCosmos), }; }; -const getCurrencyConfig = (currency: CryptoCurrency): CosmosCoinConfig => { - return getCurrencyConfiguration(currency); -}; +// const getCurrencyConfig = (currency: CryptoCurrency): CosmosCoinConfig => { +// return getCurrencyConfiguration(currency); +// }; + +// const getCoinConfig = () => +// getCurrencyConfiguration(getCryptoCurrencyById("ripple")); + +// const getCoinConfig = (currency: CryptoCurrency) => +// getCurrencyConfiguration(currency); + +const getCurrencyConfig = (currency?: CryptoCurrency) => { + if (!currency) { + throw new Error("No currency provided"); + } + return getCurrencyConfiguration(currency); +}; const bridge: Bridge = createBridges( executeWithSigner(createSigner), getCurrencyConfig, + // getCoinConfig, ); const resolver: Resolver = createResolver(createSigner, cosmosResolver);