Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(wrw): add unsigned sweep support for atom #525

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
72 changes: 72 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,77 @@ 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),
userKey:(values.userKey ?? '').replace(/\s+/g, ''),
backupKey:(values.backupKey ?? '').replace(/\s+/g, ''),
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,
...(await includePubsFor(coin, {
...values,
userKey: values.userKey ?? '',
backupKey: values.backupKey ?? '',
bitgoKey: values.bitgoKey ?? '',
})),
},
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
102 changes: 102 additions & 0 deletions src/containers/BuildUnsignedSweepCoin/CosmosForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { Form, FormikHelpers, FormikProvider, useFormik } from 'formik';
import { Link } from 'react-router-dom';
import * as Yup from 'yup';
import {
Button,
FormikSelectfield,
FormikTextarea,
FormikTextfield,
} from '~/components';

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

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="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