Skip to content

Commit

Permalink
Merge pull request #414 from bitfinexcom/staging
Browse files Browse the repository at this point in the history
Release version to master
  • Loading branch information
prdn authored Sep 11, 2024
2 parents 60e9584 + c4ef311 commit 8b70406
Show file tree
Hide file tree
Showing 27 changed files with 198 additions and 170 deletions.
2 changes: 1 addition & 1 deletion bfx-report-ui
Submodule bfx-report-ui updated 36 files
+96 −84 package-lock.json
+2 −2 package.json
+0 −25 src/components/AccountBalance/AccountBalance.js
+2 −3 src/components/AppSummary/_AppSummary.scss
+1 −17 src/components/AverageWinLoss/AverageWinLoss.js
+3 −23 src/components/Candles/Candles.js
+2 −7 src/components/Candles/_Candles.scss
+2 −1 src/components/ConcentrationRisk/ConcentrationRisk.container.js
+3 −14 src/components/ConcentrationRisk/ConcentrationRisk.js
+1 −17 src/components/FeesReport/FeesReport.js
+1 −18 src/components/LoanReport/LoanReport.js
+0 −2 src/components/Positions/Positions.js
+2 −6 src/components/PositionsActive/PositionsActive.js
+2 −6 src/components/PositionsAudit/PositionsAudit.js
+2 −0 src/components/Snapshots/Snapshots.container.js
+12 −26 src/components/Snapshots/Snapshots.js
+15 −7 src/components/Snapshots/_Snapshots.scss
+16 −3 src/components/TaxReport/TaxReport.loader.js
+10 −0 src/components/TaxReport/_TaxReport.scss
+1 −17 src/components/TradedVolume/TradedVolume.js
+0 −2 src/components/Trades/Trades.js
+2 −0 src/components/Wallets/Wallets.container.js
+6 −12 src/components/Wallets/Wallets.js
+1 −3 src/state/snapshots/reducer.js
+7 −0 src/state/taxReport/actions.js
+2 −0 src/state/taxReport/constants.js
+10 −0 src/state/taxReport/reducer.js
+23 −1 src/state/taxReport/saga.js
+1 −1 src/styles/index.scss
+13 −12 src/ui/NavSwitcher/_NavSwitcher.scss
+0 −42 src/ui/QueryButton/QueryButton.js
+0 −12 src/ui/QueryButton/_QueryButton.scss
+0 −3 src/ui/QueryButton/index.js
+3 −3 src/ui/SectionSwitch/SectionSwitch.helpers.js
+29 −0 src/ui/SectionSwitch/_SectionSwitch.scss
+1 −1 src/ui/_index.scss
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bfx-reports-framework",
"version": "4.19.0",
"version": "4.20.0",
"description": "Bitfinex reports framework",
"main": "worker.js",
"license": "Apache-2.0",
Expand Down
20 changes: 20 additions & 0 deletions test/test-cases/api-sync-mode-sqlite-test-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,26 @@ module.exports = (
assert.isOk(Number.isInteger(res.body.result.lastSyncMts))
})

it('it should be successfully performed by the getLastFinishedSyncMts method, lastSyncMts is integer', async function () {
this.timeout(5000)

const res = await agent
.post(`${basePath}/json-rpc`)
.type('json')
.send({
auth,
method: 'getLastFinishedSyncMts',
id: 5
})
.expect('Content-Type', /json/)
.expect(200)

assert.isObject(res.body)
assert.propertyVal(res.body, 'id', 5)
assert.isObject(res.body.result)
assert.isOk(Number.isInteger(res.body.result.lastSyncMts))
})

it('it should be successfully performed by the haveCollsBeenSyncedAtLeastOnce method, returns true', async function () {
this.timeout(60000)

Expand Down
11 changes: 11 additions & 0 deletions workers/loc.api/service.report.framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ class FrameworkReportService extends ReportService {
}, 'isStagingBfxApi', args, cb)
}

getLastFinishedSyncMts (space, args, cb) {
return this._privResponder(async () => {
const lastFinishedSyncQueueJob = await this._dao
.getLastFinishedSyncQueueJob(args?.auth?._id)

return {
lastSyncMts: lastFinishedSyncQueueJob?.updatedAt ?? null
}
}, 'getLastFinishedSyncMts', args, cb)
}

signUp (space, args, cb) {
return this._responder(() => {
return this._authenticator.signUp(args)
Expand Down
44 changes: 10 additions & 34 deletions workers/loc.api/sync/dao/dao.better.sqlite.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,7 @@ const {
RemoveElemsLeaveLastNRecordsError
} = require('../../errors')

const {
CONSTR_FIELD_NAME,
TRIGGER_FIELD_NAME,
INDEX_FIELD_NAME,
UNIQUE_INDEX_FIELD_NAME
} = require('../schema/models/model/db.service.field.names')
const Model = require('../schema/models/model')
const ALLOWED_COLLS = require('../schema/allowed.colls')
const SYNC_QUEUE_STATES = require('../sync.queue/sync.queue.states')
const DB_WORKER_ACTIONS = require(
Expand Down Expand Up @@ -221,14 +216,7 @@ class BetterSqliteDAO extends DAO {
}

_createTablesIfNotExists (opts = {}) {
const models = this._getModelsMap({
models: opts?.models,
omittedFields: [
TRIGGER_FIELD_NAME,
INDEX_FIELD_NAME,
UNIQUE_INDEX_FIELD_NAME
]
})
const models = opts?.models ?? this._getModelsMap()
const sql = getTableCreationQuery(models, opts)

return this.query({
Expand All @@ -239,10 +227,7 @@ class BetterSqliteDAO extends DAO {
}

_createTriggerIfNotExists (opts = {}) {
const models = this._getModelsMap({
models: opts?.models,
omittedFields: []
})
const models = opts?.models ?? this._getModelsMap()
const sql = getTriggerCreationQuery(models, opts)

return this.query({
Expand All @@ -253,10 +238,7 @@ class BetterSqliteDAO extends DAO {
}

_createIndexisIfNotExists (opts = {}) {
const models = this._getModelsMap({
models: opts?.models,
omittedFields: []
})
const models = opts?.models ?? this._getModelsMap()
const sql = getIndexCreationQuery(models, opts)

return this.query({
Expand Down Expand Up @@ -488,16 +470,6 @@ class BetterSqliteDAO extends DAO {
return false
}

const modelsMap = this._getModelsMap({
omittedFields: [
'_id',
CONSTR_FIELD_NAME,
TRIGGER_FIELD_NAME,
INDEX_FIELD_NAME,
UNIQUE_INDEX_FIELD_NAME
]
})

await this._beginTrans(async () => {
const tableNames = await this.getTablesNames({ doNotQueueQuery })
const filteredTempTableNames = tableNames.filter((name) => (
Expand All @@ -508,12 +480,16 @@ class BetterSqliteDAO extends DAO {

for (const tempName of filteredTempTableNames) {
const name = tempName.replace(namePrefix, '')
const model = modelsMap.get(name)
const projection = Object.keys(model).join(', ')
const model = this._getModelOf(name)

if (!model) {
continue
}

const projection = model.getModelFieldKeys()
.filter((fieldName) => fieldName !== Model.UID_FIELD_NAME)
.join(', ')

if (isStrictEqual) {
sqlArr.push(`DELETE FROM ${name}`)
}
Expand Down
8 changes: 6 additions & 2 deletions workers/loc.api/sync/dao/dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ class DAO {
this.processMessageManagerFactory = processMessageManagerFactory
}

_getModelsMap (params) {
return this.syncSchema.getModelsMap(params)
_getModelsMap () {
return this.syncSchema.getModelsMap()
}

_getModelOf (tableName) {
return this.syncSchema.getModelOf(tableName)
}

_getMethodCollMap (params) {
Expand Down
7 changes: 5 additions & 2 deletions workers/loc.api/sync/dao/helpers/find-in-coll-by/get-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ module.exports = (args, methodColl, opts) => {
filter
} = getFilterParams(args, methodColl, { isPublic })

const _model = { ...model, ...additionalModel }
const modelFields = {
...model.getModelFields(),
...additionalModel
}
const exclude = isPublic ? ['_id', 'user_id'] : ['_id']

const {
Expand All @@ -46,7 +49,7 @@ module.exports = (args, methodColl, opts) => {
} = getGroupQuery(methodColl)
const { subQuery, subQueryValues } = getSubQuery(methodColl)
const projection = getProjectionQuery(
_model,
modelFields,
exclude,
isExcludePrivate
)
Expand Down
23 changes: 10 additions & 13 deletions workers/loc.api/sync/dao/helpers/get-index-creation-query.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
'use strict'

const {
INDEX_FIELD_NAME,
UNIQUE_INDEX_FIELD_NAME
} = require('../../schema/models/model/db.service.field.names')

const _getIndexQuery = (
name,
fields = [],
Expand Down Expand Up @@ -67,18 +62,20 @@ const _getIndexQueryFromModel = (
shouldNotAddIfNotExistsStm
} = opts ?? {}

const modelUniqueIndexies = model.getUniqueIndexies()
const modelIndexies = model.getIndexies()
const uniqueIndexFields = (
model[UNIQUE_INDEX_FIELD_NAME] &&
typeof model[UNIQUE_INDEX_FIELD_NAME] === 'string'
modelUniqueIndexies &&
typeof modelUniqueIndexies === 'string'
)
? model[UNIQUE_INDEX_FIELD_NAME].split(' ')
: model[UNIQUE_INDEX_FIELD_NAME]
? modelUniqueIndexies.split(' ')
: modelUniqueIndexies
const indexFields = (
model[INDEX_FIELD_NAME] &&
typeof model[INDEX_FIELD_NAME] === 'string'
modelIndexies &&
typeof modelIndexies === 'string'
)
? model[INDEX_FIELD_NAME].split(' ')
: model[INDEX_FIELD_NAME]
? modelIndexies.split(' ')
: modelIndexies

const uniqueIndexiesArr = _getIndexQuery(
name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ const getFieldsFilters = (
const _params = { ...params }
const field = _params[fieldName]

if (
Object.keys(model)
.some(key => key === modelFieldName)
) {
if (model.hasModelFieldName(modelFieldName)) {
if (typeof field === 'boolean') {
return {
...accum,
Expand Down
5 changes: 5 additions & 0 deletions workers/loc.api/sync/dao/helpers/get-projection-query.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
'use strict'

const Model = require('../../schema/models/model')

const _getProjArr = (model) => {
if (Array.isArray(model)) {
return model
}
if (model instanceof Model) {
return model.getModelFieldKeys()
}
if (
model &&
typeof model === 'object'
Expand Down
14 changes: 5 additions & 9 deletions workers/loc.api/sync/dao/helpers/get-table-creation-query.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
'use strict'

const {
CONSTR_FIELD_NAME
} = require('../../schema/models/model/db.service.field.names')

const _getConstraintsQuery = (name, model) => {
const constraintsArr = Array.isArray(model[CONSTR_FIELD_NAME])
? model[CONSTR_FIELD_NAME]
: [model[CONSTR_FIELD_NAME]]
const modelConstraints = model.getConstraints()
const constraintsArr = Array.isArray(modelConstraints)
? modelConstraints
: [modelConstraints]

return constraintsArr.reduce((accum, item) => {
const _constraints = (
Expand Down Expand Up @@ -43,8 +40,7 @@ module.exports = (models = [], opts = {}) => {
const _name = `${prefix}${name}`
const constraints = _getConstraintsQuery(_name, model)

const keys = Object.keys(model)
.filter((field) => field !== CONSTR_FIELD_NAME)
const keys = model.getModelFieldKeys()
const columnDefs = keys.reduce((accum, field, i, arr) => {
const isLast = arr.length === (i + 1)
const type = model[field]
Expand Down
11 changes: 4 additions & 7 deletions workers/loc.api/sync/dao/helpers/get-trigger-creation-query.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
'use strict'

const {
TRIGGER_FIELD_NAME
} = require('../../schema/models/model/db.service.field.names')

const _getTriggersQuery = (
name,
model,
Expand All @@ -13,9 +9,10 @@ const _getTriggersQuery = (
shouldNotAddIfNotExistsStm
} = opts ?? {}

const triggersArr = Array.isArray(model[TRIGGER_FIELD_NAME])
? model[TRIGGER_FIELD_NAME]
: [model[TRIGGER_FIELD_NAME]]
const modelTriggers = model.getTriggers()
const triggersArr = Array.isArray(modelTriggers)
? modelTriggers
: [modelTriggers]

return triggersArr.reduce((accum, item) => {
if (
Expand Down
2 changes: 1 addition & 1 deletion workers/loc.api/sync/data.inserter/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const normalizeApiData = (
return data
}

const modelKeys = Object.keys(model)
const modelKeys = model.getModelFieldKeys()

if (modelKeys.length === 0) {
return data
Expand Down
6 changes: 1 addition & 5 deletions workers/loc.api/sync/data.inserter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,11 +539,7 @@ class DataInserter extends EventEmitter {
_args.params.notThrowError = true
const currIterationArgs = cloneDeep(_args)

const { subUserId } = model ?? {}
const hasNotSubUserField = (
!subUserId ||
typeof subUserId !== 'string'
)
const hasNotSubUserField = !model.hasModelFieldName('subUserId')
const { auth: _auth } = _args ?? {}
const { session } = _auth ?? {}
const sessionAuth = isPublic || hasNotSubUserField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,24 +213,22 @@ class SyncUserStepManager {
const hasUserIdField = (
Number.isInteger(userId)
)
const hasUserIdFieldInModel = (
typeof model?.user_id === 'string'
)
const hasUserIdFieldInModel = model
.hasModelFieldName('user_id')
const hasSubUserIdField = (
Number.isInteger(subUserId)
)
const hasSubUserIdFieldInModel = (
typeof model?.subUserId === 'string'
)
const hasSubUserIdFieldInModel = model
.hasModelFieldName('subUserId')
const hasSymbolField = (
symbolFieldName &&
typeof model?.[symbolFieldName] === 'string' &&
model.hasModelFieldName(symbolFieldName) &&
symbol &&
typeof symbol === 'string'
)
const hasTimeframeField = (
timeframeFieldName &&
typeof model?.[timeframeFieldName] === 'string' &&
model.hasModelFieldName(timeframeFieldName) &&
timeframe &&
typeof timeframe === 'string'
)
Expand Down
14 changes: 8 additions & 6 deletions workers/loc.api/sync/movements/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ class Movements {
this.ALLOWED_COLLS = ALLOWED_COLLS
this.authenticator = authenticator

this.movementsModel = this.syncSchema.getModelsMap()
.get(this.ALLOWED_COLLS.MOVEMENTS)
this.ledgersModel = this.syncSchema.getModelsMap()
.get(this.ALLOWED_COLLS.LEDGERS)
this.movementsModelFields = this.syncSchema
.getModelOf(this.ALLOWED_COLLS.MOVEMENTS)
.getModelFields()
this.ledgersModelFields = this.syncSchema
.getModelOf(this.ALLOWED_COLLS.LEDGERS)
.getModelFields()
}

async getMovements (params = {}) {
Expand Down Expand Up @@ -177,7 +179,7 @@ class Movements {
end = Date.now(),
filter: _filter,
sort = [['mts', -1], ['id', -1]],
projection = this.ledgersModel,
projection = this.ledgersModelFields,
exclude = ['user_id'],
isExcludePrivate = true,
isWithdrawals = false,
Expand Down Expand Up @@ -227,7 +229,7 @@ class Movements {
end = Date.now(),
filter: _filter,
sort = [['mts', -1], ['id', -1]],
projection = this.ledgersModel,
projection = this.ledgersModelFields,
exclude = ['user_id'],
isExcludePrivate = true,
isWithdrawals = false,
Expand Down
Loading

0 comments on commit 8b70406

Please sign in to comment.