diff --git a/apps/autonolas-registry/common-util/Login/LoginV2.jsx b/apps/autonolas-registry/common-util/Login/LoginV2.jsx
index 83a0bc42..27d46c81 100644
--- a/apps/autonolas-registry/common-util/Login/LoginV2.jsx
+++ b/apps/autonolas-registry/common-util/Login/LoginV2.jsx
@@ -36,7 +36,7 @@ export const LoginV2 = ({
const { disconnect } = useDisconnect();
const { chainId, isConnectedToWrongNetwork } = useHelpers();
const { chain: walletConnectedChain } = useAccount();
- const { switchChainAsync, isLoading } = useSwitchChain();
+ const { switchChainAsync, isPending } = useSwitchChain();
const screens = useBreakpoint();
@@ -142,7 +142,7 @@ export const LoginV2 = ({
<>
{!hideWrongNetwork && (
}>
diff --git a/apps/launch/common-util/ErrorAlert.tsx b/apps/launch/common-util/ErrorAlert.tsx
new file mode 100644
index 00000000..2dd219d5
--- /dev/null
+++ b/apps/launch/common-util/ErrorAlert.tsx
@@ -0,0 +1,34 @@
+import { Alert } from 'antd';
+import { mainnet } from 'viem/chains';
+
+import { EXPLORER_URLS, UNICODE_SYMBOLS } from 'libs/util-constants/src';
+
+import { ErrorType } from 'types/index';
+
+export const ErrorAlert = ({
+ error,
+ networkId,
+}: {
+ error: NonNullable;
+ networkId?: number | null;
+}) => (
+
+ {error.message}
+ {error.transactionHash && (
+ <>
+
+ {`Explore transaction hash ${UNICODE_SYMBOLS.EXTERNAL_LINK}`}
+ >
+ )}
+ >
+ }
+ />
+);
diff --git a/apps/launch/common-util/functions/frontend-library.ts b/apps/launch/common-util/functions/frontend-library.ts
index 1df08872..d1211111 100644
--- a/apps/launch/common-util/functions/frontend-library.ts
+++ b/apps/launch/common-util/functions/frontend-library.ts
@@ -36,31 +36,65 @@ export const notifyConnectWallet = () => {
notifyWarning('Please connect your wallet');
};
-const METAMASK_ERRORS: Record = {
- 4001: 'Transaction rejected by user. The contract hasn’t been created.',
+export enum Feature {
+ CREATE = 'create',
+ NOMINATE = 'nominate',
+}
+
+const METAMASK_ERRORS = {
+ create: [
+ {
+ code: 4001,
+ name: '',
+ message: 'Transaction rejected by user. The contract hasn’t been created.',
+ },
+ ],
+ nominate: [
+ {
+ code: 4001,
+ name: 'Transaction rejected by user',
+ message: 'Transaction rejected by user. The contract hasn’t been nominated',
+ },
+ ],
};
-const EVM_ERRORS = [
- {
- errorText: 'Transaction has been reverted by the EVM',
- displayText: 'Transaction failed. The contract hasn’t been created.',
- },
-];
+const EVM_ERRORS = {
+ create: [
+ {
+ errorText: 'Transaction has been reverted by the EVM',
+ name: '',
+ displayText: 'Transaction failed. The contract hasn’t been created.',
+ },
+ ],
+ nominate: [
+ {
+ errorText: 'Transaction has been reverted by the EVM',
+ name: 'Transaction failed',
+ displayText: 'Transaction failed. The contract hasn’t been nominated',
+ },
+ ],
+};
-export const getErrorInfo = (error: Error | { code: number; message: string }) => {
+export const getErrorInfo = (type: Feature, error: Error | { code: number; message: string }) => {
const defaultMessage = 'Some error occurred. Please try again';
+ let name;
let message = defaultMessage;
let transactionHash;
- if ('code' in error && METAMASK_ERRORS[error.code]) {
- message = METAMASK_ERRORS[error.code];
+ if ('code' in error) {
+ const metamaskError = METAMASK_ERRORS[type].find((item) => item.code === error.code);
+ if (metamaskError) {
+ name = metamaskError.name;
+ message = metamaskError.message;
+ }
}
if ('message' in error) {
- const foundError = EVM_ERRORS.find((item) => error.message.indexOf(item.errorText) !== -1);
- if (foundError) {
- message = foundError.displayText;
+ const evmError = EVM_ERRORS[type].find((item) => error.message === item.errorText);
+ if (evmError) {
+ name = evmError.name;
+ message = evmError.displayText;
}
}
@@ -68,5 +102,5 @@ export const getErrorInfo = (error: Error | { code: number; message: string }) =
transactionHash = (error.receipt as TransactionReceipt).transactionHash as Address;
}
- return { message, transactionHash };
+ return { name, message, transactionHash };
};
diff --git a/apps/launch/common-util/hooks/useNetworkHelpers.tsx b/apps/launch/common-util/functions/networkHelpers.ts
similarity index 69%
rename from apps/launch/common-util/hooks/useNetworkHelpers.tsx
rename to apps/launch/common-util/functions/networkHelpers.ts
index 17079b00..1a4c93e7 100644
--- a/apps/launch/common-util/hooks/useNetworkHelpers.tsx
+++ b/apps/launch/common-util/functions/networkHelpers.ts
@@ -15,3 +15,10 @@ export const getChainIdFromPath = (networkName: string | undefined) => {
const network = ALL_SUPPORTED_CHAINS.find((e) => toLower(e.networkName) === toLower(networkName));
return network?.id;
};
+
+export const getDisplayNameFromPath = (networkName: string | undefined) => {
+ if (!networkName) return null;
+
+ const network = ALL_SUPPORTED_CHAINS.find((e) => toLower(e.networkName) === toLower(networkName));
+ return network?.networkDisplayName;
+};
diff --git a/apps/launch/common-util/functions/web3.ts b/apps/launch/common-util/functions/web3.ts
index bb0bb98f..32af75f9 100644
--- a/apps/launch/common-util/functions/web3.ts
+++ b/apps/launch/common-util/functions/web3.ts
@@ -1,4 +1,3 @@
-import { BaseContractMethod, Contract } from 'ethers';
import { Address } from 'viem';
import Web3 from 'web3';
import { AbiItem } from 'web3-utils';
@@ -48,6 +47,7 @@ export const getStakingFactoryContract = () => {
return contract;
};
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const sendTransaction = async (methodFn: any, account: Address) => {
const estimatedGas = await getEstimatedGasLimit(methodFn, account);
const fn = methodFn.send({ from: account, estimatedGas });
@@ -63,6 +63,7 @@ type CreateContractParams = {
initPayload: string;
account: Address;
};
+
export const createStakingContract = async ({
implementation,
initPayload,
@@ -74,3 +75,17 @@ export const createStakingContract = async ({
return result;
};
+
+type AddNomineeParams = {
+ address: Address;
+ chainId: number;
+ account: Address;
+};
+
+export const addNominee = async ({ address, chainId, account }: AddNomineeParams) => {
+ const contract = getVoteWeightingContract();
+ const createFn = contract.methods.addNomineeEVM(address, chainId);
+ const result = await sendTransaction(createFn, account);
+
+ return result;
+};
diff --git a/apps/launch/components/Layout/SwitchNetworkSelect/index.tsx b/apps/launch/components/Layout/SwitchNetworkSelect/index.tsx
index bf2a73f4..0c7c189d 100644
--- a/apps/launch/components/Layout/SwitchNetworkSelect/index.tsx
+++ b/apps/launch/components/Layout/SwitchNetworkSelect/index.tsx
@@ -10,8 +10,6 @@ import {
PAGES_TO_LOAD_WITH_CHAIN_ID,
} from 'common-util/config/supportedChains';
-import { useHandleRoute } from './useHandleRoute';
-
const networkSelectOptions = ALL_SUPPORTED_CHAINS.map((e) => ({
label: e.networkDisplayName,
value: e.networkName,
@@ -25,9 +23,6 @@ export const SwitchNetworkSelect: FC = () => {
const chainName = (router?.query?.network || 'ethereum') as string;
- // handle the routing
- useHandleRoute();
-
return (