Skip to content

Commit 2afc7e7

Browse files
committed
fix: connection not found when delete wallet
1 parent 8beef45 commit 2afc7e7

3 files changed

Lines changed: 38 additions & 1 deletion

File tree

packages/neuron-wallet/src/database/chain/ormconfig.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import env from '../../env'
1313
import { InitMigration1561695143591 } from './migrations/1561695143591-InitMigration'
1414
import { AddStatusToTx1562038960990 } from './migrations/1562038960990-AddStatusToTx'
1515

16+
export const CONNECTION_NOT_FOUND_NAME = 'ConnectionNotFoundError'
17+
1618
const dbPath = (networkName: string): string => {
1719
const name = `cell-${networkName}.sqlite`
1820
return path.join(env.fileBasePath, 'cells', name)

packages/neuron-wallet/src/listeners/tx-status.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { remote } from 'electron'
22
import { interval } from 'rxjs'
3+
import { getConnection } from 'typeorm'
34
import { TransactionStatus } from '../types/cell-types'
45
import LockUtils from '../models/lock-utils'
56
import AddressesUsedSubject from '../models/subjects/addresses-used-subject'
67
import { FailedTransaction } from '../services/tx'
8+
import { CONNECTION_NOT_FOUND_NAME } from '../database/chain/ormconfig'
79

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

@@ -47,7 +49,14 @@ const trackingStatus = async () => {
4749
export const register = () => {
4850
// every 5 seconds
4951
interval(5000).subscribe(async () => {
50-
await trackingStatus()
52+
try {
53+
getConnection()
54+
await trackingStatus()
55+
} catch (err) {
56+
if (err.name !== CONNECTION_NOT_FOUND_NAME) {
57+
throw err
58+
}
59+
}
5160
})
5261
}
5362

packages/neuron-wallet/src/services/tx/transaction-service.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { pubkeyToAddress } from '@nervosnetwork/ckb-sdk-utils'
33
import { Transaction, TransactionWithoutHash, TransactionStatus } from '../../types/cell-types'
44
import TransactionEntity from '../../database/chain/entities/transaction'
55
import LockUtils from '../../models/lock-utils'
6+
import { CONNECTION_NOT_FOUND_NAME } from '../../database/chain/ormconfig'
67

78
export interface TransactionsByAddressesParam {
89
pageNo: number
@@ -122,6 +123,20 @@ export class TransactionsService {
122123
params: TransactionsByLockHashesParam,
123124
searchValue: string = ''
124125
): Promise<PaginationResult<Transaction>> => {
126+
try {
127+
// if connection not found, may means no database to connection
128+
// it will happend when first connection to database and no network.
129+
getConnection()
130+
} catch (err) {
131+
if (err.name === CONNECTION_NOT_FOUND_NAME) {
132+
return {
133+
totalCount: 0,
134+
items: [],
135+
}
136+
}
137+
throw err
138+
}
139+
125140
const skip = (params.pageNo - 1) * params.pageSize
126141

127142
const type = TransactionsService.filterSearchType(searchValue)
@@ -224,6 +239,17 @@ export class TransactionsService {
224239
}
225240

226241
public static get = async (hash: string): Promise<Transaction | undefined> => {
242+
try {
243+
// if connection not found, may means no database to connection
244+
// it will happend when first connection to database and no network.
245+
getConnection()
246+
} catch (err) {
247+
if (err.name === CONNECTION_NOT_FOUND_NAME) {
248+
return undefined
249+
}
250+
throw err
251+
}
252+
227253
const tx = await getConnection()
228254
.getRepository(TransactionEntity)
229255
.findOne(hash, { relations: ['inputs', 'outputs'] })

0 commit comments

Comments
 (0)