diff --git a/libs/coin-modules/coin-icon/src/api/index.ts b/libs/coin-modules/coin-icon/src/api/index.ts index e9f5b231e8da..15f7b6f09f0b 100644 --- a/libs/coin-modules/coin-icon/src/api/index.ts +++ b/libs/coin-modules/coin-icon/src/api/index.ts @@ -1,7 +1,6 @@ import network from "@ledgerhq/live-network/network"; import { BigNumber } from "bignumber.js"; import type { Operation, OperationType } from "@ledgerhq/types-live"; -import { getEnv } from "@ledgerhq/live-env"; import { encodeOperationId } from "@ledgerhq/coin-framework/operation"; import { CryptoCurrency } from "@ledgerhq/types-cryptoassets"; import { LIMIT } from "../constants"; @@ -10,6 +9,7 @@ import { AccountType, IconTransactionType } from "./api-type"; import { log } from "@ledgerhq/logs"; import { IconOperation } from "../types"; import querystring from "querystring"; +import { getCoinConfig } from "../config"; /** * Returns Testnet API URL if the current network is testnet @@ -17,9 +17,10 @@ import querystring from "querystring"; * @param {network} network */ function getApiUrl(network: CryptoCurrency): string { - let apiUrl = getEnv("ICON_INDEXER_ENDPOINT"); + const currencyConfig = getCoinConfig(); + let apiUrl = currencyConfig.infra.indexer; if (isTestnet(network)) { - apiUrl = getEnv("ICON_TESTNET_INDEXER_ENDPOINT"); + apiUrl = currencyConfig.infra.indexer_testnet; } return apiUrl; } diff --git a/libs/coin-modules/coin-icon/src/api/node.ts b/libs/coin-modules/coin-icon/src/api/node.ts index 87c72f42d323..af94031ccda4 100644 --- a/libs/coin-modules/coin-icon/src/api/node.ts +++ b/libs/coin-modules/coin-icon/src/api/node.ts @@ -2,12 +2,12 @@ import { BigNumber } from "bignumber.js"; import IconService from "icon-sdk-js"; import type { IcxTransaction, SignedTransaction } from "icon-sdk-js"; import { CryptoCurrency } from "@ledgerhq/types-cryptoassets"; -import { getEnv } from "@ledgerhq/live-env"; import { isTestnet } from "../logic"; import { GOVERNANCE_SCORE_ADDRESS, IISS_SCORE_ADDRESS } from "../constants"; import { IconAccount } from "../types"; import { SignedOperation } from "@ledgerhq/types-live"; import { IconDelegationType } from "./api-type"; +import { getCoinConfig } from "../config"; const { HttpProvider } = IconService; const { IconBuilder } = IconService; @@ -17,17 +17,19 @@ const { IconBuilder } = IconService; * @param {currency} currency */ export function getRpcUrl(currency: CryptoCurrency): string { - let rpcUrl = getEnv("ICON_NODE_ENDPOINT"); + const currencyConfig = getCoinConfig(); + let rpcUrl = currencyConfig.infra.node_endpoint; if (isTestnet(currency)) { - rpcUrl = getEnv("ICON_TESTNET_NODE_ENDPOINT"); + rpcUrl = currencyConfig.infra.node_testnet_endpoint; } return rpcUrl; } export function getDebugRpcUrl(currency: CryptoCurrency): string { - let rpcUrl = getEnv("ICON_DEBUG_ENDPOINT"); + const currencyConfig = getCoinConfig(); + let rpcUrl = currencyConfig.infra.debug_endpoint; if (isTestnet(currency)) { - rpcUrl = getEnv("ICON_TESTNET_DEBUG_ENDPOINT"); + rpcUrl = currencyConfig.infra.debug_testnet_endpoint; } return rpcUrl; } diff --git a/libs/coin-modules/coin-icon/src/bridge/index.ts b/libs/coin-modules/coin-icon/src/bridge/index.ts index 475e2105a9cb..9be540c8b278 100644 --- a/libs/coin-modules/coin-icon/src/bridge/index.ts +++ b/libs/coin-modules/coin-icon/src/bridge/index.ts @@ -6,6 +6,7 @@ import { makeSync, } from "@ledgerhq/coin-framework/bridge/jsHelpers"; import { SignerContext } from "@ledgerhq/coin-framework/signer"; +import { CoinConfig } from "@ledgerhq/coin-framework/config"; import type { AccountBridge, CurrencyBridge } from "@ledgerhq/types-live"; import resolver from "../hw-getAddress"; @@ -20,6 +21,7 @@ import { getAccountShape } from "../synchronization"; import { assignFromAccountRaw, assignToAccountRaw } from "../serialization"; import type { Transaction } from "../types"; import { IconSigner } from "../signer"; +import { IconCoinConfig, setCoinConfig } from "../config"; export function buildCurrencyBridge(signerContext: SignerContext): CurrencyBridge { const getAddress = resolver(signerContext); @@ -61,7 +63,9 @@ export function buildAccountBridge( }; } -export function createBridges(signerContext: SignerContext) { +export function createBridges(signerContext: SignerContext, coinConfig: CoinConfig,) { + setCoinConfig(coinConfig); + return { currencyBridge: buildCurrencyBridge(signerContext), accountBridge: buildAccountBridge(signerContext), diff --git a/libs/coin-modules/coin-icon/src/config.ts b/libs/coin-modules/coin-icon/src/config.ts new file mode 100644 index 000000000000..cae136181d14 --- /dev/null +++ b/libs/coin-modules/coin-icon/src/config.ts @@ -0,0 +1,29 @@ +import { CurrencyConfig, CoinConfig } from "@ledgerhq/coin-framework/config"; +import { MissingCoinConfig } from "@ledgerhq/coin-framework/errors"; + +export type IconConfig = { + infra: { + indexer: string; + indexer_testnet: string; + node_endpoint: string; + node_testnet_endpoint: string; + debug_endpoint: string; + debug_testnet_endpoint: string; + }; +}; + +export type IconCoinConfig = CurrencyConfig & IconConfig; + +let coinConfig: CoinConfig | undefined; + +export const setCoinConfig = (config: CoinConfig): void => { + coinConfig = config; +}; + +export const getCoinConfig = (): IconCoinConfig => { + if (!coinConfig) { + throw new MissingCoinConfig(); + } + + return coinConfig(); +}; diff --git a/libs/ledger-live-common/src/families/icon/setup.ts b/libs/ledger-live-common/src/families/icon/setup.ts index 568b06a32fc5..3de87b8fd9d7 100644 --- a/libs/ledger-live-common/src/families/icon/setup.ts +++ b/libs/ledger-live-common/src/families/icon/setup.ts @@ -9,12 +9,34 @@ import Transport from "@ledgerhq/hw-transport"; import type { Bridge } from "@ledgerhq/types-live"; import { CreateSigner, createResolver, executeWithSigner } from "../../bridge/setup"; import type { Resolver } from "../../hw/getAddress/types"; +import { IconCoinConfig } from "@ledgerhq/coin-icon/config"; +import { getEnv } from "@ledgerhq/live-env"; const createSigner: CreateSigner = (transport: Transport) => { return new Icon(transport); }; -const bridge: Bridge = createBridges(executeWithSigner(createSigner)); +const getCurrencyConfig = (): IconCoinConfig => { + return { + status: { + type: "active", + }, + infra: { + indexer: getEnv("ICON_INDEXER_ENDPOINT"), + indexer_testnet: getEnv("ICON_TESTNET_INDEXER_ENDPOINT"), + node_endpoint: getEnv("ICON_NODE_ENDPOINT"), + node_testnet_endpoint: getEnv("ICON_TESTNET_NODE_ENDPOINT"), + debug_endpoint: getEnv("ICON_DEBUG_ENDPOINT"), + debug_testnet_endpoint: getEnv("ICON_TESTNET_DEBUG_ENDPOINT"), + } + } + +}; + +const bridge: Bridge = createBridges( + executeWithSigner(createSigner), + getCurrencyConfig, +); const resolver: Resolver = createResolver(createSigner, iconResolver);