Skip to content

Commit

Permalink
Merge pull request #240 from BitGo/fix/remove-api-key-field-from-ethw
Browse files Browse the repository at this point in the history
fix: remove api key field from ethw forms
  • Loading branch information
benpreiser authored Sep 23, 2022
2 parents 6004977 + a6091fe commit 85368b8
Show file tree
Hide file tree
Showing 6 changed files with 449 additions and 4 deletions.
2 changes: 1 addition & 1 deletion NON_BITGO_RECOVERY.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Build a transaction from a hot wallet using the KeyCard in order to recover fund

13. For UTXO based coins like Bitcoin, Litecoin, Dash, Zcash, Bitcoin Gold, and Bitcoin Cash, the key is from https://blockchair.com/.

14. For Ethereum, Ethereum Proof of Work, and ERC20 token, the key is from https://etherscan.io/.
14. For Ethereum and ERC20 token, the key is from https://etherscan.io/.

15. For Avalanche C-Chain, the key is from https://snowtrace.io/.

Expand Down
2 changes: 1 addition & 1 deletion UNSIGNED_SWEEP.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Build an unsigned transaction from a cold wallet using the user and backup publi

13. For UTXO based coins like Bitcoin, Litecoin, Dash, Zcash, Bitcoin Gold, and Bitcoin Cash, the key is from https://blockchair.com/.

14. For Ethereum, Ethereum Proof of Work, and ERC20 token, the key is from https://etherscan.io/.
14. For Ethereum and ERC20 token, the key is from https://etherscan.io/.

15. For Avalanche C-Chain, the key is from https://snowtrace.io/.

Expand Down
76 changes: 75 additions & 1 deletion src/containers/BuildUnsignedSweepCoin/BuildUnsignedSweepCoin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { BitcoinCashForm } from './BitcoinCashForm';
import { BitcoinForm } from './BitcoinForm';
import { Erc20TokenForm } from './Erc20TokenForm';
import { EthereumForm } from './EthereumForm';
import { EthereumWForm } from './EthereumWForm';
import { LitecoinForm } from './LitecoinForm';
import { RippleForm } from './RippleForm';
import { TronForm } from './TronForm';
Expand Down Expand Up @@ -228,7 +229,6 @@ function Form() {
);
case 'eth':
case 'gteth':
case 'ethw':
return (
<EthereumForm
key={coin}
Expand Down Expand Up @@ -291,6 +291,80 @@ function Form() {
{ encoding: 'utf-8' }
);

navigate(
`/${bitGoEnvironment}/build-unsigned-sweep/${coin}/success`
);
} catch (err) {
if (err instanceof Error) {
setAlert(err.message);
} else {
console.error(err);
}
setSubmitting(false);
}
}}
/>
);
case 'ethw':
return (
<EthereumWForm
key={coin}
onSubmit={async (values, { setSubmitting }) => {
setAlert(undefined);
setSubmitting(true);
try {
await window.commands.setBitGoEnvironment(bitGoEnvironment);
const chainData = await window.queries.getChain(coin);

const { maxFeePerGas, maxPriorityFeePerGas, ...rest } =
await updateKeysFromIds(coin, values);
const recoverData = await window.commands.recover(coin, {
...rest,
eip1559: {
maxFeePerGas: toWei(maxFeePerGas),
maxPriorityFeePerGas: toWei(maxPriorityFeePerGas),
},
replayProtectionOptions: {
chain: getEthLikeRecoveryChainId(coin, bitGoEnvironment),
hardfork: 'london',
},
bitgoKey: '',
ignoreAddressTypes: [],
});
assert(
isRecoveryTransaction(recoverData),
'Fully-signed recovery transaction not detected.'
);

const showSaveDialogData = await window.commands.showSaveDialog({
filters: [
{
name: 'Custom File Type',
extensions: ['json'],
},
],
defaultPath: `~/${chainData}-unsigned-sweep-${Date.now()}.json`,
});

if (!showSaveDialogData.filePath) {
throw new Error('No file path selected');
}

await window.commands.writeFile(
showSaveDialogData.filePath,
JSON.stringify(
includePubsInUnsignedSweep
? {
...recoverData,
...(await includePubsFor(coin, values)),
}
: recoverData,
null,
2
),
{ encoding: 'utf-8' }
);

navigate(
`/${bitGoEnvironment}/build-unsigned-sweep/${coin}/success`
);
Expand Down
143 changes: 143 additions & 0 deletions src/containers/BuildUnsignedSweepCoin/EthereumWForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import { Form, FormikHelpers, FormikProvider, useFormik } from 'formik';
import { Link } from 'react-router-dom';
import * as Yup from 'yup';
import { Button, FormikTextfield } from '~/components';

const validationSchema = Yup.object({
backupKey: Yup.string().required(),
backupKeyId: Yup.string(),
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(),
recoveryDestination: Yup.string().required(),
userKey: Yup.string().required(),
userKeyId: Yup.string(),
walletContractAddress: Yup.string().required(),
}).required();

export type EthereumWFormProps = {
onSubmit: (
values: EthereumWFormValues,
formikHelpers: FormikHelpers<EthereumWFormValues>
) => void | Promise<void>;
};

type EthereumWFormValues = Yup.Asserts<typeof validationSchema>;

export function EthereumWForm({ onSubmit }: EthereumWFormProps) {
const formik = useFormik<EthereumWFormValues>({
onSubmit,
initialValues: {
backupKey: '',
backupKeyId: '',
gasLimit: 500000,
maxFeePerGas: 20,
maxPriorityFeePerGas: 10,
recoveryDestination: '',
userKey: '',
userKeyId: '',
walletContractAddress: '',
},
validationSchema,
});

return (
<FormikProvider value={formik}>
<Form>
<h4 className="tw-text-body tw-font-semibold tw-border-b-0.5 tw-border-solid tw-border-gray-700 tw-mb-4">
Self-managed cold wallet details
</h4>
<div className="tw-mb-4">
<FormikTextfield
HelperText="Your user public key, as found on your recovery KeyCard."
Label="User Public Key"
name="userKey"
Width="fill"
/>
</div>
<div className="tw-mb-4">
<FormikTextfield
HelperText="Your user Key ID, as found on your KeyCard. Most wallets will not have this and you can leave it blank."
Label="User Key ID (optional)"
name="userKeyId"
Width="fill"
/>
</div>
<div className="tw-mb-4">
<FormikTextfield
HelperText="The backup public key for the wallet, as found on your recovery KeyCard."
Label="Backup Public Key"
name="backupKey"
Width="fill"
/>
</div>
<div className="tw-mb-4">
<FormikTextfield
HelperText="Your backup Key ID, as found on your KeyCard. Most wallets will not have this and you can leave it blank."
Label="Backup Key ID (optional)"
name="backupKeyId"
Width="fill"
/>
</div>
<div className="tw-mb-4">
<FormikTextfield
HelperText="The ETH address of the wallet contract. This is also the wallet's base address."
Label="Wallet Contract Address"
name="walletContractAddress"
Width="fill"
/>
</div>
<div className="tw-mb-4">
<FormikTextfield
HelperText="The address your recovery transaction will send to."
Label="Destination Address"
name="recoveryDestination"
Width="fill"
/>
</div>
<div className="tw-mb-4">
<FormikTextfield
HelperText="Gas limit for the ETH transaction. The value should be between 30,000 and 20,000,000. The default is 500,000 unit of gas."
Label="Gas Limit"
name="gasLimit"
Width="fill"
/>
</div>
<div className="tw-mb-4">
<FormikTextfield
HelperText="Max fee per gas for the ETH transaction. The default is 20 Gwei."
Label="Max Fee Per Gas (Gwei)"
name="maxFeePerGas"
Width="fill"
/>
</div>
<div className="tw-mb-4">
<FormikTextfield
HelperText='"Tip" to the ETH miner. This is by default 10 Gwei.'
Label="Max Priority Fee Per Gas (Gwei)"
name="maxPriorityFeePerGas"
Width="fill"
/>
</div>
<div className="tw-flex tw-flex-col-reverse sm:tw-justify-between sm:tw-flex-row tw-gap-1 tw-mt-4">
<Button Tag={Link} to="/" Variant="secondary" Width="hug">
Cancel
</Button>
<Button
Variant="primary"
Width="hug"
type="submit"
Disabled={formik.isSubmitting}
disabled={formik.isSubmitting}
>
{formik.isSubmitting ? 'Recovering...' : 'Recover Funds'}
</Button>
</div>
</Form>
</FormikProvider>
);
}
Loading

0 comments on commit 85368b8

Please sign in to comment.