Skip to content

Commit

Permalink
feat(sui): broadcast transaction
Browse files Browse the repository at this point in the history
Ticket: WIN-3289
  • Loading branch information
bhavidhingra committed Aug 20, 2024
1 parent e91d00b commit 36a65a6
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 3 deletions.
3 changes: 3 additions & 0 deletions electron/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +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';

export type createAdaBroadcastableSweepTransactionParameters =
| Parameters<Ada['createBroadcastableSweepTransaction']>[0]
Expand Down Expand Up @@ -34,6 +35,8 @@ export type BroadcastTransactionOptions = Awaited<
| Parameters<Thbar['broadcastTransaction']>[0]
| Parameters<Algo['broadcastTransaction']>[0]
| Parameters<Talgo['broadcastTransaction']>[0]
| Parameters<Sui['broadcastTransaction']>[0]
| Parameters<Tsui['broadcastTransaction']>[0]
>;

export type BroadcastTransactionResult = Awaited<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { broadcastTransactionCoins } from '~/helpers/config';
import { HederaForm } from './HederaForm';
import { BackToHomeHelperText } from '~/components/BackToHomeHelperText';
import { AlgorandForm } from '~/containers/BroadcastTransactionCoin/AlgorandForm';
import { SuiForm } from '~/containers/BroadcastTransactionCoin/SuiForm';

function Form() {
const { env, coin } = useParams<'env' | 'coin'>();
Expand Down Expand Up @@ -100,6 +101,56 @@ function Form() {
{ encoding: 'utf-8' }
);

navigate(
`/${bitGoEnvironment}/broadcast-transaction/${coin}/success`
);
} catch (err) {
if (err instanceof Error) {
setAlert(err.message);
} else {
console.error(err);
}
setSubmitting(false);
}
}}
/>
);
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,

Check failure on line 132 in src/containers/BroadcastTransactionCoin/BroadcastTransactionCoin.tsx

View workflow job for this annotation

GitHub Actions / test

Argument of type '{ serializedSignedTransaction: string; signature: string; }' is not assignable to parameter of type 'BroadcastTransactionOptions'.
});
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`
);
Expand Down
69 changes: 69 additions & 0 deletions src/containers/BroadcastTransactionCoin/SuiForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
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({
serializedSignedTx: Yup.string().required(),
signature: Yup.string().required(),
}).required();

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

type SuiFormValues = Yup.Asserts<typeof validationSchema>;

export function SuiForm({ onSubmit }: SuiFormProps) {
const formik = useFormik<SuiFormValues>({
onSubmit,
initialValues: {
serializedSignedTx: '',
signature: '',
},
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">
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"
Width="fill"
/>
</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>
</Form>
</FormikProvider>
);
}
4 changes: 2 additions & 2 deletions src/helpers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -859,8 +859,8 @@ export const broadcastTransactionCoins: Record<
BitgoEnv,
readonly CoinMetadata[]
> = {
prod: [allCoinMetas.hbar, allCoinMetas.algo] as const,
test: [allCoinMetas.thbar, allCoinMetas.talgo] as const,
prod: [allCoinMetas.hbar, allCoinMetas.algo, allCoinMetas.sui] as const,
test: [allCoinMetas.thbar, allCoinMetas.talgo, allCoinMetas.tsui] as const,
};

export type WalletMetadata = {
Expand Down
7 changes: 6 additions & 1 deletion src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +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-beta/sdk-coin-sui';

export type createAdaBroadcastableSweepTransactionParameters =
| Parameters<Ada['createBroadcastableSweepTransaction']>[0]
Expand Down Expand Up @@ -34,14 +35,18 @@ export type BroadcastTransactionOptions = Awaited<
| Parameters<Thbar['broadcastTransaction']>[0]
| Parameters<Algo['broadcastTransaction']>[0]
| Parameters<Talgo['broadcastTransaction']>[0]
| Parameters<Sui['broadcastTransaction']>[0]
| Parameters<Tsui['broadcastTransaction']>[0]
>;

export type BroadcastTransactionResult = Awaited<
ReturnType<
| Hbar['broadcastTransaction']
| Thbar['broadcastTransaction']
| Algo['broadcastTransaction']
| Talgo['broadcastTransaction']>
| Talgo['broadcastTransaction']
| Sui['broadcastTransaction']
| Tsui['broadcastTransaction']>
>;

export type AdaRecoveryConsolidationRecoveryOptions =
Expand Down

0 comments on commit 36a65a6

Please sign in to comment.