From 2ec09de962fdb3d9f16c361ae63041f4e384965d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20S=C3=A1?= Date: Mon, 4 Jul 2022 18:05:31 +0100 Subject: [PATCH 1/2] fix: make paper & SMS receipts independent --- lib/graphql/resolvers.js | 26 ++++++++++++++++++++------ lib/graphql/types.js | 1 + 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/graphql/resolvers.js b/lib/graphql/resolvers.js index d68bc8ce..eb1988d8 100644 --- a/lib/graphql/resolvers.js +++ b/lib/graphql/resolvers.js @@ -23,16 +23,18 @@ const speedtestFiles = [ ] const addSmthInfo = (dstField, srcFields) => smth => - smth && smth.active ? _.set(dstField, _.pick(srcFields, smth)) : _.identity + (smth && smth.active) ? _.set(dstField, _.pick(srcFields, smth)) : _.identity const addOperatorInfo = addSmthInfo( 'operatorInfo', ['name', 'phone', 'email', 'website', 'companyNumber'] ) -const addReceiptInfo = addSmthInfo( - 'receiptInfo', - [ +const addReceiptInfo = receiptInfo => ret => { + if (!receiptInfo) return ret + + const fields = [ + 'paper', 'sms', 'operatorWebsite', 'operatorEmail', @@ -43,10 +45,22 @@ const addReceiptInfo = addSmthInfo( 'exchangeRate', 'addressQRCode', ] -) + const defaults = _.fromPairs(_.map(field => [field, false], fields)) + + receiptInfo = _.flow( + o => _.set('paper', o.active, o), + _.assign(defaults), + _.pick(fields), + )(receiptInfo) + + return (receiptInfo.paper || receiptInfo.sms) ? + _.set('receiptInfo', receiptInfo, ret) : + ret +} + /* TODO: Simplify this. */ -const buildTriggers = (allTriggers) => { +const buildTriggers = allTriggers => { const normalTriggers = [] const customTriggers = _.filter(o => { if (_.isEmpty(o.customInfoRequestId) || _.isNil(o.customInfoRequestId)) normalTriggers.push(o) diff --git a/lib/graphql/types.js b/lib/graphql/types.js index 90d2472c..1a74179a 100644 --- a/lib/graphql/types.js +++ b/lib/graphql/types.js @@ -32,6 +32,7 @@ type MachineInfo { } type ReceiptInfo { + paper: Boolean! sms: Boolean! operatorWebsite: Boolean! operatorEmail: Boolean! From 6ab5dbbd7dc0dce7522190d8019722f56901e03a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20S=C3=A1?= Date: Mon, 4 Jul 2022 18:14:43 +0100 Subject: [PATCH 2/2] fix: always send `areThereAvailablePromoCodes` This field is not covered by the version of the `user_config` table. --- lib/graphql/resolvers.js | 6 +++--- lib/graphql/types.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/graphql/resolvers.js b/lib/graphql/resolvers.js index eb1988d8..9c72d5db 100644 --- a/lib/graphql/resolvers.js +++ b/lib/graphql/resolvers.js @@ -96,7 +96,6 @@ const staticConfig = ({ currentConfigVersion, deviceId, deviceName, pq, settings const staticConf = _.flow( _.pick([ - 'areThereAvailablePromoCodes', 'coins', 'configVersion', 'timezone' @@ -171,7 +170,7 @@ const dynamicConfig = ({ deviceId, operatorId, pid, pq, settings, }) => { state.pids = _.update(operatorId, _.set(deviceId, { pid, ts: Date.now() }), state.pids) return _.flow( - _.pick(['balances', 'cassettes', 'coins', 'rates']), + _.pick(['areThereAvailablePromoCodes', 'balances', 'cassettes', 'coins', 'rates']), _.update('cassettes', massageCassettes), @@ -186,7 +185,8 @@ const dynamicConfig = ({ deviceId, operatorId, pid, pq, settings, }) => { /* Group the separate objects by cryptoCode */ /* { balances, coins, rates } => { cryptoCode: { balance, ask, bid, cashIn, cashOut }, ... } */ - ({ balances, cassettes, coins, rates }) => ({ + ({ areThereAvailablePromoCodes, balances, cassettes, coins, rates }) => ({ + areThereAvailablePromoCodes, cassettes, coins: _.flow( _.reduce( diff --git a/lib/graphql/types.js b/lib/graphql/types.js index 1a74179a..92126887 100644 --- a/lib/graphql/types.js +++ b/lib/graphql/types.js @@ -86,7 +86,6 @@ type Terms { type StaticConfig { configVersion: Int! - areThereAvailablePromoCodes: Boolean! coins: [Coin!]! enablePaperWalletOnly: Boolean! hasLightning: Boolean! @@ -137,6 +136,7 @@ type Cassettes { } type DynamicConfig { + areThereAvailablePromoCodes: Boolean! cassettes: Cassettes coins: [DynamicCoinValues!]! reboot: Boolean!