Skip to content

Commit

Permalink
Merge pull request #265 from bitfinexcom/beta
Browse files Browse the repository at this point in the history
Release version to master
  • Loading branch information
prdn authored Mar 29, 2023
2 parents 1d55c7d + f7000c2 commit e01b2de
Show file tree
Hide file tree
Showing 25 changed files with 591 additions and 56 deletions.
2 changes: 1 addition & 1 deletion bfx-report-ui
Submodule bfx-report-ui updated 43 files
+1 −1 package.json
+20 −2 public/locales/en/translations.json
+8 −5 src/components/Auth/Auth.js
+29 −20 src/components/Auth/InputKey/InputKey.js
+34 −0 src/components/Auth/LoginEmail/LoginEmail.js
+1 −0 src/components/Auth/LoginEmail/index.js
+56 −0 src/components/Auth/LoginOtp/LoginOtp.js
+1 −0 src/components/Auth/LoginOtp/index.js
+16 −2 src/components/Auth/PasswordRecovery/PasswordRecovery.container.js
+150 −72 src/components/Auth/PasswordRecovery/PasswordRecovery.js
+0 −16 src/components/Auth/PasswordRecovery/PasswordRecovery.props.js
+18 −6 src/components/Auth/RegisterSubAccounts/RegisterSubAccounts.js
+14 −1 src/components/Auth/SignIn/SignIn.container.js
+147 −75 src/components/Auth/SignIn/SignIn.js
+18 −3 src/components/Auth/SignUp/SignUp.container.js
+185 −102 src/components/Auth/SignUp/SignUp.js
+15 −15 src/components/Auth/_Auth.scss
+2 −1 src/components/Header/AccountMenu/AccountMenu.container.js
+6 −2 src/components/Header/AccountMenu/AccountMenu.js
+2 −1 src/components/Header/TopNavigation/TopNavigation.container.js
+9 −6 src/components/Header/TopNavigation/TopNavigation.js
+2 −1 src/components/Main/Main.container.js
+6 −1 src/components/Main/Main.js
+2 −0 src/components/Preferences/Preferences.container.js
+66 −57 src/components/Preferences/Preferences.js
+6 −1 src/components/SubAccounts/SubAccount/SubAccount.js
+1 −1 src/config.js
+63 −0 src/state/auth/actions.js
+9 −0 src/state/auth/constants.js
+22 −3 src/state/auth/reducer.js
+173 −7 src/state/auth/saga.js
+13 −0 src/state/auth/selectors.js
+11 −3 src/state/utils.js
+1 −0 src/state/ws/constants.js
+6 −0 src/state/ws/saga.js
+1 −1 src/styles/button.scss
+4 −4 src/styles/index.scss
+4 −3 src/styles/modals.scss
+1 −1 src/ui/DateInput/_DateInput.scss
+2 −1 src/ui/Select/Select.js
+3 −2 src/ui/Select/_Select.scss
+8 −1 src/utils/handleElectronLoad.js
+5 −1 src/utils/triggerElectronLoad.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.2.0",
"version": "4.3.0",
"description": "Bitfinex reports framework",
"main": "worker.js",
"license": "Apache-2.0",
Expand Down
17 changes: 14 additions & 3 deletions test/helpers/helpers.mock-rest-v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,27 @@ const getMockDataOpts = () => ({
...getBaseMockDataOpts(),
candles: { limit: 500 },
generate_token: null,
delete_token: null
delete_token: null,
login: null,
login_verify: null
})

const getExtraMockMethods = () => (new Map([
['post', {
'/v2/login': 'login',
'/v2/login/verify': 'login_verify'
}]
]))

const createMockRESTv2SrvWithDate = (
start = Date.now(),
end = start,
limit = null,
opts = getMockDataOpts(),
{
_getMockData = getMockData,
_setDataTo = setDataTo
_setDataTo = setDataTo,
extraMockMethods = getExtraMockMethods()
} = {}
) => {
return _createMockRESTv2SrvWithDate(
Expand All @@ -67,7 +77,8 @@ const createMockRESTv2SrvWithDate = (
opts,
{
_getMockData,
_setDataTo
_setDataTo,
extraMockMethods
}
)
}
Expand Down
19 changes: 19 additions & 0 deletions test/helpers/mock-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@ const _ms = Date.now()

module.exports = new Map([
...mockData,
[
'login',
[
'12345678-8888-4321-1234-8cb090a01360',
[
[
'otp',
true
]
]
]
],
[
'login_verify',
[
'pub:api:88888888-4444-4444-4444-121212121212-caps:s:o:f:w:wd:a-write',
'2023-03-21T12:00:00.000Z'
]
],
[
'generate_token',
['pub:api:88888888-4444-4444-4444-121212121212-caps:s:o:f:w:wd:a-write']
Expand Down
80 changes: 80 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 @@ -83,6 +83,58 @@ module.exports = (
assert.isOk(res.body.result)
})

it('it should be successfully performed by the loginToBFX method', async function () {
this.timeout(5000)

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

assert.isObject(res.body)
assert.propertyVal(res.body, 'id', 5)
assert.isArray(res.body.result)
assert.isString(res.body.result[0])
assert.isArray(res.body.result[1])
assert.isArray(res.body.result[1][0])
assert.isString(res.body.result[1][0][0])
assert.isBoolean(res.body.result[1][0][1])
})

it('it should be successfully performed by the verifyOnBFX method', async function () {
this.timeout(5000)

const res = await agent
.post(`${basePath}/json-rpc`)
.type('json')
.send({
auth: {
loginToken: '12345678-8888-4321-1234-8cb090a01360',
token: '123456',
verifyMethod: 'otp'
},
method: 'verifyOnBFX',
id: 5
})
.expect('Content-Type', /json/)
.expect(200)

assert.isObject(res.body)
assert.propertyVal(res.body, 'id', 5)
assert.isArray(res.body.result)
assert.isString(res.body.result[0])
assert.isString(res.body.result[1])
})

it('it should be successfully performed by the signIn method', async function () {
this.timeout(5000)

Expand All @@ -107,10 +159,35 @@ module.exports = (
assert.strictEqual(res.body.result.email, email)
assert.strictEqual(res.body.result.isSubAccount, isSubAccount)
assert.isString(res.body.result.token)
assert.isBoolean(res.body.result.shouldNotSyncOnStartupAfterUpdate)
assert.isNotOk(res.body.result.shouldNotSyncOnStartupAfterUpdate)

auth.token = res.body.result.token
})

it('it should be successfully performed by the updateUser method', async function () {
this.timeout(5000)

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

assert.isObject(res.body)
assert.propertyVal(res.body, 'id', 5)
assert.isBoolean(res.body.result)
assert.isOk(res.body.result)
})

it('it should be successfully performed by the signIn method by token', async function () {
this.timeout(5000)

Expand All @@ -131,6 +208,8 @@ module.exports = (
assert.strictEqual(res.body.result.email, email)
assert.strictEqual(res.body.result.isSubAccount, isSubAccount)
assert.strictEqual(res.body.result.token, auth.token)
assert.isBoolean(res.body.result.shouldNotSyncOnStartupAfterUpdate)
assert.isOk(res.body.result.shouldNotSyncOnStartupAfterUpdate)
})

it('it should not be successfully performed by the signIn method', async function () {
Expand Down Expand Up @@ -328,6 +407,7 @@ module.exports = (
assert.isString(user.email)
assert.isBoolean(user.isSubAccount)
assert.isBoolean(user.isNotProtected)
assert.isBoolean(user.isRestrictedToBeAddedToSubAccount)
assert.isArray(user.subUsers)

user.subUsers.forEach((subUser) => {
Expand Down
7 changes: 6 additions & 1 deletion workers/loc.api/di/app.deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ const Crypto = require('../sync/crypto')
const Authenticator = require('../sync/authenticator')
const privResponder = require('../responder')
const ProcessMessageManager = require('../process.message.manager')
const HTTPRequest = require('../http.request')

decorate(injectable(), EventEmitter)

Expand Down Expand Up @@ -157,7 +158,8 @@ module.exports = ({
['_dataConsistencyChecker', TYPES.DataConsistencyChecker],
['_winLossVSAccountBalance', TYPES.WinLossVSAccountBalance],
['_weightedAveragesReport', TYPES.WeightedAveragesReport],
['_getDataFromApi', TYPES.GetDataFromApi]
['_getDataFromApi', TYPES.GetDataFromApi],
['_httpRequest', TYPES.HTTPRequest]
]
})
rebind(TYPES.RServiceDepsSchemaAliase)
Expand Down Expand Up @@ -197,6 +199,9 @@ module.exports = ({
bind(TYPES.ProcessMessageManager)
.to(ProcessMessageManager)
.inSingletonScope()
bind(TYPES.HTTPRequest)
.to(HTTPRequest)
.inSingletonScope()
bind(TYPES.WSTransport)
.to(WSTransport)
.inSingletonScope()
Expand Down
3 changes: 2 additions & 1 deletion workers/loc.api/di/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@ module.exports = {
SyncUserStepData: Symbol.for('SyncUserStepData'),
SyncUserStepDataFactory: Symbol.for('SyncUserStepDataFactory'),
WeightedAveragesReport: Symbol.for('WeightedAveragesReport'),
WeightedAveragesReportCsvWriter: Symbol.for('WeightedAveragesReportCsvWriter')
WeightedAveragesReportCsvWriter: Symbol.for('WeightedAveragesReportCsvWriter'),
HTTPRequest: Symbol.for('HTTPRequest')
}
18 changes: 16 additions & 2 deletions workers/loc.api/errors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const {
ConflictError,
ArgsParamsError
} = require('bfx-report/workers/loc.api/errors')
const {
getErrorArgs
} = require('bfx-report/workers/loc.api/errors/helpers')

class CollSyncPermissionError extends BaseError {
constructor (message = 'ERR_PERMISSION_DENIED_TO_SYNC_SELECTED_COLL') {
Expand Down Expand Up @@ -113,6 +116,14 @@ class SubAccountUpdatingError extends AuthError {
}
}

class UserUpdatingError extends AuthError {
constructor (message = 'ERR_USER_UPDATE_HAS_BEEN_FAILED') {
super(message)

this.statusMessage = 'User update has been failed'
}
}

class UserRemovingError extends AuthError {
constructor (message = 'ERR_USER_REMOVE_HAS_BEEN_FAILED') {
super(message)
Expand Down Expand Up @@ -212,8 +223,10 @@ class SyncInfoUpdatingError extends BaseError {
}

class AuthTokenGenerationError extends AuthError {
constructor (message = 'ERR_AUTH_TOKEN_HAS_NOT_BEEN_GENERATED') {
super(message)
constructor (args) {
const _args = getErrorArgs(args, 'ERR_AUTH_TOKEN_HAS_NOT_BEEN_GENERATED')

super(_args)
}
}

Expand All @@ -235,6 +248,7 @@ module.exports = {
MigrationLaunchingError,
SubAccountCreatingError,
SubAccountUpdatingError,
UserUpdatingError,
UserRemovingError,
UserWasPreviouslyStoredInDbError,
SubAccountLedgersBalancesRecalcError,
Expand Down
26 changes: 26 additions & 0 deletions workers/loc.api/http.request/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict'

const {
AuthError
} = require('bfx-report/workers/loc.api/errors')

const isAuthApiError = (err) => {
return /ERR_AUTH_API/.test(err.toString())
}

const makeRequestToBFX = async (requestFn) => {
try {
return await requestFn()
} catch (err) {
if (isAuthApiError(err)) {
throw new AuthError()
}

throw err
}
}

module.exports = {
isAuthApiError,
makeRequestToBFX
}
63 changes: 63 additions & 0 deletions workers/loc.api/http.request/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
'use strict'

const { RESTv2 } = require('bfx-api-node-rest')

const {
makeRequestToBFX
} = require('./helpers')

const { decorateInjectable } = require('../di/utils')

const depsTypes = (TYPES) => [
TYPES.CONF
]
class HTTPRequest {
constructor (
conf
) {
this.conf = conf

this._TEST_REST_URL = 'http://localhost:9999'
this._isTestEnv = process.env.NODE_ENV === 'test'

this._transportCache = new Map()
this.getRequest() // Init default cache
}

getRequest (opts = {}) {
const key = JSON.stringify(opts)

const _opts = {
transform: true,
url: this._isTestEnv
? this._TEST_REST_URL
: this.conf?.restUrl,
...opts
}

if (this._transportCache.has(key)) {
return this._transportCache.get(key)
}

const rest = new ExpandedRESTv2(_opts)
this._transportCache.set(key, rest)

return rest
}
}

class ExpandedRESTv2 extends RESTv2 {
async login (body) {
return makeRequestToBFX(() => this
._makePublicPostRequest('/login', body))
}

async verify (body) {
return makeRequestToBFX(() => this
._makePublicPostRequest('/login/verify', body))
}
}

decorateInjectable(HTTPRequest, depsTypes)

module.exports = HTTPRequest
22 changes: 22 additions & 0 deletions workers/loc.api/process.message.manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,28 @@ class ProcessMessageManager {
{ backupFilesMetadata }
)
}

async [PROCESS_STATES.REQUEST_UPDATE_USERS_SYNC_ON_STARTUP_REQUIRED_STATE] (err, state, data) {
if (err) {
this.logger.debug('[Users sync on startup required state has not been updated]')
this.logger.error(err)

this.sendState(
PROCESS_MESSAGES.RESPONSE_UPDATE_USERS_SYNC_ON_STARTUP_REQUIRED_STATE,
{ err }
)

return
}

const isDone = await this.dao
.updateUsersSyncOnStartupRequiredState()

this.sendState(
PROCESS_MESSAGES.RESPONSE_UPDATE_USERS_SYNC_ON_STARTUP_REQUIRED_STATE,
{ isDone }
)
}
}

decorateInjectable(ProcessMessageManager, depsTypes)
Expand Down
4 changes: 3 additions & 1 deletion workers/loc.api/process.message.manager/process.messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ module.exports = {
REQUEST_MIGRATION_HAS_FAILED_WHAT_SHOULD_BE_DONE: 'request:migration-has-failed:what-should-be-done',
REQUEST_SHOULD_ALL_TABLES_BE_REMOVED: 'request:should-all-tables-be-removed',

RESPONSE_GET_BACKUP_FILES_METADATA: 'response:get-backup-files-metadata'
RESPONSE_GET_BACKUP_FILES_METADATA: 'response:get-backup-files-metadata',

RESPONSE_UPDATE_USERS_SYNC_ON_STARTUP_REQUIRED_STATE: 'response:update-users-sync-on-startup-required-state'
}
Loading

0 comments on commit e01b2de

Please sign in to comment.