Commit 455ac4bb authored by tom's avatar tom

tx fixes

parent 0e071390
...@@ -15,7 +15,7 @@ import { useContractContext } from './context'; ...@@ -15,7 +15,7 @@ import { useContractContext } from './context';
import ContractConnectWallet from './ContractConnectWallet'; import ContractConnectWallet from './ContractConnectWallet';
import ContractMethodCallable from './ContractMethodCallable'; import ContractMethodCallable from './ContractMethodCallable';
import ContractWriteResult from './ContractWriteResult'; import ContractWriteResult from './ContractWriteResult';
import { getNativeCoinValue } from './utils'; import { getNativeCoinValue, isExtendedError } from './utils';
interface Props { interface Props {
isProxy?: boolean; isProxy?: boolean;
...@@ -68,11 +68,11 @@ const ContractWrite = ({ isProxy }: Props) => { ...@@ -68,11 +68,11 @@ const ContractWrite = ({ isProxy }: Props) => {
return { hash: result.hash as string }; return { hash: result.hash as string };
} catch (error) { } catch (error) {
if (error instanceof Error) { if (isExtendedError(error)) {
if ('reason' in error && error.reason === 'underlying network changed') { if ('reason' in error && error.reason === 'underlying network changed') {
if ('detectedNetwork' in error) { if ('detectedNetwork' in error && typeof error.detectedNetwork === 'object' && error.detectedNetwork !== null) {
const networkName = (error.detectedNetwork as { name: string }).name; const networkName = error.detectedNetwork.name;
if (networkName) { if (networkName) {
throw new Error( throw new Error(
// eslint-disable-next-line max-len // eslint-disable-next-line max-len
......
...@@ -6,3 +6,20 @@ export const getNativeCoinValue = (value: string | Array<string>) => { ...@@ -6,3 +6,20 @@ export const getNativeCoinValue = (value: string | Array<string>) => {
const _value = Array.isArray(value) ? value[0] : value; const _value = Array.isArray(value) ? value[0] : value;
return BigNumber(_value).times(10 ** config.network.currency.decimals).toString(); return BigNumber(_value).times(10 ** config.network.currency.decimals).toString();
}; };
interface ExtendedError extends Error {
detectedNetwork?: {
chain: number;
name: string;
};
reason?: string;
}
export function isExtendedError(error: unknown): error is ExtendedError {
return (
typeof error === 'object' &&
error !== null &&
'message' in error &&
typeof (error as Record<string, unknown>).message === 'string'
);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment