From 80e588b2226e94a953133eb0862fe9b7e39357c7 Mon Sep 17 00:00:00 2001 From: Trung-Tin Pham <60747384+AtelyPham@users.noreply.github.com> Date: Thu, 5 Oct 2023 16:37:56 +0700 Subject: [PATCH] fix: hotfix the response object --- .../faucet/src/components/ProcessingModal.tsx | 71 +++++++++---------- apps/faucet/src/types/index.ts | 17 +++-- .../src/chains/substrate/index.tsx | 39 +++++++--- 3 files changed, 75 insertions(+), 52 deletions(-) diff --git a/apps/faucet/src/components/ProcessingModal.tsx b/apps/faucet/src/components/ProcessingModal.tsx index 1fb7e7a8c8..166f4a2a9f 100644 --- a/apps/faucet/src/components/ProcessingModal.tsx +++ b/apps/faucet/src/components/ProcessingModal.tsx @@ -1,3 +1,4 @@ +import getExplorerURI from '@webb-tools/api-provider-environment/transaction/utils/getExplorerURI'; import { chainsConfig } from '@webb-tools/dapp-config/chains/chain-config'; import isValidUrl from '@webb-tools/dapp-types/utils/isValidUrl'; import { MetaMaskIcon, WalletLineIcon } from '@webb-tools/icons'; @@ -201,32 +202,32 @@ const MintTxLinkOrHash = (props: { if (FaucetError.isFaucetError(mintTokenResult)) return ''; - const { transactionHash, typedChainId, isSubstrate } = + const { hash, typedChainId, isSubstrate } = parseMintResult(mintTokenResult); const chain = chainsConfig[typedChainId]; if (!chain) { - alert(`Typed chain id ${typedChainId} is not in the chains config`); - return transactionHash; + console.warn( + `Typed chain id ${typedChainId} is not in the chains config` + ); + return hash; } - if (isSubstrate) { - return transactionHash; - } - - if (!chain.blockExplorers || !transactionHash) { - return transactionHash; + if (!chain.blockExplorers || !hash) { + return hash; } try { - return new URL( - `/tx/${transactionHash}`, - chain.blockExplorers.default.url + return getExplorerURI( + chain.blockExplorers.default.url, + hash, + 'tx', + isSubstrate ? 'polkadot' : 'web3' ).toString(); } catch (error) { console.error(error); - return transactionHash; + return hash; } }, [mintTokenResult]); @@ -276,31 +277,29 @@ const getSuccesMessage = () => { ); }; -const parseMintResult = (result: MintTokenBody) => { - const { - tx_result: { Evm: txReceipt, Substrate: txHash }, - typed_chain_id: { Evm: evmChainId, Substrate: substrateChainId }, - } = result; - - let typedChainId: number; - let transactionHash: string; - let isSubstrate = false; - - if (substrateChainId) { - typedChainId = calculateTypedChainId(ChainType.Substrate, substrateChainId); - transactionHash = txHash ?? ''; - isSubstrate = true; - } else if (evmChainId) { - typedChainId = calculateTypedChainId(ChainType.EVM, evmChainId); - transactionHash = txReceipt?.transactionHash ?? ''; - } else { - typedChainId = -1; - transactionHash = ''; +const parseMintResult = ( + result: MintTokenBody +): { + isSubstrate: boolean; + hash: string; + typedChainId: number; +} => { + const { typed_chain_id, tx_result } = result; + + if ('Substrate' in tx_result) { + return { + hash: tx_result.Substrate.block_hash, + isSubstrate: true, + typedChainId: calculateTypedChainId( + ChainType.Substrate, + typed_chain_id.id + ), + }; } return { - isSubstrate, - transactionHash, - typedChainId, + hash: tx_result.Evm.transactionHash, + isSubstrate: false, + typedChainId: calculateTypedChainId(ChainType.EVM, typed_chain_id.id), }; }; diff --git a/apps/faucet/src/types/index.ts b/apps/faucet/src/types/index.ts index 9fcf1e80a6..9294a6d77b 100644 --- a/apps/faucet/src/types/index.ts +++ b/apps/faucet/src/types/index.ts @@ -155,7 +155,8 @@ export type MintTokenBody = { * The typed chain id */ typed_chain_id: { - [type in ChainType]: number; + id: number; + type: ChainType; }; /** @@ -171,10 +172,16 @@ export type MintTokenBody = { /** * The transaction receipt */ - tx_result: { - Evm?: TransactionReceipt; - Substrate?: string; - }; + tx_result: + | { + Evm: TransactionReceipt; + } + | { + Substrate: { + block_hash: string; + tx_hash: string; + }; + }; }; export type TooManyClaimResponse = { diff --git a/libs/dapp-config/src/chains/substrate/index.tsx b/libs/dapp-config/src/chains/substrate/index.tsx index b0e69712a7..2fda5df933 100644 --- a/libs/dapp-config/src/chains/substrate/index.tsx +++ b/libs/dapp-config/src/chains/substrate/index.tsx @@ -45,7 +45,7 @@ export const chainsConfig: Record = { }, env: ['development'], }, - [PresetTypedChainId.LocalTangleStandalone]: { + /* [PresetTypedChainId.LocalTangleStandalone]: { chainType: ChainType.Substrate, id: SubstrateChainId.LocalTangleStandalone, name: 'Tangle', @@ -74,20 +74,37 @@ export const chainsConfig: Record = { }, }, env: ['development'], - }, - /* [PresetTypedChainId.TangleStandaloneTestnet]: { + }, */ + [PresetTypedChainId.TangleStandaloneTestnet]: { chainType: ChainType.Substrate, - group: 'webb', + group: 'tangle', tag: 'test', - chainId: SubstrateChainId.TangleStandaloneTestnet, - logo: WEBBLogo, - url: 'wss://tangle-standalone-archive.webb.tools', - blockExplorerStub: populateBlockExplorerStub( - 'wss://tangle-standalone-archive.webb.tools' - ), + id: SubstrateChainId.TangleStandaloneTestnet, name: 'Tangle Standalone Testnet', + network: 'Substrate', + nativeCurrency: { + name: 'Tangle', + symbol: 'tTNT', + decimals: 18, + }, + blockExplorers: { + default: { + name: 'Tangle Explorer', + url: populateBlockExplorerStub('wss://rpc-archive.tangle.tools'), + }, + }, + rpcUrls: { + default: { + http: [], + webSocket: ['wss://rpc-archive.tangle.tools', 'wss://rpc.tangle.tools'], + }, + public: { + http: [], + webSocket: ['wss://rpc-archive.tangle.tools', 'wss://rpc.tangle.tools'], + }, + }, env: ['development'], - }, */ + }, [PresetTypedChainId.Kusama]: { chainType: ChainType.KusamaRelayChain, id: SubstrateChainId.Kusama,