Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
bhavidhingra committed Aug 9, 2024
2 parents 3d5fed3 + 3c2b484 commit b4260f3
Show file tree
Hide file tree
Showing 9 changed files with 917 additions and 658 deletions.
2 changes: 1 addition & 1 deletion electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import { join } from 'path';
import * as ecc from 'tiny-secp256k1';
import { Hbar, Thbar } from '@bitgo/sdk-coin-hbar';
import { Algo, Talgo } from '@bitgo/sdk-coin-algo';
import { Sui, Tsui } from '@bitgo/sdk-coin-sui';
import { Sui, Tsui } from '@bitgo-beta/sdk-coin-sui';

const bip32 = BIP32Factory(ecc);

Expand Down
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/sdk-coin-sui';
import { Sui, Tsui } from '@bitgo-beta/sdk-coin-sui';

export type createAdaBroadcastableSweepTransactionParameters =
| Parameters<Ada['createBroadcastableSweepTransaction']>[0]
Expand Down
1,260 changes: 746 additions & 514 deletions package-lock.json

Large diffs are not rendered by default.

80 changes: 40 additions & 40 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,46 @@
}
},
"dependencies": {
"@bitgo/abstract-cosmos": "10.0.24",
"@bitgo/abstract-utxo": "8.9.0",
"@bitgo/sdk-api": "1.50.0",
"@bitgo/sdk-coin-ada": "4.2.2",
"@bitgo/sdk-coin-algo": "2.1.22",
"@bitgo/sdk-coin-arbeth": "21.0.16",
"@bitgo/sdk-coin-atom": "12.0.24",
"@bitgo/sdk-coin-avaxc": "5.0.16",
"@bitgo/sdk-coin-bch": "2.0.24",
"@bitgo/sdk-coin-bcha": "2.1.8",
"@bitgo/sdk-coin-bld": "2.0.24",
"@bitgo/sdk-coin-bsc": "22.1.8",
"@bitgo/sdk-coin-bsv": "2.0.24",
"@bitgo/sdk-coin-btc": "2.0.24",
"@bitgo/sdk-coin-btg": "2.0.24",
"@bitgo/sdk-coin-coreum": "20.0.24",
"@bitgo/sdk-coin-dash": "2.0.24",
"@bitgo/sdk-coin-doge": "2.0.24",
"@bitgo/sdk-coin-dot": "4.1.2",
"@bitgo/sdk-coin-eos": "2.1.17",
"@bitgo/sdk-coin-eth": "24.2.13",
"@bitgo/sdk-coin-ethw": "20.0.24",
"@bitgo/sdk-coin-hash": "2.0.24",
"@bitgo/sdk-coin-hbar": "2.0.24",
"@bitgo/sdk-coin-injective": "2.0.24",
"@bitgo/sdk-coin-ltc": "3.0.24",
"@bitgo/sdk-coin-near": "2.0.24",
"@bitgo/sdk-coin-opeth": "18.1.9",
"@bitgo/sdk-coin-osmo": "2.0.24",
"@bitgo/sdk-coin-polygon": "20.5.8",
"@bitgo/sdk-coin-sei": "2.0.24",
"@bitgo/sdk-coin-sol": "4.3.2",
"@bitgo/sdk-coin-sui": "5.4.0",
"@bitgo/sdk-coin-tia": "2.1.10",
"@bitgo/sdk-coin-trx": "2.0.24",
"@bitgo/sdk-coin-xlm": "3.1.2",
"@bitgo/sdk-coin-xrp": "2.1.5",
"@bitgo/sdk-coin-zec": "2.0.24",
"@bitgo/sdk-coin-zeta": "2.0.24",
"@bitgo/utxo-lib": "9.39.0",
"@bitgo-beta/sdk-coin-sui": "^1.4.1-alpha.168",
"@bitgo/abstract-cosmos": "10.1.0",
"@bitgo/abstract-utxo": "8.12.0",
"@bitgo/sdk-api": "1.51.3",
"@bitgo/sdk-coin-ada": "4.2.7",
"@bitgo/sdk-coin-algo": "2.1.27",
"@bitgo/sdk-coin-arbeth": "21.0.21",
"@bitgo/sdk-coin-atom": "12.1.0",
"@bitgo/sdk-coin-avaxc": "5.0.21",
"@bitgo/sdk-coin-bch": "2.0.29",
"@bitgo/sdk-coin-bcha": "2.1.13",
"@bitgo/sdk-coin-bld": "2.0.29",
"@bitgo/sdk-coin-bsc": "22.1.13",
"@bitgo/sdk-coin-bsv": "2.0.29",
"@bitgo/sdk-coin-btc": "2.2.0",
"@bitgo/sdk-coin-btg": "2.0.29",
"@bitgo/sdk-coin-coreum": "20.0.29",
"@bitgo/sdk-coin-dash": "2.0.29",
"@bitgo/sdk-coin-doge": "2.0.29",
"@bitgo/sdk-coin-dot": "4.1.7",
"@bitgo/sdk-coin-eos": "2.1.22",
"@bitgo/sdk-coin-eth": "24.2.18",
"@bitgo/sdk-coin-ethw": "20.0.29",
"@bitgo/sdk-coin-hash": "2.0.29",
"@bitgo/sdk-coin-hbar": "2.0.29",
"@bitgo/sdk-coin-injective": "2.0.29",
"@bitgo/sdk-coin-ltc": "3.0.29",
"@bitgo/sdk-coin-near": "2.0.29",
"@bitgo/sdk-coin-opeth": "18.1.14",
"@bitgo/sdk-coin-osmo": "2.0.29",
"@bitgo/sdk-coin-polygon": "20.5.13",
"@bitgo/sdk-coin-sei": "2.0.29",
"@bitgo/sdk-coin-sol": "4.4.3",
"@bitgo/sdk-coin-tia": "2.1.15",
"@bitgo/sdk-coin-trx": "2.0.29",
"@bitgo/sdk-coin-xlm": "3.2.3",
"@bitgo/sdk-coin-xrp": "2.1.10",
"@bitgo/sdk-coin-zec": "2.0.29",
"@bitgo/sdk-coin-zeta": "2.0.29",
"@bitgo/utxo-lib": "10.1.0",
"@ethereumjs/common": "2.6.5",
"@lottiefiles/react-lottie-player": "3.4.9",
"clsx": "1.2.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,54 +117,7 @@ function Form() {
);
case 'sui':
case 'tsui':
return (
<SuiForm
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 broadcastResult =
await window.commands.broadcastTransaction(coin, {
serializedSignedTransaction: values.serializedSignedTx,
signature: values.signature,
});
const showSaveDialogData = await window.commands.showSaveDialog({
filters: [
{
name: 'Custom File Type',
extensions: ['json'],
},
],
defaultPath: `~/${chainData}-broadcast-transaction-${Date.now()}.json`,
});

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

await window.commands.writeFile(
showSaveDialogData.filePath,
JSON.stringify(broadcastResult, null, 2),
{ encoding: 'utf-8' }
);

navigate(
`/${bitGoEnvironment}/broadcast-transaction/${coin}/success`
);
} catch (err) {
if (err instanceof Error) {
setAlert(err.message);
} else {
console.error(err);
}
setSubmitting(false);
}
}}
/>
);
return ( <SuiForm /> );

default:
throw new Error(`Unsupported coin: ${String(coin)}`);
Expand Down
161 changes: 111 additions & 50 deletions src/containers/BroadcastTransactionCoin/SuiForm.tsx
Original file line number Diff line number Diff line change
@@ -1,68 +1,129 @@
import { Form, FormikHelpers, FormikProvider, useFormik } from 'formik';
import { Link } from 'react-router-dom';
import { Form, FormikProvider, useFormik } from 'formik';
import { useNavigate, useParams } from 'react-router-dom';
import * as Yup from 'yup';
import { Button, FormikTextfield } from '~/components';
import { Button } from '~/components';
import { FormikFilefield } from '~/components/FormikFilefield';
import { useAlertBanner } from '~/contexts';
import { assert, safeEnv } from '~/helpers';
import {
BroadcastTransactionResult,
suiBroadcastTransactionParameters,
} from '~/utils/types';

const validationSchema = Yup.object({
serializedSignedTx: Yup.string().required(),
signature: Yup.string().required(),
}).required();

export type SuiFormProps = {
onSubmit: (
values: SuiFormValues,
formikHelpers: FormikHelpers<SuiFormValues>
) => void | Promise<void>;
};
function hasBroadcastableTransactions(
json: unknown
): json is
| suiBroadcastTransactionParameters {
const data = json as
| suiBroadcastTransactionParameters;
return (
data &&
data.transactions &&
data.transactions.length > 0
);
}

type SuiFormValues = Yup.Asserts<typeof validationSchema>;
export function SuiForm() {
const { env, coin } = useParams<'env' | 'coin'>();
const [, setAlert] = useAlertBanner();

export function SuiForm({ onSubmit }: SuiFormProps) {
const formik = useFormik<SuiFormValues>({
onSubmit,
const environment = safeEnv(env);
const navigate = useNavigate();
const formik = useFormik<{ file?: File }>({
initialValues: {
serializedSignedTx: '',
signature: '',
file: undefined,
},
validationSchema,
onSubmit: async (values, formikHelpers) => {
if (values.file) {
formikHelpers.setSubmitting(true);
await window.commands.setBitGoEnvironment(environment);
const fileReader = new FileReader();
fileReader.readAsText(values.file, 'UTF-8');
fileReader.onload = async event => {
try {
const data = JSON.parse(event.target?.result as string) as
| suiBroadcastTransactionParameters;

console.log(data);
assert(hasBroadcastableTransactions(data), 'Broadcastable transactions not found');

const chainData = await window.queries.getChain(coin!);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const broadcastResult: Error | BroadcastTransactionResult =
await window.commands.broadcastTransaction(
coin!,
data
);

if (broadcastResult instanceof Error) {
throw broadcastResult;
}

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

await window.commands.writeFile(
showSaveDialogData.filePath,
JSON.stringify(broadcastResult, null, 2),
{ encoding: 'utf8' }
);
navigate(
`/${environment}/broadcast-transaction/${coin}/success`
);
} catch (error) {
if (error instanceof Error) {
formikHelpers.setFieldError('file', error.message);
setAlert(error.message);
} else {
console.log(error);
}
formikHelpers.setSubmitting(false);
}
};
} else {
formikHelpers.setFieldError('file', 'File is required');
}
},
validationSchema: Yup.object({
file: Yup.mixed().required('File is required'),
}).required(),
});

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">
Transaction
</h4>
<div className="tw-mb-4">
<FormikTextfield
HelperText="Your built and signed recovery transaction in base64 format."
Label="Serialized and Signed Recovery Transaction"
name="serializedSignedTx"
<FormikFilefield
name="file"
accept=".json"
Width="fill"
Label="Upload Broadcast Transaction(s)"
onChange={event => {
formik
.setFieldValue('file', event.currentTarget.files?.[0])
.catch(console.error);
}}
/>
</div>
<div className="tw-mb-4">
<FormikTextfield
HelperText="Transaction signature in base64 format."
Label="Signature"
name="signature"
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 ? 'Broadcasting...' : 'Broadcast Transaction'}
</Button>
</div>
<Button
Variant="primary"
Width="fill"
type="submit"
Disabled={formik.isSubmitting || !formik.values.file}
disabled={formik.isSubmitting || !formik.values.file}
>
Broadcast Transaction(s)
</Button>
</Form>
</FormikProvider>
);
Expand Down
12 changes: 10 additions & 2 deletions src/helpers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -786,8 +786,16 @@ export const evmCCRWrongChainCoins: Record<BitgoEnv, readonly CoinMetadata[]> =

export const evmCCRIntendedChainCoins: Record<string, readonly CoinMetadata[]> =
{
polygon: [allCoinMetas.eth] as const,
tpolygon: [allCoinMetas.hteth] as const,
polygon: [
allCoinMetas.eth,
allCoinMetas.arbeth,
allCoinMetas.opeth,
] as const,
tpolygon: [
allCoinMetas.hteth,
allCoinMetas.tarbeth,
allCoinMetas.topeth,
] as const,
eth: [
allCoinMetas.polygon,
allCoinMetas.arbeth,
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ export function isRecoveryTransaction(
('transaction' in value && !!value['transaction']) ||
('txid' in value && !!value['txid']) ||
('serializedTx' in value && !!value['serializedTx']) ||
('txRequests' in value && !!value['txRequests'])
('txRequests' in value && !!value['txRequests']) ||
('transactions' in value && !!value['transactions'])
);
}

Expand Down
6 changes: 5 additions & 1 deletion src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '@bitgo/sdk-coin-trx';
import { Hbar, Thbar } from '@bitgo/sdk-coin-hbar';
import { Algo, Talgo } from '@bitgo/sdk-coin-algo';
import { Sui, Tsui } from '@bitgo/sdk-coin-sui';
import { Sui, Tsui } from '@bitgo-beta/sdk-coin-sui';

export type createAdaBroadcastableSweepTransactionParameters =
| Parameters<Ada['createBroadcastableSweepTransaction']>[0]
Expand All @@ -30,6 +30,10 @@ export type BroadcastableSweepTransaction = Awaited<
>
>;

export type suiBroadcastTransactionParameters =
| Parameters<Sui['broadcastTransaction']>[0]
| Parameters<Tsui['broadcastTransaction']>[0];

export type BroadcastTransactionOptions = Awaited<
| Parameters<Hbar['broadcastTransaction']>[0]
| Parameters<Thbar['broadcastTransaction']>[0]
Expand Down

0 comments on commit b4260f3

Please sign in to comment.