Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/neuron-wallet/src/controllers/wallets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
import i18n from 'utils/i18n'
import AddressService from 'services/addresses'
import WalletCreatedSubject from 'models/subjects/wallet-created-subject'
import logger from 'utils/logger'

/**
* @class WalletsController
Expand Down Expand Up @@ -369,6 +370,7 @@ export default class WalletsController {
result: hash,
}
} catch (err) {
logger.error(`sendCapacity:`, err)
return {
status: ResponseCode.Fail,
message: `Error: "${err.message}"`,
Expand Down
21 changes: 18 additions & 3 deletions packages/neuron-wallet/src/listeners/tx-status.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { remote } from 'electron'
import { interval } from 'rxjs'
import { getConnection } from 'typeorm'
import Core from '@nervosnetwork/ckb-sdk-core'
import { TransactionStatus } from 'types/cell-types'
import LockUtils from 'models/lock-utils'
import AddressesUsedSubject from 'models/subjects/addresses-used-subject'
import { FailedTransaction, TransactionPersistor } from 'services/tx'
import { CONNECTION_NOT_FOUND_NAME } from 'database/chain/ormconfig'
import TypeConvert from 'types/type-convert'
import GetBlocks from 'services/sync/get-blocks'

const { nodeService } = remote.require('./startup/sync-block-task/params')

Expand All @@ -17,17 +19,20 @@ const getTransactionStatus = async (hash: string) => {
return {
tx,
status: TransactionStatus.Failed,
blockHash: null,
}
}
if (tx.txStatus.status === 'committed') {
return {
tx: tx.transaction,
status: TransactionStatus.Success,
blockHash: tx.txStatus.blockHash,
}
}
return {
tx: tx.transaction,
status: TransactionStatus.Pending,
blockHash: null,
}
}

Expand All @@ -46,6 +51,7 @@ const trackingStatus = async () => {
hash,
tx: txWithStatus.tx,
status: txWithStatus.status,
blockHash: txWithStatus.blockHash,
}
})
)
Expand All @@ -58,9 +64,18 @@ const trackingStatus = async () => {
AddressesUsedSubject.getSubject().next(usedAddresses)
}

for (const successTx of successTxs) {
const transaction = TypeConvert.toTransaction(successTx.tx)
await TransactionPersistor.saveFetchTx(transaction)
if (successTxs.length > 0) {
const { core }: { core: Core } = nodeService
const getBlockService = new GetBlocks(core.rpc.node.url)
for (const successTx of successTxs) {
const transaction = TypeConvert.toTransaction(successTx.tx)
const { blockHash } = successTx
const blockHeader = await getBlockService.getHeader(blockHash!)
transaction.blockHash = blockHash!
transaction.blockNumber = blockHeader.number
transaction.timestamp = blockHeader.timestamp
await TransactionPersistor.saveFetchTx(transaction)
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion packages/neuron-wallet/src/services/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ export default class AddressService {
AddressPrefix.Mainnet
).address

const blake160: string = LockUtils.addressToBlake160(testnetAddress)
const addressToParse = env.testnet ? testnetAddress : mainnetAddress

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Any plan to move this out of Env, placing into its own storage/class?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will do this later, don't know how to judge mainnet now.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

got that.

const blake160: string = LockUtils.addressToBlake160(addressToParse)

const testnetAddressInfo = {
walletId: addressMetaInfo.walletId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ export class TransactionPersistor {
)
let txEntity: TransactionEntity
if (saveType === TxSaveType.Sent) {
txEntity = await TransactionPersistor.saveWithSent(transaction)
txEntity = await TransactionPersistor.saveWithSent(tx)
} else if (saveType === TxSaveType.Fetch) {
txEntity = await TransactionPersistor.saveWithFetch(transaction)
txEntity = await TransactionPersistor.saveWithFetch(tx)
} else {
throw new Error('Error TxSaveType!')
}
Expand Down