Skip to content

Commit

Permalink
fix: hotfix the response object
Browse files Browse the repository at this point in the history
  • Loading branch information
AtelyPham committed Oct 5, 2023
1 parent 3dbfb55 commit 80e588b
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 52 deletions.
71 changes: 35 additions & 36 deletions apps/faucet/src/components/ProcessingModal.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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]);

Expand Down Expand Up @@ -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),
};
};
17 changes: 12 additions & 5 deletions apps/faucet/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ export type MintTokenBody = {
* The typed chain id
*/
typed_chain_id: {
[type in ChainType]: number;
id: number;
type: ChainType;
};

/**
Expand All @@ -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 = {
Expand Down
39 changes: 28 additions & 11 deletions libs/dapp-config/src/chains/substrate/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const chainsConfig: Record<number, ChainConfig> = {
},
env: ['development'],
},
[PresetTypedChainId.LocalTangleStandalone]: {
/* [PresetTypedChainId.LocalTangleStandalone]: {
chainType: ChainType.Substrate,
id: SubstrateChainId.LocalTangleStandalone,
name: 'Tangle',
Expand Down Expand Up @@ -74,20 +74,37 @@ export const chainsConfig: Record<number, ChainConfig> = {
},
},
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,
Expand Down

0 comments on commit 80e588b

Please sign in to comment.