diff --git a/lib/admin/accounts.js b/lib/admin/accounts.js index e0ab0739..5ed29714 100644 --- a/lib/admin/accounts.js +++ b/lib/admin/accounts.js @@ -2,9 +2,9 @@ const _ = require('lodash/fp') const db = require('../db') const config = require('./config') -const pu = require('../plugin-helper') +const ph = require('../plugin-helper') -const schemas = pu.loadSchemas() +const schemas = ph.loadSchemas() function fetchAccounts () { return db.oneOrNone('select data from user_config where type=$1', ['accounts']) diff --git a/lib/cash-in-tx.js b/lib/cash-in-tx.js index 42a730cf..4380872f 100644 --- a/lib/cash-in-tx.js +++ b/lib/cash-in-tx.js @@ -2,19 +2,20 @@ const _ = require('lodash/fp') const pgp = require('pg-promise')() const db = require('./db') const BN = require('./bn') -const logger = require('./logger') const mapValuesWithKey = _.mapValues.convert({cap: false}) module.exports = {post} -const UPDATEABLE_FIELDS = ['fee', 'txHash', 'phone', 'error', 'send', 'cryptoAtoms', 'fiat'] +const UPDATEABLE_FIELDS = ['fee', 'txHash', 'phone', 'error', 'send', + 'cryptoAtoms', 'fiat', 'timedout'] function post (tx, pi) { const TransactionMode = pgp.txMode.TransactionMode const isolationLevel = pgp.txMode.isolationLevel const tmSRD = new TransactionMode({tiLevel: isolationLevel.serializable}) + console.log('DEBUG502: %j', tx) function transaction (t) { const sql = 'select * from cash_in_txs where id=$1' const sql2 = 'select * from bills where cash_in_txs_id=$1' @@ -36,9 +37,11 @@ function post (tx, pi) { return db.tx(transaction) .then(txVector => { - const [, newTx] = txVector + const [oldTx, newTx, newBills] = txVector + const oldBills = oldTx ? oldTx.bills : [] return postProcess(txVector, pi) .then(changes => update(newTx, changes)) + .then(tx => _.merge({bills: _.concat(oldBills, newBills)}, tx)) }) } @@ -109,7 +112,7 @@ const massage = _.flow(_.omit(['direction', 'bills']), convertBigNumFields, _.ma function insertNewBills (billRows, tx) { const bills = pullNewBills(billRows, tx) - if (_.isEmpty(bills)) return Promise.resolve() + if (_.isEmpty(bills)) return Promise.resolve([]) const dbBills = _.map(massage, bills) const columns = _.keys(dbBills[0]) @@ -120,9 +123,11 @@ function insertNewBills (billRows, tx) { } function upsert (row, tx) { + console.log('DEBUG501: %j', row) const oldTx = toObj(row) if (!oldTx) { + console.log('DEBUG500: %j', tx) return insert(tx) .then(newTx => [oldTx, newTx]) } @@ -164,7 +169,11 @@ function postProcess (txVector, pi) { if (newTx.send && !oldTx.send) { return pi.sendCoins(newTx) - .then(txHash => ({txHash})) + .then(txHash => ({ + txHash, + sendConfirmed: true, + sendTime: 'now()^' + })) } return Promise.resolve({}) diff --git a/lib/notifier.js b/lib/notifier.js index ee77089b..883fe6b8 100644 --- a/lib/notifier.js +++ b/lib/notifier.js @@ -40,7 +40,6 @@ function sendNoAlerts (plugins) { } function checkNotification (plugins) { - console.log('DEBUG444') return checkStatus(plugins) .then(alertRec => { console.log('DEBUG445: %j', alertRec) diff --git a/lib/plugins/wallet/mock-wallet/mock-wallet.js b/lib/plugins/wallet/mock-wallet/mock-wallet.js index 3ffce98d..e5bb4d74 100644 --- a/lib/plugins/wallet/mock-wallet/mock-wallet.js +++ b/lib/plugins/wallet/mock-wallet/mock-wallet.js @@ -3,9 +3,9 @@ const BN = require('../../../bn') const NAME = 'FakeWallet' const SECONDS = 1000 -const UNSEEN_TIME = 6 * SECONDS -const PUBLISH_TIME = 12 * SECONDS -const AUTHORIZE_TIME = 60 * SECONDS +const PUBLISH_TIME = 3 * SECONDS +const AUTHORIZE_TIME = 8 * SECONDS +const CONFIRM_TIME = 60 * SECONDS let t0 @@ -36,9 +36,9 @@ function newAddress () { function getStatus (account, toAddress, cryptoAtoms, cryptoCode) { const elapsed = Date.now() - t0 - if (elapsed < UNSEEN_TIME) return Promise.resolve({status: 'notSeen'}) - if (elapsed < PUBLISH_TIME) return Promise.resolve({status: 'published'}) - if (elapsed < AUTHORIZE_TIME) return Promise.resolve({status: 'authorized'}) + if (elapsed < PUBLISH_TIME) return Promise.resolve({status: 'notSeen'}) + if (elapsed < AUTHORIZE_TIME) return Promise.resolve({status: 'published'}) + if (elapsed < CONFIRM_TIME) return Promise.resolve({status: 'authorized'}) console.log('[%s] DEBUG: Mock wallet has confirmed transaction', cryptoCode) return Promise.resolve({status: 'confirmed'}) diff --git a/migrations/026-add_send_confirmed.js b/migrations/026-add_send_confirmed.js new file mode 100644 index 00000000..a696b9af --- /dev/null +++ b/migrations/026-add_send_confirmed.js @@ -0,0 +1,17 @@ +var db = require('./db') + +exports.up = function (next) { + var sql = [ + 'alter table cash_in_txs add column send_confirmed boolean not null default false', + 'alter table cash_in_txs add column device_time bigint not null', + 'alter table cash_in_txs add column timedout boolean not null default false', + 'alter table cash_in_txs add column send_time timestamptz', + 'alter table cash_out_txs add column device_time bigint not null', + 'alter table cash_out_txs add column timedout boolean not null default false' + ] + db.multi(sql, next) +} + +exports.down = function (next) { + next() +}