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
3 changes: 2 additions & 1 deletion packages/neuron-wallet/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import 'reflect-metadata'

import initApp from './startup/initApp'
import createWindow from './startup/createWindow'
import createLoopTask from './startup/loopTask/create'

import i18n from './utils/i18n'
import mainmenu from './utils/mainmenu'
import createLoopTask from './startup/loopTask/create'

let mainWindow: Electron.BrowserWindow | null

Expand Down
26 changes: 15 additions & 11 deletions packages/neuron-wallet/src/typeorm.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { createConnection, getConnectionOptions, getConnection } from 'typeorm'
import * as path from 'path'
import env from './env'
import { SqliteConnectionOptions } from 'typeorm/driver/sqlite/SqliteConnectionOptions'
import path from 'path'

import Transaction from './entities/Transaction'
import Input from './entities/Input'
import Output from './entities/Output'
import SyncInfo from './entities/SyncInfo'

import logger from './utils/logger'
import env from './env'

import { InitMigration1558328532490 } from './migration/1558328532490-InitMigration'
import { AddSince1558491231870 } from './migration/1558491231870-AddSince'

Expand All @@ -15,30 +18,31 @@ const dbPath = (networkName: string): string => {
return path.join(env.fileBasePath, 'cells', name)
}

const connectOptions = async (networkName: string) => {
const connectOptions = async (networkName: string): Promise<SqliteConnectionOptions> => {
const connectionOptions = await getConnectionOptions()
Object.assign(connectionOptions, {

return {
...connectionOptions,
type: 'sqlite',
database: dbPath(networkName),
entities: [Transaction, Input, Output, SyncInfo],
migrations: [InitMigration1558328532490, AddSince1558491231870],
})

return connectionOptions
}
}

export const initConnection = async (networkName: string) => {
// try to close connection, if not exist, will throw ConnectionNotFoundError when call getConnection()
try {
await getConnection().close()
} catch (e) {
// console.error(e)
} catch (err) {
logger.log({ level: 'error', message: err.message })
}
const connectionOptions = await connectOptions(networkName)

try {
await createConnection(connectionOptions)
} catch (e) {
console.error(e)
} catch (err) {
logger.log({ level: 'error', message: err.message })
}
}

Expand Down