From 61c9531946aa608aaf5f1eeb522f0e81405deeb5 Mon Sep 17 00:00:00 2001 From: tomasklim Date: Tue, 6 Aug 2024 14:11:10 +0200 Subject: [PATCH] feat(connect): use network shortcut not just symbol for identification --- packages/blockchain-link-types/src/blockbook-api.ts | 1 + packages/blockchain-link-types/src/common.ts | 1 + packages/blockchain-link-utils/src/blockbook.ts | 1 + packages/blockchain-link-utils/src/ripple.ts | 1 + .../blockchain-link/src/workers/blockfrost/index.ts | 1 + .../src/workers/electrum/methods/getInfo.ts | 1 + packages/blockchain-link/src/workers/solana/index.ts | 1 + packages/connect/e2e/__wscache__/blockbook.js | 1 + packages/connect/src/backend/Blockchain.ts | 12 ++++++++++-- packages/suite-web/e2e/fixtures/eth-account.ts | 1 + packages/suite-web/e2e/fixtures/send-form-doge.ts | 1 + .../e2e/fixtures/send-form-ltc-mimble-wimble.ts | 1 + 12 files changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/blockchain-link-types/src/blockbook-api.ts b/packages/blockchain-link-types/src/blockbook-api.ts index 2debd21191f1..788a69f8fd7f 100644 --- a/packages/blockchain-link-types/src/blockbook-api.ts +++ b/packages/blockchain-link-types/src/blockbook-api.ts @@ -362,6 +362,7 @@ export interface WsInfoRes { bestHeight: number; bestHash: string; block0Hash: string; + network: string; testnet: boolean; backend: WsBackendInfo; } diff --git a/packages/blockchain-link-types/src/common.ts b/packages/blockchain-link-types/src/common.ts index 75004777e2cf..f9aac4ca295c 100644 --- a/packages/blockchain-link-types/src/common.ts +++ b/packages/blockchain-link-types/src/common.ts @@ -51,6 +51,7 @@ export interface ServerInfo { blockHeight: number; blockHash: string; consensusBranchId?: number; // zcash current branch id + network: string; } export type TokenStandard = 'ERC20' | 'ERC1155' | 'ERC721' | 'SPL' | 'BEP20'; diff --git a/packages/blockchain-link-utils/src/blockbook.ts b/packages/blockchain-link-utils/src/blockbook.ts index 470ffbd9cea4..afec4c9f9dee 100644 --- a/packages/blockchain-link-utils/src/blockbook.ts +++ b/packages/blockchain-link-utils/src/blockbook.ts @@ -22,6 +22,7 @@ import { Addresses, filterTargets, enhanceVinVout, sumVinVout, transformTarget } export const transformServerInfo = (payload: ServerInfo) => ({ name: payload.name, shortcut: payload.shortcut, + network: payload.network || payload.shortcut, // for backwards Blockbook compatibility testnet: payload.testnet, version: payload.version, decimals: payload.decimals, diff --git a/packages/blockchain-link-utils/src/ripple.ts b/packages/blockchain-link-utils/src/ripple.ts index 4de17fbb07ec..2129f3cbb081 100644 --- a/packages/blockchain-link-utils/src/ripple.ts +++ b/packages/blockchain-link-utils/src/ripple.ts @@ -4,6 +4,7 @@ import type { Transaction } from '@trezor/blockchain-link-types'; export const transformServerInfo = (payload: any) => ({ name: 'Ripple', shortcut: 'xrp', + network: 'xrp', testnet: false, version: payload.buildVersion, decimals: 6, diff --git a/packages/blockchain-link/src/workers/blockfrost/index.ts b/packages/blockchain-link/src/workers/blockfrost/index.ts index 7b6f2b5ca69d..b240f4722497 100644 --- a/packages/blockchain-link/src/workers/blockfrost/index.ts +++ b/packages/blockchain-link/src/workers/blockfrost/index.ts @@ -27,6 +27,7 @@ const getInfo = async (request: Request) => { type: RESPONSES.GET_INFO, payload: { url: api.options.url, + network: info.shortcut, ...info, }, } as const; diff --git a/packages/blockchain-link/src/workers/electrum/methods/getInfo.ts b/packages/blockchain-link/src/workers/electrum/methods/getInfo.ts index 7b553cc8d6c2..16fa84891cf5 100644 --- a/packages/blockchain-link/src/workers/electrum/methods/getInfo.ts +++ b/packages/blockchain-link/src/workers/electrum/methods/getInfo.ts @@ -19,6 +19,7 @@ const getInfo: Api = client => { blockHash: blockheaderToBlockhash(hex), name: 'Bitcoin', shortcut: coin, + network: coin, testnet: coin === 'REGTEST', decimals: 8, }); diff --git a/packages/blockchain-link/src/workers/solana/index.ts b/packages/blockchain-link/src/workers/solana/index.ts index b44e9ca02f37..ffb99b00e313 100644 --- a/packages/blockchain-link/src/workers/solana/index.ts +++ b/packages/blockchain-link/src/workers/solana/index.ts @@ -390,6 +390,7 @@ const getInfo = async (request: Request, isTestnet: boolea blockHeight: Number(blockHeight), blockHash, shortcut: isTestnet ? 'dsol' : 'sol', + network: isTestnet ? 'dsol' : 'sol', url: api.clusterUrl, name: 'Solana', version: (await api.rpc.getVersion().send())['solana-core'], diff --git a/packages/connect/e2e/__wscache__/blockbook.js b/packages/connect/e2e/__wscache__/blockbook.js index de6ace0ec33b..b1892307106d 100644 --- a/packages/connect/e2e/__wscache__/blockbook.js +++ b/packages/connect/e2e/__wscache__/blockbook.js @@ -10,6 +10,7 @@ const blockbookFixtures = { bestHeight: 7000000, // high block to make sure that utxos have enough confirmations (composeTransaction test) bestHash: '', block0Hash: '', + network: params.shortcut, testnet: true, version: '0.0.0-mocked', }, diff --git a/packages/connect/src/backend/Blockchain.ts b/packages/connect/src/backend/Blockchain.ts index 6ce17fff5256..348313dc77b9 100644 --- a/packages/connect/src/backend/Blockchain.ts +++ b/packages/connect/src/backend/Blockchain.ts @@ -133,9 +133,17 @@ export class Blockchain { this.serverInfo = info; const trezorShortcut = getNormalizedTrezorShortcut(this.coinInfo.shortcut); - const backendShortcut = this.serverInfo.shortcut; - if (trezorShortcut.toLowerCase() !== backendShortcut.toLowerCase()) { + // TODO: remove of change + // const backendShortcut = this.serverInfo.shortcut; + // if (trezorShortcut.toLowerCase() !== backendShortcut.toLowerCase()) { + + if ( + (this.coinInfo.type === 'ethereum' && + info.network.toLowerCase() !== this.coinInfo.chain?.toLowerCase()) || + (this.coinInfo.type !== 'ethereum' && + info.network.toLowerCase() !== trezorShortcut.toLowerCase()) + ) { throw ERRORS.TypedError('Backend_Invalid'); } diff --git a/packages/suite-web/e2e/fixtures/eth-account.ts b/packages/suite-web/e2e/fixtures/eth-account.ts index ae51aae5757f..bbe00cab4f6a 100644 --- a/packages/suite-web/e2e/fixtures/eth-account.ts +++ b/packages/suite-web/e2e/fixtures/eth-account.ts @@ -103,6 +103,7 @@ export const fixtures = [ bestHeight: 19960825, bestHash: '0x8339e411cd2f62b9493e36c444f7bd11ec716ceaa94f491e9726233d22abc024', block0Hash: '0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3', + network: 'ETH', testnet: false, backend: { version: 'erigon/2.59.3/linux-amd64/go1.21.6', diff --git a/packages/suite-web/e2e/fixtures/send-form-doge.ts b/packages/suite-web/e2e/fixtures/send-form-doge.ts index 0c94e214f539..e17e33b8ac80 100644 --- a/packages/suite-web/e2e/fixtures/send-form-doge.ts +++ b/packages/suite-web/e2e/fixtures/send-form-doge.ts @@ -131,6 +131,7 @@ export const fixtures = [ bestHeight: 4484566, bestHash: '38fbb073e7eb4bfac9ed485dd0b3212247fb2a3d8b509dc9738c01a86ede33b3', block0Hash: '1a91e3dace36e2be3bf030a65679fe821aa1d6ef92e7c9902eb318182c355691', + network: 'DOGE', testnet: false, backend: { version: '1140600', subversion: '/Shibetoshi:1.14.6/' }, }, diff --git a/packages/suite-web/e2e/fixtures/send-form-ltc-mimble-wimble.ts b/packages/suite-web/e2e/fixtures/send-form-ltc-mimble-wimble.ts index c1c86db86711..cd7ac4240613 100644 --- a/packages/suite-web/e2e/fixtures/send-form-ltc-mimble-wimble.ts +++ b/packages/suite-web/e2e/fixtures/send-form-ltc-mimble-wimble.ts @@ -95,6 +95,7 @@ export const fixtures = [ bestHeight: 2373436, bestHash: '2c1bc2b99f8a4447a57dfc7b694b9c82bff1b3af7cce8ff151df01238dc07c8b', block0Hash: '12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2', + network: 'LTC', testnet: false, backend: { version: '210201', subversion: '/LitecoinCore:0.21.2.1/' }, },