Skip to content

Commit 0ca97df

Browse files
swapped currency
removed log added returns back in just in case added original rates removed helper references updated runtime currency to cache for 5 mins linted updated calls to use fewer custom ones fixed tests added choices to adFree updated runtime currency updated relativeCurrencyQuery removed tonumber as return changed remove strict checks on publisher and owner in settlement doc (#414) Log sentry release (#410) updated require structure for bat utils and balance server (#291) added tests and reconnect mechanisms to redis (#343) delete all the things (#416) rework signed txn validation (#418) added check for accounts transactions endpoint (#420) changed response to string (#419) added grafana and prometheus... unable to login (#406) fix error code on claim no longer avail, add count on grants b4 offer (#422) remove dependency on unsignedTx (#423) fixes failure from extra promo in db (#425) Sentry upgrade (#428) swapped currency changed ratios url to staging
1 parent 61d960c commit 0ca97df

File tree

4 files changed

+50
-4
lines changed

4 files changed

+50
-4
lines changed

bat-utils/lib/runtime-currency.test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,13 @@ test('capture exception is passed up to runtime', async (t) => {
7070

7171
test('rates are provided for basic tokens', async (t) => {
7272
const knownRateKeys = currency.knownRateKeys
73-
t.plan(2 + knownRateKeys.length)
73+
t.plan(2 + knownRateKeys.length * 2)
7474
let result
7575
result = await currency.rates('BAT')
7676
t.true(_.isObject(result))
7777
t.true(knownRateKeys.length > 1)
7878
knownRateKeys.forEach((key) => {
79+
t.true(_.isString(result[key]))
7980
t.true(_.isNumber(+result[key]))
8081
})
8182
})

config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ module.exports =
109109
{ altcurrency : process.env.ALTCURRENCY || 'BAT'
110110
, cache :
111111
{ redis :
112-
{ url : process.env.REDIS_URL || 'redis://localhost:6379' }
112+
{ url : process.env.REDIS_URL || 'redis://localhost:6379' }
113113
}
114114
, currency :
115115
{ altcoins : process.env.CRYPTO_CURRENCIES ? process.env.CRYPTO_CURRENCIES.split(',')

ledger/controllers/surveyor.js

+43-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,47 @@ const server = async (request, reply, runtime) => {
3333
surveyor.payload = entry.payload
3434
surveyor.parentId = entry.parentId
3535
}
36-
36+
if (surveyor) {
37+
await addChoices(runtime, surveyor)
38+
}
3739
return surveyor
3840
}
3941

42+
async function addChoices (runtime, surveyor) {
43+
const payload = surveyor.payload || {}
44+
surveyor.payload = payload
45+
const adFree = payload.adFree || {}
46+
payload.adFree = adFree
47+
adFree.choices = await getAdjustedChoices(runtime, 'USD', ['BAT'])
48+
}
49+
50+
async function getAdjustedChoices (runtime, base, currencies) {
51+
const rates = await runtime.currency.rates(base, currencies)
52+
return underscore.mapObject(rates, choicesPrices)
53+
}
54+
55+
function choicesPrices (ratio) {
56+
const basePrice = 1 / ratio
57+
const table = [
58+
[3, 5, 7, 10, 20],
59+
[4, 6, 9, 12, 25],
60+
[5, 8, 11, 17, 35],
61+
[6, 10, 14, 20, 40],
62+
[9, 12, 20, 35, 50],
63+
[15, 25, 35, 50, 100],
64+
[20, 35, 50, 85, 175],
65+
[30, 50, 70, 100, 200]
66+
]
67+
const priceIncrements = [1, 0.8, 0.6, 0.5, 0.35, 0.2, 0.15, 0.1]
68+
let index = underscore.findIndex(priceIncrements, (increment) => {
69+
return increment <= basePrice
70+
})
71+
if (underscore.isUndefined(index)) {
72+
index = priceIncrements.length - 1
73+
}
74+
return table[index]
75+
}
76+
4077
const registrarType = (surveyorType) => {
4178
return { contribution: 'persona', voting: 'viewing' }[surveyorType]
4279
}
@@ -305,8 +342,12 @@ v2.phase1 =
305342
})
306343

307344
const payload = surveyor.payload
345+
const surveyorJSON = underscore.extend({
346+
signature,
347+
payload
348+
}, surveyor.publicInfo())
308349

309-
reply(underscore.extend({ signature: signature, payload: payload }, surveyor.publicInfo()))
350+
reply(surveyorJSON)
310351
}
311352
},
312353

test/e2e.integration.test.js

+4
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ test('ledger : v2 contribution workflow with uphold BAT wallet', async t => {
168168

169169
t.true(response.body.hasOwnProperty('payload'))
170170
t.true(response.body.payload.hasOwnProperty('adFree'))
171+
t.true(response.body.payload.adFree.hasOwnProperty('choices'))
172+
t.true(_.isArray(response.body.payload.adFree.choices.BAT))
173+
t.true(response.body.payload.adFree.choices.BAT.length === 5)
174+
console.log(response.body.payload.adFree)
171175
t.true(response.body.payload.adFree.hasOwnProperty('probi'))
172176
const donateAmt = new BigNumber(response.body.payload.adFree.probi).dividedBy('1e18').toNumber()
173177

0 commit comments

Comments
 (0)