Skip to content

Commit

Permalink
Merge pull request #339 from bitfinexcom/staging
Browse files Browse the repository at this point in the history
Release Master
  • Loading branch information
prdn authored Nov 29, 2023
2 parents 3a03195 + e335541 commit 1c67784
Show file tree
Hide file tree
Showing 12 changed files with 266 additions and 91 deletions.
2 changes: 1 addition & 1 deletion bfx-report-ui
Submodule bfx-report-ui updated 68 files
+4,472 −3,042 package-lock.json
+2 −2 package.json
+13 −1 public/locales/en/translations.json
+33 −33 public/locales/zh-TW/translations.json
+11 −9 src/components/AccountBalance/AccountBalance.js
+2 −2 src/components/AccountSummary/AccountSummary.feeTierVolume.js
+7 −8 src/components/AccountSummary/AccountSummary.js
+75 −0 src/components/AppSummary/AppSummary.byAsset.js
+208 −0 src/components/AppSummary/AppSummary.columns.js
+4 −0 src/components/AppSummary/AppSummary.container.js
+25 −84 src/components/AppSummary/AppSummary.fees.js
+35 −0 src/components/AppSummary/AppSummary.helpers.js
+39 −36 src/components/AppSummary/AppSummary.js
+9 −5 src/components/AppSummary/AppSummary.value.js
+152 −46 src/components/AppSummary/_AppSummary.scss
+1 −1 src/components/ErrorDialog/ErrorDialog.js
+5 −3 src/components/PublicTrades/PublicTrades.columns.js
+2 −3 src/components/SubAccounts/SubAccount/SubAccount.js
+3 −3 src/components/Trades/Trades.columns.js
+5 −1 src/state/accountBalance/saga.js
+2 −2 src/state/audit/reducer.js
+5 −1 src/state/auth/saga.js
+2 −2 src/state/base/saga.js
+1 −2 src/state/candles/saga.js
+2 −2 src/state/changeLogs/reducer.js
+2 −2 src/state/columns/selectors.js
+2 −2 src/state/derivatives/reducer.js
+2 −2 src/state/filters/reducer.js
+4 −5 src/state/filters/selectors.js
+2 −3 src/state/filters/utils.js
+2 −2 src/state/fundingCreditHistory/reducer.js
+2 −2 src/state/fundingLoanHistory/reducer.js
+2 −2 src/state/fundingOfferHistory/reducer.js
+2 −2 src/state/invoices/utils.js
+2 −2 src/state/ledgers/utils.js
+3 −3 src/state/logins/reducer.js
+2 −2 src/state/movements/reducer.js
+3 −3 src/state/orderTrades/reducer.js
+2 −2 src/state/orders/reducer.js
+2 −3 src/state/pagination/reducer.js
+2 −2 src/state/positions/reducer.js
+2 −2 src/state/publicFunding/reducer.js
+2 −2 src/state/publicTrades/reducer.js
+2 −0 src/state/reducers.js
+2 −2 src/state/routing/selectors.js
+3 −3 src/state/sagas.helper.js
+2 −0 src/state/sagas.js
+34 −0 src/state/summaryByAsset/actions.js
+6 −0 src/state/summaryByAsset/constants.js
+36 −0 src/state/summaryByAsset/reducer.js
+53 −0 src/state/summaryByAsset/saga.js
+15 −0 src/state/summaryByAsset/selectors.js
+8 −0 src/state/sync/actions.js
+2 −0 src/state/sync/constants.js
+7 −0 src/state/sync/reducer.js
+8 −8 src/state/sync/saga.js
+2 −0 src/state/sync/selectors.js
+2 −2 src/state/tickers/reducer.js
+2 −2 src/state/timeRange/reducer.js
+2 −2 src/state/trades/reducer.js
+2 −3 src/state/utils.js
+ src/styles/fonts/Roboto-Medium.woff2
+8 −0 src/styles/fonts/roboto.css
+4 −0 src/styles/index.scss
+1 −0 src/ui/Charts/Chart/Chart.js
+10 −2 src/ui/DataTable/DataTable.js
+1 −0 src/ui/SectionHeader/_SectionHeader.scss
+4 −5 src/utils/columns.js
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.11.0",
"version": "4.12.0",
"description": "Bitfinex reports framework",
"main": "worker.js",
"license": "Apache-2.0",
Expand Down
4 changes: 2 additions & 2 deletions workers/loc.api/bfx.api.router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ class BfxApiRouter extends BaseBfxApiRouter {
['payInvoiceList', 90],
['accountTrades', 90],
['fundingTrades', 90],
['trades', 15],
['trades', 10],
['statusMessages', 90],
['candles', 30],
['candles', 20],
['orderTrades', 90],
['orderHistory', 90],
['activeOrders', 90],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = (ctx) => {
)

const paramsOrder = [
'syncedAt',
'symbol',
'timeframe',
'baseStart',
Expand Down
33 changes: 21 additions & 12 deletions workers/loc.api/sync/authenticator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1082,19 +1082,25 @@ class Authenticator {
} = user ?? {}
const tokenKey = this._getTokenKeyByEmailField(user)

const userSession = this.userSessions.get(token) ?? {}
const authTokenRefreshInterval = authToken
? this.setupAuthTokenRefreshInterval(user)
: null

this.userSessions.set(
token, {
...user,
authTokenFn: () => {
return this.userSessions.get(token)?.authToken
},
authTokenRefreshInterval,
authTokenInvalidateIntervals: new Map()
}
token,
Object.assign(
userSession,
user,
{
authTokenFn: () => {
return this.userSessions.get(token)?.authToken
},
authTokenRefreshInterval,
authTokenInvalidateIntervals: userSession
?.authTokenInvalidateIntervals ?? new Map()
}
)
)
this.userTokenMapByEmail.set(tokenKey, token)
}
Expand Down Expand Up @@ -1133,9 +1139,8 @@ class Authenticator {
? token
: this.userTokenMapByEmail.get(tokenKey)

this.userTokenMapByEmail.delete(tokenKey)

const session = this.userSessions.get(_token) ?? {}
this.userTokenMapByEmail.delete(this._getTokenKeyByEmailField(session))
const {
authTokenRefreshInterval,
authTokenInvalidateIntervals = new Map()
Expand Down Expand Up @@ -1272,8 +1277,12 @@ class Authenticator {
const { authTokenInvalidateIntervals } = userSession
let count = 0

if (authTokenInvalidateIntervals.has(authToken)) {
return
}

const authTokenInvalidateInterval = setInterval(async () => {
const session = this.userSessions.get(token)
const session = this.userSessions.get(token) ?? userSession

try {
count += 1
Expand All @@ -1288,7 +1297,7 @@ class Authenticator {
} catch (err) {
if (count >= 3) {
clearInterval(authTokenInvalidateInterval)
session.authTokenInvalidateIntervals?.delete(authToken)
session?.authTokenInvalidateIntervals?.delete(authToken)
}

this.logger.debug(err)
Expand Down
9 changes: 7 additions & 2 deletions workers/loc.api/sync/currency.converter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const depsTypes = (TYPES) => [
TYPES.SyncSchema,
TYPES.FOREX_SYMBS,
TYPES.ALLOWED_COLLS,
TYPES.SYNC_API_METHODS
TYPES.SYNC_API_METHODS,
TYPES.Logger
]
class CurrencyConverter {
constructor (
Expand All @@ -40,7 +41,8 @@ class CurrencyConverter {
syncSchema,
FOREX_SYMBS,
ALLOWED_COLLS,
SYNC_API_METHODS
SYNC_API_METHODS,
logger
) {
this.rService = rService
this.getDataFromApi = getDataFromApi
Expand All @@ -49,6 +51,7 @@ class CurrencyConverter {
this.FOREX_SYMBS = FOREX_SYMBS
this.ALLOWED_COLLS = ALLOWED_COLLS
this.SYNC_API_METHODS = SYNC_API_METHODS
this.logger = logger

this._COLL_NAMES = {
PUBLIC_TRADES: 'publicTrades',
Expand Down Expand Up @@ -114,6 +117,8 @@ class CurrencyConverter {
return this.currenciesSynonymous
}
} catch (err) {
this.logger.debug(err)

return this.currenciesSynonymous
}
}
Expand Down
120 changes: 85 additions & 35 deletions workers/loc.api/sync/data.inserter/data.checker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,17 @@ class DataChecker {
return filterMethodCollMap(methodCollMap)
}

async checkNewPublicData () {
/*
* `authMap` can be empty
*/
async checkNewPublicData (authMap) {
const methodCollMap = this._getMethodCollMap()

if (this._isInterrupted) {
return filterMethodCollMap(methodCollMap, true)
}

await this._checkNewDataPublicArrObjType(methodCollMap)
await this._checkNewDataPublicArrObjType(authMap, methodCollMap)
await this._checkNewPublicUpdatableData(methodCollMap)

return filterMethodCollMap(methodCollMap, true)
Expand Down Expand Up @@ -179,7 +182,7 @@ class DataChecker {
schema.start.push(freshSyncUserStepData)
}

async _checkNewDataPublicArrObjType (methodCollMap) {
async _checkNewDataPublicArrObjType (authMap, methodCollMap) {
for (const [method, schema] of methodCollMap) {
if (this._isInterrupted) {
return
Expand All @@ -191,7 +194,21 @@ class DataChecker {
this._resetSyncSchemaProps(schema)

if (schema.name === this.ALLOWED_COLLS.CANDLES) {
await this._checkNewCandlesData(method, schema)
// If `authMap` is empty sync candles for all users
const _authMap = (
!(authMap instanceof Map) ||
authMap.size === 0
)
? new Map([['ALL', {}]])
: authMap

for (const authItem of _authMap) {
await this._checkNewCandlesData(
method,
schema,
authItem[1]
)
}
}
if (
schema.name === this.ALLOWED_COLLS.PUBLIC_TRADES ||
Expand Down Expand Up @@ -336,20 +353,29 @@ class DataChecker {
*/
async _checkNewCandlesData (
method,
schema
schema,
auth
) {
if (this._isInterrupted) {
return
}

const { _id: userId, subUser } = auth ?? {}
const { _id: subUserId } = subUser ?? {}
const usersFilter = Number.isInteger(userId)
? { $eq: { user_id: userId } }
: {}

const currMts = Date.now()
const firstLedgerMts = await this._getFirstLedgerMts()
const firstLedgerMts = await this._getFirstLedgerMts(usersFilter)

if (!Number.isInteger(firstLedgerMts)) {
return
}

const uniqueSymbsSet = await this._getUniqueSymbsFromLedgers()
const uniqueSymbsSet = await this._getUniqueSymbsFromLedgers(
usersFilter
)
const candlesPairsSet = new Set()

for (const symbol of uniqueSymbsSet) {
Expand Down Expand Up @@ -389,7 +415,9 @@ class DataChecker {
collName: method,
symbol,
timeframe: CANDLES_TIMEFRAME,
defaultStart: firstLedgerMts
defaultStart: firstLedgerMts,
userId,
subUserId
}
)

Expand All @@ -398,7 +426,6 @@ class DataChecker {
!syncUserStepData.isCurrStepReady
) {
schema.hasNewData = true
schema.start.push(syncUserStepData)
}

const wasStartPointChanged = this._wasStartPointChanged(
Expand All @@ -407,39 +434,42 @@ class DataChecker {
)
const shouldFreshSyncBeAdded = this._shouldFreshSyncBeAdded(
syncUserStepData,
currMts
currMts,
{ dayOfYear: 1 }
)

if (
!wasStartPointChanged &&
!shouldFreshSyncBeAdded
) {
continue
}

const freshSyncUserStepData = this.syncUserStepDataFactory({
...syncUserStepData.getParams(),
isBaseStepReady: true,
isCurrStepReady: true
})

if (wasStartPointChanged) {
freshSyncUserStepData.setParams({
syncUserStepData.setParams({
baseStart: firstLedgerMts,
baseEnd: syncUserStepData.baseStart,
isBaseStepReady: false
})

schema.hasNewData = true
}
if (shouldFreshSyncBeAdded) {
freshSyncUserStepData.setParams({
syncUserStepData.setParams({
currStart: lastElemMtsFromTables,
currEnd: currMts,
isCurrStepReady: false
})

schema.hasNewData = true
}

schema.hasNewData = true
schema.start.push(freshSyncUserStepData)
if (!schema.hasNewData) {
continue
}

// To keep flow: one candles request per currency
if (!syncUserStepData.isBaseStepReady) {
syncUserStepData.setParams({
baseEnd: syncUserStepData.currEnd ?? currMts,
isCurrStepReady: true
})
}

syncUserStepData.auth = auth
schema.start.push(syncUserStepData)
}
}

Expand Down Expand Up @@ -502,7 +532,8 @@ class DataChecker {
) {
const {
measure = 'minutes',
allowedTimeDiff = 60
allowedTimeDiff = 60,
dayOfYear
} = allowedDiff ?? {}

const baseEnd = (
Expand All @@ -517,15 +548,28 @@ class DataChecker {
)
? syncUserStepData.currEnd
: 0
const syncedAt = syncUserStepData.hasSyncedAt
? syncUserStepData.syncedAt
: 0

const momentBaseEnd = moment.utc(baseEnd)
const momentCurrEnd = moment.utc(currEnd)
const momentCurrMts = moment.utc(currMts)
const momentSyncedAt = moment.utc(syncedAt)

const momentMaxEnd = moment.max(momentBaseEnd, momentCurrEnd)
const momentDiff = momentCurrMts.diff(momentMaxEnd, measure)

return momentDiff > allowedTimeDiff
const yearsDiff = momentCurrMts.year() - momentSyncedAt.year()
const dayOfYearDiff = momentCurrMts.dayOfYear() - momentSyncedAt.dayOfYear()

return (
momentDiff > allowedTimeDiff &&
(
!Number.isFinite(dayOfYear) ||
yearsDiff >= 1 ||
dayOfYearDiff >= dayOfYear
)
)
}

_wasStartPointChanged (
Expand Down Expand Up @@ -553,8 +597,11 @@ class DataChecker {
return momentDiff > allowedTimeDiff
}

async _getFirstLedgerMts () {
const firstElemFilter = { $not: { currency: 'USD' } }
async _getFirstLedgerMts (usersFilter) {
const firstElemFilter = {
...usersFilter,
$not: { currency: 'USD' }
}
const firstElemOrder = [['mts', 1]]

const tempLedgersTableName = SyncTempTablesManager.getTempTableName(
Expand Down Expand Up @@ -600,9 +647,12 @@ class DataChecker {
return mts
}

async _getUniqueSymbsFromLedgers () {
async _getUniqueSymbsFromLedgers (usersFilter) {
const ledgerParams = {
filter: { $not: { currency: this.FOREX_SYMBS } },
filter: {
...usersFilter,
$not: { currency: this.FOREX_SYMBS }
},
isDistinct: true,
projection: ['currency']
}
Expand Down
Loading

0 comments on commit 1c67784

Please sign in to comment.