From 36a65a61d672a145e69ea8d79fcf6dea0927ba49 Mon Sep 17 00:00:00 2001 From: Bhavi Dhingra Date: Wed, 7 Aug 2024 01:15:19 +0530 Subject: [PATCH] feat(sui): broadcast transaction Ticket: WIN-3289 --- electron/types.ts | 3 + .../BroadcastTransactionCoin.tsx | 51 ++++++++++++++ .../BroadcastTransactionCoin/SuiForm.tsx | 69 +++++++++++++++++++ src/helpers/config.ts | 4 +- src/utils/types.ts | 7 +- 5 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 src/containers/BroadcastTransactionCoin/SuiForm.tsx diff --git a/electron/types.ts b/electron/types.ts index 8378ec4f..542b317f 100644 --- a/electron/types.ts +++ b/electron/types.ts @@ -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[0] @@ -34,6 +35,8 @@ export type BroadcastTransactionOptions = Awaited< | Parameters[0] | Parameters[0] | Parameters[0] + | Parameters[0] + | Parameters[0] >; export type BroadcastTransactionResult = Awaited< diff --git a/src/containers/BroadcastTransactionCoin/BroadcastTransactionCoin.tsx b/src/containers/BroadcastTransactionCoin/BroadcastTransactionCoin.tsx index e028223c..5135d589 100644 --- a/src/containers/BroadcastTransactionCoin/BroadcastTransactionCoin.tsx +++ b/src/containers/BroadcastTransactionCoin/BroadcastTransactionCoin.tsx @@ -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'>(); @@ -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 ( + { + 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` ); diff --git a/src/containers/BroadcastTransactionCoin/SuiForm.tsx b/src/containers/BroadcastTransactionCoin/SuiForm.tsx new file mode 100644 index 00000000..a6b342a3 --- /dev/null +++ b/src/containers/BroadcastTransactionCoin/SuiForm.tsx @@ -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 + ) => void | Promise; +}; + +type SuiFormValues = Yup.Asserts; + +export function SuiForm({ onSubmit }: SuiFormProps) { + const formik = useFormik({ + onSubmit, + initialValues: { + serializedSignedTx: '', + signature: '', + }, + validationSchema, + }); + + return ( + +
+

+ Transaction +

+
+ +
+
+ +
+
+ + +
+
+
+ ); +} diff --git a/src/helpers/config.ts b/src/helpers/config.ts index 07139307..6afb8baa 100644 --- a/src/helpers/config.ts +++ b/src/helpers/config.ts @@ -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 = { diff --git a/src/utils/types.ts b/src/utils/types.ts index 81a7ae74..910a5953 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -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[0] @@ -34,6 +35,8 @@ export type BroadcastTransactionOptions = Awaited< | Parameters[0] | Parameters[0] | Parameters[0] + | Parameters[0] + | Parameters[0] >; export type BroadcastTransactionResult = Awaited< @@ -41,7 +44,9 @@ export type BroadcastTransactionResult = Awaited< | Hbar['broadcastTransaction'] | Thbar['broadcastTransaction'] | Algo['broadcastTransaction'] - | Talgo['broadcastTransaction']> + | Talgo['broadcastTransaction'] + | Sui['broadcastTransaction'] + | Tsui['broadcastTransaction']> >; export type AdaRecoveryConsolidationRecoveryOptions =