diff --git a/packages/blockchain-link/src/workers/solana/index.ts b/packages/blockchain-link/src/workers/solana/index.ts index 16aa71d57fb..53f691576fe 100644 --- a/packages/blockchain-link/src/workers/solana/index.ts +++ b/packages/blockchain-link/src/workers/solana/index.ts @@ -266,14 +266,11 @@ const getAccountInfo = async (request: Request) => } as const; }; -const getInfo = async (request: Request) => { +const getInfo = async (request: Request, isTestnet: boolean) => { const api = await request.connect(); const { blockhash: blockHash, lastValidBlockHeight: blockHeight } = await api.getLatestBlockhash('finalized'); - const isTestnet = - (await api.getGenesisHash()) !== '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d'; const serverInfo = { - // genesisHash is reliable identifier of the network, for mainnet the genesis hash is 5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d testnet: isTestnet, blockHeight, blockHash, @@ -517,12 +514,12 @@ const unsubscribe = (request: Request) => { } as const; }; -const onRequest = (request: Request) => { +const onRequest = (request: Request, isTestnet: boolean) => { switch (request.type) { case MESSAGES.GET_ACCOUNT_INFO: return getAccountInfo(request); case MESSAGES.GET_INFO: - return getInfo(request); + return getInfo(request, isTestnet); case MESSAGES.PUSH_TRANSACTION: return pushTransaction(request); case MESSAGES.ESTIMATE_FEE: @@ -542,6 +539,7 @@ class SolanaWorker extends BaseWorker { } private lazyTokens = createLazy(() => solanaUtils.getTokenMetadata()); + private isTestnet = false; async tryConnect(url: string): Promise { const api = new Connection(url, { @@ -551,7 +549,11 @@ class SolanaWorker extends BaseWorker { 'User-Agent': `Trezor Suite ${getSuiteVersion()}`, }, }); - await api.getLatestBlockhash('finalized'); + + // genesisHash is reliable identifier of the network, for mainnet the genesis hash is 5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d + this.isTestnet = + (await api.getGenesisHash()) !== '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d'; + this.post({ id: -1, type: RESPONSES.CONNECTED }); return Promise.resolve(api); @@ -570,7 +572,7 @@ class SolanaWorker extends BaseWorker { getTokenMetadata: this.lazyTokens.getOrInit, }; - const response = await onRequest(request); + const response = await onRequest(request, this.isTestnet); this.post({ id: event.data.id, ...response }); } catch (error) { this.errorResponse(event.data.id, error);