meriadec
7 years ago
5 changed files with 112 additions and 98 deletions
@ -0,0 +1,28 @@ |
|||||
|
// @flow
|
||||
|
|
||||
|
const core = require('@ledgerhq/ledger-core') |
||||
|
|
||||
|
let instanciated = false |
||||
|
let queue = Promise.resolve() |
||||
|
|
||||
|
// TODO: `core` should be typed
|
||||
|
type Job = Object => Promise<any> |
||||
|
|
||||
|
export default function withLibcore(job: Job) { |
||||
|
if (!instanciated) { |
||||
|
core.instanciateWalletPool({ |
||||
|
// sqlite files will be located in the app local data folder
|
||||
|
dbPath: process.env.LEDGER_LIVE_SQLITE_PATH, |
||||
|
}) |
||||
|
instanciated = true |
||||
|
} |
||||
|
queue = queue.then(() => { |
||||
|
try { |
||||
|
return job(core) |
||||
|
} catch (e) { |
||||
|
console.log(`withLibCore: Error in job`, e) // eslint-disable-line no-console
|
||||
|
return Promise.resolve() |
||||
|
} |
||||
|
}) |
||||
|
return queue |
||||
|
} |
@ -1,20 +0,0 @@ |
|||||
// Yep. That's a singleton.
|
|
||||
//
|
|
||||
// Electron needs to tell lib ledger core where to store the sqlite files, when
|
|
||||
// instanciating wallet pool, but we don't need to do each everytime we
|
|
||||
// require ledger-core, only the first time, so, eh.
|
|
||||
|
|
||||
const core = require('@ledgerhq/ledger-core') |
|
||||
|
|
||||
let instanciated = false |
|
||||
|
|
||||
module.exports = () => { |
|
||||
if (!instanciated) { |
|
||||
core.instanciateWalletPool({ |
|
||||
// sqlite files will be located in the app local data folder
|
|
||||
dbPath: process.env.LEDGER_LIVE_SQLITE_PATH, |
|
||||
}) |
|
||||
instanciated = true |
|
||||
} |
|
||||
return core |
|
||||
} |
|
Loading…
Reference in new issue