Skip to content

Commit

Permalink
Merge pull request #403 from BitGo/WP-1496-broadcast-algo-tx
Browse files Browse the repository at this point in the history
feat(wrw): update algo wrw and add support for broadcasting
  • Loading branch information
pranavjain97 authored Mar 1, 2024
2 parents 9bacf36 + 252d803 commit f77c51f
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 13 deletions.
3 changes: 3 additions & 0 deletions electron/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ada['createBroadcastableSweepTransaction']>[0]
Expand All @@ -31,6 +32,8 @@ export type BroadcastableSweepTransaction = Awaited<
export type BroadcastTransactionOptions = Awaited<
| Parameters<Hbar['broadcastTransaction']>[0]
| Parameters<Thbar['broadcastTransaction']>[0]
| Parameters<Algo['broadcastTransaction']>[0]
| Parameters<Talgo['broadcastTransaction']>[0]
>;

export type BroadcastTransactionResult = Awaited<
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
98 changes: 98 additions & 0 deletions src/containers/BroadcastTransactionCoin/AlgorandForm.tsx
Original file line number Diff line number Diff line change
@@ -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<AlgorandFormValues>
) => void | Promise<void>;
};

type AlgorandFormValues = Yup.Asserts<typeof validationSchema>;

export function AlgorandForm({ onSubmit }: AlgorandFormProps) {
const formik = useFormik<AlgorandFormValues>({
onSubmit,
initialValues: {
serializedSignedTx: '',
nodeParams: {
token: '',
baseServer: '',
port: 8443,
},
},
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>
<Form>
<h4 className="tw-text-body tw-font-semibold tw-border-b-0.5 tw-border-solid tw-border-gray-700 tw-mb-4">
Node Parameters
</h4>
<div className="tw-mb-4">
<FormikTextfield
HelperText="Token of the Algorand node you are connecting to."
Label="Algorand token"
name="nodeParams.token"
Width="fill"
/>
</div>
<div className="tw-mb-4">
<FormikTextfield
HelperText="Server address of the Algorand node you are connecting to."
Label="Node Server Address"
name="nodeParams.baseServer"
Width="fill"
/>
</div>
<div className="tw-mb-4">
<FormikTextfield
HelperText="Port of the Algorand node you are connecting to."
Label="Port"
name="nodeParams.port"
Width="fill"
/>
</div>
</Form>
<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>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'>();
Expand Down Expand Up @@ -63,6 +64,56 @@ function Form() {
}}
/>
);
case 'algo':
case 'talgo':
return (
<AlgorandForm
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,
});
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)}`);
}
Expand Down
10 changes: 3 additions & 7 deletions src/containers/BuildUnsignedSweepCoin/AlgorandForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -47,7 +43,7 @@ export function AlgorandForm({ onSubmit }: AlgorandFormProps) {
bitgoKey: '',
walletPassphrase: '',
fee: 1000,
firstRound: 0,
firstRound: undefined,
note: '',
nodeParams: {
token: '',
Expand Down Expand Up @@ -106,7 +102,7 @@ export function AlgorandForm({ onSubmit }: AlgorandFormProps) {
</div>
<div className="tw-mb-4">
<FormikTextfield
HelperText="The first round for when the transaction is valid. If the transaction is sent prior to this round it will be rejected by the network."
HelperText="The first round for when the transaction is valid. If not provided, the latest round from the node is used."
Label="First Round when the transaction should be valid"
name="firstRound"
Width="fill"
Expand Down
4 changes: 2 additions & 2 deletions src/containers/NonBitGoRecoveryCoin/AlgorandForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function AlgorandForm({ onSubmit }: AlgorandFormProps) {
bitgoKey: '',
walletPassphrase: '',
fee: 1000,
firstRound: 0,
firstRound: undefined,
note: '',
nodeParams: {
token: '',
Expand Down Expand Up @@ -123,7 +123,7 @@ export function AlgorandForm({ onSubmit }: AlgorandFormProps) {
</div>
<div className="tw-mb-4">
<FormikTextfield
HelperText="The first round for when the transaction is valid. If the transaction is sent prior to this round it will be rejected by the network."
HelperText="The first round for when the transaction is valid. If not provided, the latest round from the node is used."
Label="First Round when the transaction should be valid"
name="firstRound"
Width="fill"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ function Form() {
const chainData = await window.queries.getChain(coin);
const recoverData = await window.commands.recover(coin, {
...values,
bitgoKey: '',
bitgoKey: values.bitgoKey,
ignoreAddressTypes: [],
});
assert(
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
9 changes: 8 additions & 1 deletion src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ada['createBroadcastableSweepTransaction']>[0]
Expand All @@ -31,10 +32,16 @@ export type BroadcastableSweepTransaction = Awaited<
export type BroadcastTransactionOptions = Awaited<
| Parameters<Hbar['broadcastTransaction']>[0]
| Parameters<Thbar['broadcastTransaction']>[0]
| Parameters<Algo['broadcastTransaction']>[0]
| Parameters<Talgo['broadcastTransaction']>[0]
>;

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

export type AdaRecoveryConsolidationRecoveryOptions =
Expand Down

0 comments on commit f77c51f

Please sign in to comment.