Skip to content

Commit

Permalink
feat(sui): add sui token support
Browse files Browse the repository at this point in the history
  • Loading branch information
bhavidhingra committed Sep 20, 2024
1 parent 733a00d commit ecb6047
Show file tree
Hide file tree
Showing 10 changed files with 399 additions and 26 deletions.
2 changes: 1 addition & 1 deletion electron/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Dot, Tdot } from '@bitgo/sdk-coin-dot';
import { Sol, Tsol } from '@bitgo/sdk-coin-sol';
import { Hbar, Thbar } from '@bitgo/sdk-coin-hbar';
import { Algo, Talgo } from '@bitgo/sdk-coin-algo';
import { Sui, Tsui } from '@bitgo-beta/sdk-coin-sui';
import { Sui, Tsui } from '@bitgo/sdk-coin-sui';

export type createAdaBroadcastableSweepTransactionParameters =
| Parameters<Ada['createBroadcastableSweepTransaction']>[0]
Expand Down
26 changes: 13 additions & 13 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"dependencies": {
"@bitgo/abstract-cosmos": "11.0.4",
"@bitgo/abstract-utxo": "8.14.1",
"@bitgo/sdk-opensslbytes": "^2.0.0",
"@bitgo/sdk-api": "1.54.0",
"@bitgo/sdk-coin-ada": "4.2.13",
"@bitgo/sdk-coin-algo": "2.1.33",
Expand Down Expand Up @@ -44,13 +43,14 @@
"@bitgo/sdk-coin-polygon": "21.0.4",
"@bitgo/sdk-coin-sei": "3.0.4",
"@bitgo/sdk-coin-sol": "4.5.1",
"@bitgo/sdk-coin-sui": "5.6.3",
"@bitgo/sdk-coin-sui": "5.7.0",
"@bitgo/sdk-coin-tia": "3.0.4",
"@bitgo/sdk-coin-trx": "2.0.35",
"@bitgo/sdk-coin-xlm": "3.2.9",
"@bitgo/sdk-coin-xrp": "2.1.16",
"@bitgo/sdk-coin-zec": "2.0.35",
"@bitgo/sdk-coin-zeta": "3.0.4",
"@bitgo/sdk-opensslbytes": "^2.0.0",
"@bitgo/utxo-lib": "10.3.0",
"@ethereumjs/common": "2.6.5",
"@lottiefiles/react-lottie-player": "3.4.9",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import {
import { TronForm } from '~/containers/BuildUnsignedConsolidation/TronForm';
import { TronTokenForm } from '~/containers/BuildUnsignedConsolidation/TronTokenForm';
import { CoinsSelectAutocomplete } from '~/components';
import { buildUnsignedConsolidationCoins } from '~/helpers/config';
import { buildUnsignedConsolidationCoins, tokenParentCoins } from '~/helpers/config';
import { BackToHomeHelperText } from '~/components/BackToHomeHelperText';
import { ConsolidationRecoveryBatch } from '@bitgo/sdk-coin-trx';
import { useAlertBanner } from '~/contexts';
import { GenericEcdsaForm } from '~/containers/BuildUnsignedConsolidation/GenericEcdsaForm';
import { SolForm } from '~/containers/BuildUnsignedConsolidation/SolForm';
import { SolTokenForm } from '~/containers/BuildUnsignedConsolidation/SolTokenForm';
import { SuiTokenForm } from '~/containers/BuildUnsignedConsolidation/SuiTokenForm';

type ConsolidationFormProps = {
coin?: string;
Expand All @@ -25,10 +26,9 @@ type ConsolidationFormProps = {
function isRecoveryConsolidationTransaction(
result: any
): result is ConsolidationRecoveryBatch {
const consolidationRecoveryBatch = result as ConsolidationRecoveryBatch;
return (
consolidationRecoveryBatch &&
consolidationRecoveryBatch.transactions !== undefined
('txRequests' in result && !!result['txRequests']) ||
('transactions' in result && !!result['transactions'])
);
}

Expand Down Expand Up @@ -343,6 +343,60 @@ function ConsolidationForm({ coin, environment }: ConsolidationFormProps) {
console.log(e);
}

setSubmitting(false);
}
}}
/>
);
case 'suiToken':
case 'tsuiToken':
return (
<SuiTokenForm
onSubmit={async (values, { setSubmitting }) => {
setSubmitting(true);
try {
await window.commands.setBitGoEnvironment(environment);
const parentCoin = tokenParentCoins[coin];
const chainData = await window.queries.getChain(parentCoin);
const consolidateData = await window.commands.recoverConsolidations(parentCoin, {
...(await updateKeysFromIds(parentCoin, values)),
bitgoKey: values.bitgoKey.replace(/\s+/g, ''),
tokenContractAddress: values.packageId,
seed: values.seed,
});

if (consolidateData instanceof Error) {
throw consolidateData;
}

const showSaveDialogData = await window.commands.showSaveDialog({
filters: [
{
name: 'Custom File Type',
extensions: ['json'],
},
],
defaultPath: `~/${chainData}-unsigned-consolidation-${Date.now()}.json`,
});
if (!showSaveDialogData.filePath) {
throw new Error('No file path selected');
}

await window.commands.writeFile(
showSaveDialogData.filePath,
JSON.stringify(consolidateData, null, 2),
{ encoding: 'utf8' }
);
navigate(
`/${environment}/build-unsigned-consolidation/${coin}/success`
);
} catch (e) {
if (e instanceof Error) {
setAlert(e.message);
} else {
console.log(e);
}

setSubmitting(false);
}
}}
Expand Down
136 changes: 136 additions & 0 deletions src/containers/BuildUnsignedConsolidation/SuiTokenForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import { Form, FormikHelpers, FormikProvider, useFormik } from 'formik';
import { Link } from 'react-router-dom';
import * as Yup from 'yup';
import {
Button,
FormikPasswordfield,
FormikTextarea,
FormikTextfield,
} from '~/components';

const validationSchema = Yup.object({
userKey: Yup.string().required(),
backupKey: Yup.string().required(),
bitgoKey: Yup.string().required(),
packageId: Yup.string().required(),
walletPassphrase: Yup.string(),
startingScanIndex: Yup.number(),
endingScanIndex: Yup.number().moreThan(
Yup.ref('startingScanIndex'),
'Ending scan index must be greater than starting scan index'
),
seed: Yup.string(),
}).required();

export type SuiFormValues = Yup.Asserts<typeof validationSchema>;

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

export function SuiTokenForm({ onSubmit }: SuiTokenFormValues) {
const formik = useFormik<SuiFormValues>({
onSubmit,
initialValues: {
userKey: '',
backupKey: '',
bitgoKey: '',
packageId: '',
walletPassphrase: '',
startingScanIndex: 1,
endingScanIndex: 21,
seed: undefined,
},
});

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 or Hot wallet details
</h4>
<div className="tw-mb-4">
<FormikTextarea
HelperText="Your user public key, as found on your recovery KeyCard. Required for hot wallets."
Label="User Public Key (optional)"
name="userKey"
Width="fill"
/>
</div>
<div className="tw-mb-4">
<FormikTextfield
HelperText="Your user seed as found on your KeyCard as Key ID. Most wallets will not have this and you can leave it blank."
Label="Seed (optional)"
name="seed"
Width="fill"
/>
</div>
<div className="tw-mb-4">
<FormikTextarea
HelperText="The backup public key for the wallet, as found on your recovery KeyCard. Required for hot wallets."
Label="Backup Public Key (optional)"
name="backupKey"
Width="fill"
/>
</div>
<div className="tw-mb-4">
<FormikPasswordfield
HelperText="Your wallet passphrase, required for hot wallets."
Label="Wallet Passphrase (optional)"
name="walletPassphrase"
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 package ID of the SUI token to recover. This is unique to each token, and is NOT your wallet address."
Label="Package Id"
name="packageId"
Width="fill"
/>
</div>
<div className="tw-mb-4">
<FormikTextfield
HelperText="The starting index (inclusive) of addresses to consolidate"
Label="Starting Scan Index"
name="startingScanIndex"
Width="fill"
/>
</div>
<div className="tw-mb-4">
<FormikTextfield
HelperText="The ending index (exclusive) of addresses to consolidate"
Label="Ending Scan Index"
name="endingScanIndex"
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 ? 'Consolidating...' : 'Consolidate Funds'}
</Button>
</div>
</Form>
</FormikProvider>
);
}
Loading

0 comments on commit ecb6047

Please sign in to comment.