From d8416fd9b9776107649e2ed8ae6ada96b9e482a0 Mon Sep 17 00:00:00 2001 From: devchenyan Date: Sun, 14 Jan 2024 10:58:23 +0800 Subject: [PATCH] fix: broadcastSignedTransaction --- .../components/BroadcastTransaction/index.tsx | 4 +- .../neuron-ui/src/services/remote/offline.ts | 13 ++---- .../src/services/remote/remoteApiWrapper.ts | 2 +- packages/neuron-wallet/src/controllers/api.ts | 4 +- .../src/controllers/offline-sign.ts | 45 +------------------ .../neuron-wallet/src/models/offline-sign.ts | 9 ---- 6 files changed, 9 insertions(+), 68 deletions(-) diff --git a/packages/neuron-ui/src/components/BroadcastTransaction/index.tsx b/packages/neuron-ui/src/components/BroadcastTransaction/index.tsx index 45083447a8..c807147633 100644 --- a/packages/neuron-ui/src/components/BroadcastTransaction/index.tsx +++ b/packages/neuron-ui/src/components/BroadcastTransaction/index.tsx @@ -5,7 +5,7 @@ import { isSuccessResponse, RoutePath, isMainnet as isMainnetUtil, useGoBack, ge import Dialog from 'widgets/Dialog' import AlertDialog from 'widgets/AlertDialog' import { useDispatch, useState as useGlobalState } from 'states' -import { broadcastTransactionOnly, OfflineSignStatus, openExternal, getTransactionList } from 'services/remote' +import { broadcastSignedTransaction, OfflineSignStatus, openExternal, getTransactionList } from 'services/remote' import { ReactComponent as HardWalletIcon } from 'widgets/Icons/HardWallet.svg' import styles from './broadcastTransaction.module.scss' @@ -46,7 +46,7 @@ const BroadcastTransaction = () => { setIsBroadcasting(true) - const res = await broadcastTransactionOnly({ + const res = await broadcastSignedTransaction({ ...json, }) diff --git a/packages/neuron-ui/src/services/remote/offline.ts b/packages/neuron-ui/src/services/remote/offline.ts index 5ef264228c..ca91db2187 100644 --- a/packages/neuron-ui/src/services/remote/offline.ts +++ b/packages/neuron-ui/src/services/remote/offline.ts @@ -34,23 +34,16 @@ export interface OfflineSignJSON { multisig_configs?: MultisigConfigs } -export interface SignedTransaction { - transaction: State.GeneratedTx - status: OfflineSignStatus.Signed - type: OfflineSignType - description?: string - asset_account?: Pick - multisig_configs?: MultisigConfigs -} - export type SignProps = OfflineSignJSON & { walletID: string; password: string; multisigConfig?: MultisigEntity } export type BroadcastProps = OfflineSignJSON & { walletID: string } +export type SignedTransaction = OfflineSignJSON & { status: OfflineSignStatus.Signed } + export const exportTransactionAsJSON = remoteApi('export-transaction-as-json') export const signTransactionOnly = remoteApi('sign-transaction-only') export const broadcastTransaction = remoteApi('broadcast-transaction') -export const broadcastTransactionOnly = remoteApi('broadcast-transaction-only') +export const broadcastSignedTransaction = remoteApi('broadcast-signed-transaction') export const signAndExportTransaction = remoteApi( 'sign-and-export-transaction' ) diff --git a/packages/neuron-ui/src/services/remote/remoteApiWrapper.ts b/packages/neuron-ui/src/services/remote/remoteApiWrapper.ts index 994aef368e..9ccc527c39 100644 --- a/packages/neuron-ui/src/services/remote/remoteApiWrapper.ts +++ b/packages/neuron-ui/src/services/remote/remoteApiWrapper.ts @@ -133,7 +133,7 @@ type Action = | 'export-transaction-as-json' | 'sign-transaction-only' | 'broadcast-transaction' - | 'broadcast-transaction-only' + | 'broadcast-signed-transaction' | 'sign-and-export-transaction' | 'sign-and-broadcast-transaction' // nft diff --git a/packages/neuron-wallet/src/controllers/api.ts b/packages/neuron-wallet/src/controllers/api.ts index 11a1ebe6cc..4c36e1747e 100644 --- a/packages/neuron-wallet/src/controllers/api.ts +++ b/packages/neuron-wallet/src/controllers/api.ts @@ -768,8 +768,8 @@ export default class ApiController { return this.#offlineSignController.broadcastTransaction(params) }) - handle('broadcast-transaction-only', async (_, params) => { - return this.#offlineSignController.broadcastTransactionOnly(params) + handle('broadcast-signed-transaction', async (_, params) => { + return this.#offlineSignController.broadcastTransaction({ ...params, walletID: '' }) }) handle('sign-and-export-transaction', async (_, params) => { diff --git a/packages/neuron-wallet/src/controllers/offline-sign.ts b/packages/neuron-wallet/src/controllers/offline-sign.ts index 50756bb8da..1ca40ba019 100644 --- a/packages/neuron-wallet/src/controllers/offline-sign.ts +++ b/packages/neuron-wallet/src/controllers/offline-sign.ts @@ -3,7 +3,7 @@ import path from 'path' import { dialog } from 'electron' import { t } from 'i18next' import { ResponseCode } from '../utils/const' -import OfflineSign, { SignType, OfflineSignJSON, SignStatus, SignedTransaction } from '../models/offline-sign' +import OfflineSign, { SignType, OfflineSignJSON, SignStatus } from '../models/offline-sign' import TransactionSender from '../services/transaction-sender' import Transaction from '../models/chain/transaction' import AssetAccountController from './asset-account' @@ -196,47 +196,4 @@ export default class OfflineSignController { } } } - - public async broadcastTransactionOnly({ - transaction, - type, - asset_account: assetAccount, - description, - }: SignedTransaction) { - const tx = Transaction.fromObject(transaction) - switch (type) { - case SignType.CreateSUDTAccount: { - return new AssetAccountController().sendCreateTx( - { - walletID: '', - assetAccount: assetAccount!, - tx, - password: '', - }, - true - ) - } - case SignType.SendSUDT: { - return new AnyoneCanPayController().sendTx( - { - walletID: '', - tx, - password: '', - }, - true - ) - } - default: { - return new WalletsController().sendTx( - { - walletID: '', - tx, - password: '', - description, - }, - true - ) - } - } - } } diff --git a/packages/neuron-wallet/src/models/offline-sign.ts b/packages/neuron-wallet/src/models/offline-sign.ts index 4bb4946ae8..2fd73a0d93 100644 --- a/packages/neuron-wallet/src/models/offline-sign.ts +++ b/packages/neuron-wallet/src/models/offline-sign.ts @@ -46,15 +46,6 @@ export interface OfflineSignJSON { multisig_configs?: MultisigConfigs } -export interface SignedTransaction { - transaction: Transaction - status: SignStatus.Signed - type: SignType - description?: string - asset_account?: AssetAccount - multisig_configs?: MultisigConfigs -} - export default class OfflineSign implements OfflineSignProps { public transaction: Transaction public assetAccount?: AssetAccount