Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
handle non-eip1159 networks
Browse files Browse the repository at this point in the history
  • Loading branch information
hcote committed Apr 12, 2024
1 parent c263453 commit bc9b79f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import FormInput from '@/components/ui/FormInput';
import ErrorText from '@/components/ui/ErrorText';
import Card from '@/components/ui/Card';
import CardHeader from '@/components/ui/CardHeader';
import { getFaucetUrl, getNetworkToken } from '@/utils/network';
import { getFaucetUrl, getNetworkToken, isEip1559Supported } from '@/utils/network';
import showToast from '@/utils/showToast';
import Spacer from '@/components/ui/Spacer';
import TransactionHistory from '@/components/ui/TransactionHistory';
Expand All @@ -29,7 +29,7 @@ const SendTransaction = () => {
setToAddressError(false);
}, [amount, toAddress]);

const sendTransaction = useCallback(() => {
const sendTransaction = useCallback(async () => {
if (!web3?.utils.isAddress(toAddress)) {
return setToAddressError(true);
}
Expand All @@ -41,7 +41,8 @@ const SendTransaction = () => {
from: publicAddress,
to: toAddress,
value: web3.utils.toWei(amount, 'ether'),
gas: 21000,
// Specify `gasPrice` if network doesn't support EIP-1559
...(!isEip1559Supported() && { gasPrice: await web3.eth.getGasPrice() }),
};
web3.eth
.sendTransaction(txnParams as any)
Expand Down
14 changes: 14 additions & 0 deletions scaffolds/nextjs-dedicated-wallet/template/src/utils/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,17 @@ export const getBlockExplorer = (address: string) => {
return `https://sepolia.explorer.zksync.io/address/${address}`;
}
};

export const isEip1559Supported = () => {
switch (process.env.NEXT_PUBLIC_BLOCKCHAIN_NETWORK) {
case Network.POLYGON:
case Network.POLYGON_AMOY:
case Network.ETHEREUM_SEPOLIA:
case Network.ETHEREUM:
case Network.ZKSYNC:
case Network.ZKSYNC_SEPOLIA:
return true;
case Network.ETHERLINK_TESTNET:
return false;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import CardHeader from '../../ui/CardHeader';
import TransactionHistory from '../../ui/TransactionHistory';
import ErrorText from '../../ui/Error';
import { useMagicContext } from '@/components/magic/MagicProvider';
import { getFaucetUrl, getNetworkToken } from '@/utils/networks';
import { getFaucetUrl, getNetworkToken, isEip1559Supported } from '@/utils/networks';

const SendTransaction = () => {
const { web3 } = useMagicContext();
Expand All @@ -30,7 +30,7 @@ const SendTransaction = () => {
setToAddressError(false);
}, [amount, toAddress]);

const sendTransaction = useCallback(() => {
const sendTransaction = useCallback(async () => {
if (!web3?.utils.isAddress(toAddress)) {
return setToAddressError(true);
}
Expand All @@ -42,7 +42,8 @@ const SendTransaction = () => {
from: publicAddress,
to: toAddress,
value: web3.utils.toWei(amount, 'ether'),
gas: 21000,
// Specify `gasPrice` if network doesn't support EIP-1559
...(!isEip1559Supported() && { gasPrice: await web3.eth.getGasPrice() }),
};
web3.eth
.sendTransaction(txnParams as any)
Expand Down
14 changes: 14 additions & 0 deletions scaffolds/nextjs-universal-wallet/template/src/utils/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,17 @@ export const getBlockExplorer = (address: string) => {
return `https://sepolia.explorer.zksync.io/address/${address}`;
}
};

export const isEip1559Supported = () => {
switch (process.env.NEXT_PUBLIC_BLOCKCHAIN_NETWORK) {
case Network.POLYGON:
case Network.POLYGON_AMOY:
case Network.ETHEREUM_SEPOLIA:
case Network.ETHEREUM:
case Network.ZKSYNC:
case Network.ZKSYNC_SEPOLIA:
return true;
case Network.ETHERLINK_TESTNET:
return false;
}
};

0 comments on commit bc9b79f

Please sign in to comment.