Commit 455ac4bb authored by tom's avatar tom

tx fixes

parent 0e071390
......@@ -15,7 +15,7 @@ import { useContractContext } from './context';
import ContractConnectWallet from './ContractConnectWallet';
import ContractMethodCallable from './ContractMethodCallable';
import ContractWriteResult from './ContractWriteResult';
import { getNativeCoinValue } from './utils';
import { getNativeCoinValue, isExtendedError } from './utils';
interface Props {
isProxy?: boolean;
......@@ -68,11 +68,11 @@ const ContractWrite = ({ isProxy }: Props) => {
return { hash: result.hash as string };
} catch (error) {
if (error instanceof Error) {
if (isExtendedError(error)) {
if ('reason' in error && error.reason === 'underlying network changed') {
if ('detectedNetwork' in error) {
const networkName = (error.detectedNetwork as { name: string }).name;
if ('detectedNetwork' in error && typeof error.detectedNetwork === 'object' && error.detectedNetwork !== null) {
const networkName = error.detectedNetwork.name;
if (networkName) {
throw new Error(
// eslint-disable-next-line max-len
......
......@@ -6,3 +6,20 @@ export const getNativeCoinValue = (value: string | Array<string>) => {
const _value = Array.isArray(value) ? value[0] : value;
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