Skip to content

Commit

Permalink
fix: broadcastSignedTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
devchenyan committed Jan 14, 2024
1 parent 91fbcf7 commit d8416fd
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -46,7 +46,7 @@ const BroadcastTransaction = () => {

setIsBroadcasting(true)

const res = await broadcastTransactionOnly({
const res = await broadcastSignedTransaction({
...json,
})

Expand Down
13 changes: 3 additions & 10 deletions packages/neuron-ui/src/services/remote/offline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Controller.SUDTAccount, 'symbol' | 'tokenName' | 'accountName' | 'decimal' | 'tokenID'>
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<OfflineSignJSON, void>('export-transaction-as-json')
export const signTransactionOnly = remoteApi<OfflineSignJSON, void>('sign-transaction-only')
export const broadcastTransaction = remoteApi<BroadcastProps, void>('broadcast-transaction')
export const broadcastTransactionOnly = remoteApi<SignedTransaction, string>('broadcast-transaction-only')
export const broadcastSignedTransaction = remoteApi<SignedTransaction, string>('broadcast-signed-transaction')
export const signAndExportTransaction = remoteApi<SignProps, { filePath: string; json: OfflineSignJSON }>(
'sign-and-export-transaction'
)
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-ui/src/services/remote/remoteApiWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/neuron-wallet/src/controllers/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
45 changes: 1 addition & 44 deletions packages/neuron-wallet/src/controllers/offline-sign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
)
}
}
}
}
9 changes: 0 additions & 9 deletions packages/neuron-wallet/src/models/offline-sign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

1 comment on commit d8416fd

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Packaging for test is done in 7516548982

Please sign in to comment.