Skip to content

Commit

Permalink
fix(wrw): make the gas fields in EVM CCR FORM as optional
Browse files Browse the repository at this point in the history
  • Loading branch information
venkateshv1266 committed Sep 13, 2024
1 parent c085651 commit ff75451
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 41 deletions.
17 changes: 8 additions & 9 deletions src/containers/EvmCrossChainRecoveryWallet/ColdWalletForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ const validationSchema = Yup.object({
gasLimit: Yup.number()
.typeError('Gas limit must be a number')
.integer()
.positive('Gas limit must be a positive integer')
.required(),
maxFeePerGas: Yup.number().required(),
maxPriorityFeePerGas: Yup.number().required(),
.positive('Gas limit must be a positive integer'),
maxFeePerGas: Yup.number(),
maxPriorityFeePerGas: Yup.number(),
recoveryDestination: Yup.string().required(),
userKey: Yup.string().required(),
userKeyId: Yup.string(),
Expand All @@ -21,7 +20,7 @@ const validationSchema = Yup.object({
apiKey: Yup.string().required(),
wrongChain: Yup.string().required(),
intendedChain: Yup.string().required(),
gasPrice: Yup.number().required(),
gasPrice: Yup.number(),
}).required();

export type FormProps = {
Expand All @@ -38,9 +37,9 @@ export function ColdWalletForm({ onSubmit }: FormProps) {
onSubmit,
initialValues: {
bitgoFeeAddress: '',
gasLimit: 500000,
maxFeePerGas: 500,
maxPriorityFeePerGas: 50,
gasLimit: undefined,
maxFeePerGas: undefined,
maxPriorityFeePerGas: undefined,
recoveryDestination: '',
userKey: '',
userKeyId: '',
Expand All @@ -49,7 +48,7 @@ export function ColdWalletForm({ onSubmit }: FormProps) {
apiKey: '',
wrongChain: '',
intendedChain: '',
gasPrice: 20,
gasPrice: undefined,
},
validationSchema,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ export function EvmCrossChainRecoveryBaseForm({
const [intendedChainCoins, setIntendedChainCoins] = useState<
readonly CoinMetadata[]
>([]);
const [gasLimit, setGasLimit] = useState(500000);
const [maxFeePerGas, setMaxFeePerGas] = useState(500);
const [maxPriorityFeePerGas, setMaxPriorityFeePerGas] = useState(50);
const { env } = useParams<'env'>();
const { wallet } = useParams<'wallet'>();
const isCustodyWallet = wallet === allWalletMetas.custody.value;
Expand Down Expand Up @@ -53,11 +50,6 @@ export function EvmCrossChainRecoveryBaseForm({
setDisabled(false);
const intendedChainCoins = evmCCRIntendedChainCoins[wrongChainName];
setIntendedChainCoins(intendedChainCoins);
setGasLimit(allCoinMetas[wrongChainName]?.defaultGasLimitNum ?? 500000);
setMaxFeePerGas(allCoinMetas[wrongChainName]?.defaultMaxFeePerGas ?? 500);
setMaxPriorityFeePerGas(
allCoinMetas[wrongChainName]?.defaultMaxPriorityFeePerGas ?? 50
);
};

const getIntendedChainCoins = () => {
Expand Down Expand Up @@ -132,8 +124,8 @@ export function EvmCrossChainRecoveryBaseForm({
{!isCustodyWallet && (
<div className="tw-mb-4">
<FormikTextfield
HelperText="Gas limit for the Polygon transaction. The value should be between 30,000 and 20,000,000. The default is 500,000 unit of gas."
Label="Gas Limit"
HelperText="Gas limit for the transaction. The value should be between 30,000 and 20,000,000."
Label="Gas Limit (optional)"
name="gasLimit"
Width="fill"
/>
Expand All @@ -144,17 +136,17 @@ export function EvmCrossChainRecoveryBaseForm({
<>
<div className="tw-mb-4">
<FormikTextfield
HelperText="Max fee per gas for the Polygon transaction. The default is 20 Gwei."
Label="Max Fee Per Gas (Gwei)"
HelperText="Max fee per gas for the transaction."
Label="Max Fee Per Gas (Gwei) (optional)"
name="maxFeePerGas"
Width="fill"
/>
</div>

<div className="tw-mb-4">
<FormikTextfield
HelperText='"Tip" to the Polygon miner. This is by default 10 Gwei.'
Label="Max Priority Fee Per Gas (Gwei)"
HelperText='"Tip" to the miner.'
Label="Max Priority Fee Per Gas (Gwei) (optional)"
name="maxPriorityFeePerGas"
Width="fill"
/>
Expand All @@ -165,8 +157,8 @@ export function EvmCrossChainRecoveryBaseForm({
{!isCustodyWallet && isBscChain(wrongChain) && (
<div className="tw-mb-4">
<FormikTextfield
HelperText="Provide the Gas Price for BSC. This is by default 20 Gwei"
Label="Gas Price (Gwei)"
HelperText="Provide the Gas Price for the transaction."
Label="Gas Price (Gwei) (optional)"
name="gasPrice"
Width="fill"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ interface CustodyWalletParams extends BaseParams {
interface NonCustodyWalletParams extends BaseParams {
walletContractAddress: string;
bitgoFeeAddress: string;
gasLimit: number;
maxFeePerGas: number;
maxPriorityFeePerGas: number;
gasLimit?: number;
maxFeePerGas?: number;
maxPriorityFeePerGas?: number;
apiKey: string;
gasPrice: number;
gasPrice?: number;
}

interface HotWalletParams extends NonCustodyWalletParams {
Expand Down Expand Up @@ -181,7 +181,9 @@ async function handleNonCustodyFormSubmit(
values.wrongChain,
values as ColdWalletParams
);
values.gasPrice = toWei(values.gasPrice);
if (values.gasPrice) {
values.gasPrice = toWei(values.gasPrice);
}
const recoverData = await window.commands.recover(values.wrongChain, {
...values,
eip1559: getEip1559Params(values.wrongChain, maxFeePerGas, maxPriorityFeePerGas),
Expand Down
17 changes: 8 additions & 9 deletions src/containers/EvmCrossChainRecoveryWallet/HotWalletForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@ const validationSchema = Yup.object({
gasLimit: Yup.number()
.typeError('Gas limit must be a number')
.integer()
.positive('Gas limit must be a positive integer')
.required(),
maxFeePerGas: Yup.number().required(),
maxPriorityFeePerGas: Yup.number().required(),
.positive('Gas limit must be a positive integer'),
maxFeePerGas: Yup.number(),
maxPriorityFeePerGas: Yup.number(),
recoveryDestination: Yup.string().required(),
walletContractAddress: Yup.string().required(),
walletPassphrase: Yup.string().required(),
tokenContractAddress: Yup.string(),
apiKey: Yup.string().required(),
wrongChain: Yup.string().required(),
intendedChain: Yup.string().required(),
gasPrice: Yup.number().required(),
gasPrice: Yup.number(),
}).required();

export type FormProps = {
Expand All @@ -39,17 +38,17 @@ export function HotWalletForm({ onSubmit }: FormProps) {
initialValues: {
userKey: '',
bitgoFeeAddress: '',
gasLimit: 500000,
maxFeePerGas: 500,
maxPriorityFeePerGas: 50,
gasLimit: undefined,
maxFeePerGas: undefined,
maxPriorityFeePerGas: undefined,
recoveryDestination: '',
walletContractAddress: '',
walletPassphrase: '',
tokenContractAddress: undefined,
apiKey: '',
wrongChain: '',
intendedChain: '',
gasPrice: 20,
gasPrice: undefined,
},
validationSchema,
});
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ export function isEtcChain(coin: string) {
return (coin === 'etc' || coin === 'tetc')
}

export function getEip1559Params(coin: string, maxFeePerGas: number, maxPriorityFeePerGas: number) {
export function getEip1559Params(coin: string, maxFeePerGas?: number, maxPriorityFeePerGas?: number) {
// bsc/tbsc and etc/tetc doesn't support EIP-1559
if (isBscChain(coin) || isEtcChain(coin)) {
if (isBscChain(coin) || isEtcChain(coin) || !maxFeePerGas || !maxPriorityFeePerGas) {
return undefined;
}
return {
Expand Down

0 comments on commit ff75451

Please sign in to comment.