From 1a44dd7f0e792a8a87f9585b6b3575e3684e9302 Mon Sep 17 00:00:00 2001 From: Pranav Jain Date: Wed, 21 Feb 2024 15:41:36 +0530 Subject: [PATCH 1/2] feat(wrw): update recovery support for algo Ticket: WP-1467 --- package-lock.json | 1 + package.json | 1 + src/containers/BuildUnsignedSweepCoin/AlgorandForm.tsx | 10 +++------- src/containers/NonBitGoRecoveryCoin/AlgorandForm.tsx | 4 ++-- .../NonBitGoRecoveryCoin/NonBitGoRecoveryCoin.tsx | 2 +- 5 files changed, 8 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 34794125..81c4fbb8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "@bitgo/abstract-utxo": "7.0.2", "@bitgo/sdk-api": "1.43.2", "@bitgo/sdk-coin-ada": "2.36.2", + "@bitgo/sdk-coin-algo": "1.27.1", "@bitgo/sdk-coin-arbeth": "19.0.2", "@bitgo/sdk-coin-atom": "11.0.2", "@bitgo/sdk-coin-avaxc": "2.28.2", diff --git a/package.json b/package.json index 9d9bea7f..2b6c5c2f 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "@bitgo/sdk-coin-xrp": "1.8.3", "@bitgo/sdk-coin-zec": "1.6.3", "@bitgo/sdk-coin-zeta": "1.30.2", + "@bitgo/sdk-coin-algo": "1.27.1", "@bitgo/utxo-lib": "9.34.0", "@ethereumjs/common": "2.6.5", "@lottiefiles/react-lottie-player": "3.4.9", diff --git a/src/containers/BuildUnsignedSweepCoin/AlgorandForm.tsx b/src/containers/BuildUnsignedSweepCoin/AlgorandForm.tsx index ae2ff298..261108d4 100644 --- a/src/containers/BuildUnsignedSweepCoin/AlgorandForm.tsx +++ b/src/containers/BuildUnsignedSweepCoin/AlgorandForm.tsx @@ -14,11 +14,7 @@ const validationSchema = Yup.object({ bitgoKey: Yup.string().optional(), walletPassphrase: Yup.string().optional(), fee: Yup.number().required(), - firstRound: Yup.number().optional() - .typeError('firstRound must be a number') - .integer() - .positive('firstRound must be a positive integer') - .required(), + firstRound: Yup.number().optional(), note: Yup.string().optional(), nodeParams: Yup.object({ token: Yup.string().required(), @@ -47,7 +43,7 @@ export function AlgorandForm({ onSubmit }: AlgorandFormProps) { bitgoKey: '', walletPassphrase: '', fee: 1000, - firstRound: 0, + firstRound: undefined, note: '', nodeParams: { token: '', @@ -106,7 +102,7 @@ export function AlgorandForm({ onSubmit }: AlgorandFormProps) {
Date: Thu, 29 Feb 2024 16:40:32 +0530 Subject: [PATCH 2/2] feat(wrw): add broadcast tx support for algo Ticket: WP-1496 --- electron/types.ts | 3 + .../BroadcastTransactionCoin/AlgorandForm.tsx | 98 +++++++++++++++++++ .../BroadcastTransactionCoin.tsx | 51 ++++++++++ src/helpers/config.ts | 4 +- src/utils/types.ts | 9 +- 5 files changed, 162 insertions(+), 3 deletions(-) create mode 100644 src/containers/BroadcastTransactionCoin/AlgorandForm.tsx diff --git a/electron/types.ts b/electron/types.ts index 008b5ea2..8378ec4f 100644 --- a/electron/types.ts +++ b/electron/types.ts @@ -6,6 +6,7 @@ import { Ada, Tada } from '@bitgo/sdk-coin-ada'; 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'; export type createAdaBroadcastableSweepTransactionParameters = | Parameters[0] @@ -31,6 +32,8 @@ export type BroadcastableSweepTransaction = Awaited< export type BroadcastTransactionOptions = Awaited< | Parameters[0] | Parameters[0] + | Parameters[0] + | Parameters[0] >; export type BroadcastTransactionResult = Awaited< diff --git a/src/containers/BroadcastTransactionCoin/AlgorandForm.tsx b/src/containers/BroadcastTransactionCoin/AlgorandForm.tsx new file mode 100644 index 00000000..e9d79553 --- /dev/null +++ b/src/containers/BroadcastTransactionCoin/AlgorandForm.tsx @@ -0,0 +1,98 @@ +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(), + nodeParams: Yup.object({ + token: Yup.string().required(), + baseServer: Yup.string().required(), + port: Yup.number().required(), + }), +}).required(); + +export type AlgorandFormProps = { + onSubmit: ( + values: AlgorandFormValues, + formikHelpers: FormikHelpers + ) => void | Promise; +}; + +type AlgorandFormValues = Yup.Asserts; + +export function AlgorandForm({ onSubmit }: AlgorandFormProps) { + const formik = useFormik({ + onSubmit, + initialValues: { + serializedSignedTx: '', + nodeParams: { + token: '', + baseServer: '', + port: 8443, + }, + }, + validationSchema, + }); + + return ( + +
+

+ Transaction +

+
+ +
+ +

+ Node Parameters +

+
+ +
+
+ +
+
+ +
+
+
+ + +
+ +
+ ); +} diff --git a/src/containers/BroadcastTransactionCoin/BroadcastTransactionCoin.tsx b/src/containers/BroadcastTransactionCoin/BroadcastTransactionCoin.tsx index 758445f5..a2c0703c 100644 --- a/src/containers/BroadcastTransactionCoin/BroadcastTransactionCoin.tsx +++ b/src/containers/BroadcastTransactionCoin/BroadcastTransactionCoin.tsx @@ -5,6 +5,7 @@ import { safeEnv } from '~/helpers'; import { broadcastTransactionCoins } from '~/helpers/config'; import { HederaForm } from './HederaForm'; import { BackToHomeHelperText } from '~/components/BackToHomeHelperText'; +import { AlgorandForm } from '~/containers/BroadcastTransactionCoin/AlgorandForm'; function Form() { const { env, coin } = useParams<'env' | 'coin'>(); @@ -63,6 +64,56 @@ function Form() { }} /> ); + case 'algo': + case 'talgo': + 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, + }); + 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); + } + }} + /> + ); + default: throw new Error(`Unsupported coin: ${String(coin)}`); } diff --git a/src/helpers/config.ts b/src/helpers/config.ts index debbb005..0c579c1e 100644 --- a/src/helpers/config.ts +++ b/src/helpers/config.ts @@ -651,8 +651,8 @@ export const broadcastTransactionCoins: Record< BitgoEnv, readonly CoinMetadata[] > = { - prod: [allCoinMetas.hbar] as const, - test: [allCoinMetas.thbar] as const, + prod: [allCoinMetas.hbar, allCoinMetas.algo] as const, + test: [allCoinMetas.thbar, allCoinMetas.talgo] as const, }; export type WalletMetadata = { diff --git a/src/utils/types.ts b/src/utils/types.ts index 42f8a8dc..81a7ae74 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -6,6 +6,7 @@ import { ConsolidationRecoveryOptions, } from '@bitgo/sdk-coin-trx'; import { Hbar, Thbar } from '@bitgo/sdk-coin-hbar'; +import { Algo, Talgo } from '@bitgo/sdk-coin-algo'; export type createAdaBroadcastableSweepTransactionParameters = | Parameters[0] @@ -31,10 +32,16 @@ export type BroadcastableSweepTransaction = Awaited< export type BroadcastTransactionOptions = Awaited< | Parameters[0] | Parameters[0] + | Parameters[0] + | Parameters[0] >; export type BroadcastTransactionResult = Awaited< - ReturnType + ReturnType< + | Hbar['broadcastTransaction'] + | Thbar['broadcastTransaction'] + | Algo['broadcastTransaction'] + | Talgo['broadcastTransaction']> >; export type AdaRecoveryConsolidationRecoveryOptions =