Skip to content

Commit

Permalink
feat(wrw): add unsigned sweep support for atom
Browse files Browse the repository at this point in the history
TICKET: WIN-4628
  • Loading branch information
Chinmay-Sharma1 committed Feb 14, 2025
1 parent d4d1e75 commit 695f6aa
Show file tree
Hide file tree
Showing 5 changed files with 204 additions and 13 deletions.
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"dependencies": {
"@bitgo/abstract-cosmos": "11.2.20",
"@bitgo/abstract-utxo": "9.15.0",
"@bitgo/sdk-api": "1.58.6",
"@bitgo/sdk-api": "^1.58.7",
"@bitgo/sdk-coin-ada": "4.6.4",
"@bitgo/sdk-coin-algo": "2.1.62",
"@bitgo/sdk-coin-arbeth": "21.0.56",
Expand Down
71 changes: 71 additions & 0 deletions src/containers/BuildUnsignedSweepCoin/BuildUnsignedSweepCoin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { buildUnsignedSweepCoins, tokenParentCoins } from '~/helpers/config';
import { HederaForm } from './HederaForm';
import { AlgorandForm } from '~/containers/BuildUnsignedSweepCoin/AlgorandForm';
import { RippleTokenForm } from '~/containers/BuildUnsignedSweepCoin/RippleTokenForm';
import { CosmosForm } from './CosmosForm';

function Form() {
const { env, coin } = useParams<'env' | 'coin'>();
Expand Down Expand Up @@ -1465,6 +1466,76 @@ function Form() {
}}
/>
);
case 'atom':
case 'tatom':
return (
<CosmosForm
key={coin}
onSubmit={async (values, { setSubmitting }) => {
setAlert(undefined);
setSubmitting(true);
try {
await window.commands.setBitGoEnvironment(bitGoEnvironment, coin);
const chainData = await window.queries.getChain(coin);
const recoverData = await window.commands.recover(coin, {
...values,
scan: Number(values.scan),
startingScanIndex: Number(values.startingScanIndex),
bitgoKey: values.bitgoKey.replace(/\s+/g, ''),
ignoreAddressTypes: [],
});
assert(
isRecoveryTransaction(recoverData),
'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(recoverData, null, 2),
{ encoding: 'utf-8' }
);

await window.commands.writeFile(
showSaveDialogData.filePath,
JSON.stringify(
{
...recoverData,
...(await includePubsFor(coin, values)),
},
null,
2
),
{ 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);
}
}}
/>
);
default:
throw new Error(`Unsupported coin: ${String(coin)}`);
}
Expand Down
118 changes: 118 additions & 0 deletions src/containers/BuildUnsignedSweepCoin/CosmosForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import { Form, FormikHelpers, FormikProvider, useFormik } from 'formik';
import { Link } from 'react-router-dom';
import * as Yup from 'yup';
import {
Button,
FormikPasswordfield,
FormikSelectfield,
FormikTextarea,
FormikTextfield,
} from '~/components';

const validationSchema = Yup.object({
backupKey: Yup.string().required(),
bitgoKey: Yup.string().required(),
recoveryDestination: Yup.string().required(),
scan: Yup.number().required(),
startingScanIndex: Yup.number().required(),
userKey: Yup.string().required(),
}).required();

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

type CosmosFormValues = Yup.Asserts<typeof validationSchema>;

export function CosmosForm({ onSubmit }: CosmosFormProps) {
const formik = useFormik<CosmosFormValues>({
onSubmit,
initialValues: {
backupKey: '',
bitgoKey: '',
recoveryDestination: '',
scan: 20,
startingScanIndex: 0,
userKey: '',
},
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="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="The BitGo public key for the wallet, as found on your recovery KeyCard."
Label="BitGo Public Key"
name="bitgoKey"
Width="fill"
/>
</div>

<div className="tw-mb-4">
<FormikTextfield
HelperText="The base address of the wallet (also known as root address)"
Label="Base Address"
name="rootAddress"
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="The amount of addresses without transactions to scan before stopping the tool."
Label="Address Scanning Factor"
name="scan"
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>
);
}
2 changes: 2 additions & 0 deletions src/helpers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,7 @@ export const buildUnsignedSweepCoins: Record<
allCoinMetas.sol,
allCoinMetas.solToken,
allCoinMetas.ada,
allCoinMetas.atom,
allCoinMetas.dot,
allCoinMetas.hbar,
allCoinMetas.algo,
Expand Down Expand Up @@ -713,6 +714,7 @@ export const buildUnsignedSweepCoins: Record<
allCoinMetas.tsol,
allCoinMetas.tsolToken,
allCoinMetas.tada,
allCoinMetas.tatom,
allCoinMetas.tdot,
allCoinMetas.thbar,
allCoinMetas.talgo,
Expand Down

0 comments on commit 695f6aa

Please sign in to comment.