From 5e8a7af5788068ddda9afdfb74ed2c22ace48a21 Mon Sep 17 00:00:00 2001 From: shafin-deriv Date: Wed, 27 Nov 2024 19:32:44 +0800 Subject: [PATCH] chore: fix journal filter and add reset balance for demo --- package-lock.json | 8 ++++---- package.json | 2 +- .../journal/journal-components/filters.tsx | 11 ++-------- .../layout/header/account-switcher.tsx | 20 ++++++++++++++++++- src/components/layout/header/header.scss | 10 ++++++++++ .../shared_ui/checkbox/checkbox.scss | 8 ++++++++ .../shared_ui/checkbox/checkbox.tsx | 4 ++-- src/stores/journal-store.ts | 2 +- src/stores/run-panel-store.ts | 3 ++- src/utils/analytics/index.ts | 1 + 10 files changed, 50 insertions(+), 19 deletions(-) diff --git a/package-lock.json b/package-lock.json index d8957db3..148c4eb8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@deriv-com/auth-client": "^1.2.12", "@deriv-com/quill-ui": "1.18.1", "@deriv-com/translations": "^1.3.9", - "@deriv-com/ui": "^1.36.4", + "@deriv-com/ui": "^1.37.1", "@deriv-com/utils": "latest", "@deriv/deriv-api": "^1.0.15", "@deriv/deriv-charts": "^2.5.1", @@ -2688,9 +2688,9 @@ } }, "node_modules/@deriv-com/ui": { - "version": "1.36.4", - "resolved": "https://registry.npmjs.org/@deriv-com/ui/-/ui-1.36.4.tgz", - "integrity": "sha512-j9c20TN5FsCZq6oFF7JNKgAUkizVWqH/9byLfUPF3LprLk7ku+7jYV5DJCJLLR0bYxjEo7RI6lAfOfPTNEsE5g==", + "version": "1.37.1", + "resolved": "https://registry.npmjs.org/@deriv-com/ui/-/ui-1.37.1.tgz", + "integrity": "sha512-qvmsB3fvjG1Bpcrx9eazPa8AIWVh8DZMNVIqUoAbpFBbBIirdiKmKubkJz0bYkzM73OlrlFdjVEF+yGbeeZGsw==", "dependencies": { "@popperjs/core": "^2.11.8", "@types/react-modal": "^3.16.3", diff --git a/package.json b/package.json index 9c22660a..033800a4 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "@deriv-com/auth-client": "^1.2.12", "@deriv-com/quill-ui": "1.18.1", "@deriv-com/translations": "^1.3.9", - "@deriv-com/ui": "^1.36.4", + "@deriv-com/ui": "^1.37.1", "@deriv-com/utils": "latest", "@deriv/deriv-api": "^1.0.15", "@deriv/deriv-charts": "^2.5.1", diff --git a/src/components/journal/journal-components/filters.tsx b/src/components/journal/journal-components/filters.tsx index 39b2a343..5d3c55eb 100644 --- a/src/components/journal/journal-components/filters.tsx +++ b/src/components/journal/journal-components/filters.tsx @@ -1,25 +1,18 @@ import Checkbox from '@/components/shared_ui/checkbox'; import { TFiltersProps } from '../journal.types'; -const Filters = ({ - wrapper_ref, - checked_filters, - filters, - filterMessage, - className, - classNameLabel, -}: TFiltersProps) => ( +const Filters = ({ wrapper_ref, checked_filters, filters, filterMessage, className }: TFiltersProps) => (
{filters.map(item => { const hasFilter = Array.isArray(checked_filters) && checked_filters.includes(item.id); return ( filterMessage(!hasFilter, item.id)} name={item.id} + defaultChecked={hasFilter} /> ); })} diff --git a/src/components/layout/header/account-switcher.tsx b/src/components/layout/header/account-switcher.tsx index 217813ba..59a22a17 100644 --- a/src/components/layout/header/account-switcher.tsx +++ b/src/components/layout/header/account-switcher.tsx @@ -29,6 +29,7 @@ type TAccountSwitcherProps = { isVirtual?: boolean; modifiedAccountList: TModifiedAccount[]; switchAccount: (loginId: number) => void; + activeLoginId?: string; }; type TAccountSwitcher = { @@ -49,7 +50,12 @@ interface AccountSwitcherData { renderCountryIsLowRiskAndHasRealAccount: boolean; } -const RenderAccountItems = ({ isVirtual, modifiedAccountList, switchAccount }: TAccountSwitcherProps) => { +const RenderAccountItems = ({ + isVirtual, + modifiedAccountList, + switchAccount, + activeLoginId, +}: TAccountSwitcherProps) => { const { client } = useStore(); const { landing_companies } = client; @@ -95,6 +101,15 @@ const RenderAccountItems = ({ isVirtual, modifiedAccountList, switchAccount }: T onSelectAccount={() => { if (!account.is_disabled) switchAccount(account.loginid); }} + onResetBalance={ + isVirtual && activeLoginId === account.loginid + ? () => { + api_base?.api?.send({ + topup_virtual: 1, + }); + } + : undefined + } /> ))} @@ -166,6 +181,7 @@ const AccountSwitcher = observer(({ activeAccount }: TAccountSwitcher) => { ]); const switchAccount = async (loginId: number) => { + if (loginId.toString() === activeAccount?.loginid) return; const account_list = JSON.parse(localStorage.getItem('accountsList') ?? '{}'); const token = account_list[loginId]; if (!token) return; @@ -192,6 +208,7 @@ const AccountSwitcher = observer(({ activeAccount }: TAccountSwitcher) => { @@ -199,6 +216,7 @@ const AccountSwitcher = observer(({ activeAccount }: TAccountSwitcher) => { modifiedAccountList={modifiedAccountList as TModifiedAccount[]} switchAccount={switchAccount} isVirtual + activeLoginId={activeAccount?.loginid} /> diff --git a/src/components/layout/header/header.scss b/src/components/layout/header/header.scss index 5181f7a4..ca4441ce 100644 --- a/src/components/layout/header/header.scss +++ b/src/components/layout/header/header.scss @@ -40,6 +40,16 @@ } .deriv-account-switcher { + &-item { + &__balance { + button { + border-width: 1px; + height: 2.4rem; + min-width: 4.8rem; + } + } + } + &__button { margin-inline-end: 0.8rem; diff --git a/src/components/shared_ui/checkbox/checkbox.scss b/src/components/shared_ui/checkbox/checkbox.scss index 4c3f10a3..64ed4221 100644 --- a/src/components/shared_ui/checkbox/checkbox.scss +++ b/src/components/shared_ui/checkbox/checkbox.scss @@ -10,6 +10,7 @@ &__input { display: none; } + &__box { display: flex; width: 16px; @@ -26,16 +27,23 @@ &--active { border: none; background-color: var(--brand-red-coral); + display: flex; + align-items: center; + justify-content: center; + fill: #fff; } } + &--active { border: none; background-color: var(--brand-red-coral); } + &--disabled { opacity: 0.5; cursor: not-allowed !important; } + &--grey-disabled { background-color: var(--checkbox-disabled-grey); } diff --git a/src/components/shared_ui/checkbox/checkbox.tsx b/src/components/shared_ui/checkbox/checkbox.tsx index 0c3d64cc..070aef3d 100644 --- a/src/components/shared_ui/checkbox/checkbox.tsx +++ b/src/components/shared_ui/checkbox/checkbox.tsx @@ -1,6 +1,6 @@ import React from 'react'; import classNames from 'classnames'; -import { Icon } from '@/utils/tmp/dummy'; +import { LabelPairedCheckCaptionFillIcon } from '@deriv/quill-icons/LabelPaired'; import Text from '../text'; type TCheckBoxProps = Omit, 'value' | 'label'> & { @@ -86,7 +86,7 @@ const Checkbox = React.forwardRef( tabIndex={withTabIndex} onKeyDown={handleKeyDown} > - {!!checked && } + {!!checked && } filter.id); + this.journal_filters = getSetting('journal_filter') ?? this.filters.map(filter => filter.id); this.unfiltered_messages = getStoredItemsByUser(this.JOURNAL_CACHE, loginid, []); } diff --git a/src/stores/run-panel-store.ts b/src/stores/run-panel-store.ts index bec71f21..50a51035 100644 --- a/src/stores/run-panel-store.ts +++ b/src/stores/run-panel-store.ts @@ -519,7 +519,8 @@ export default class RunPanelStore { if (this.error_type === ErrorTypes.RECOVERABLE_ERRORS) { // Bot should indicate it started in below cases: // - When error happens it's a recoverable error - const { shouldRestartOnError, timeMachineEnabled } = this.dbot.interpreter.bot.tradeEngine.options; + const { shouldRestartOnError = false, timeMachineEnabled = false } = + this.dbot?.interpreter?.bot?.tradeEngine?.options ?? {}; const is_bot_recoverable = shouldRestartOnError || timeMachineEnabled; if (is_bot_recoverable) { diff --git a/src/utils/analytics/index.ts b/src/utils/analytics/index.ts index 2591b602..723cce85 100644 --- a/src/utils/analytics/index.ts +++ b/src/utils/analytics/index.ts @@ -30,6 +30,7 @@ export const AnalyticsInitializer = async () => { growthbookDecryptionKey: flags.marketing_growthbook ? process.env.GROWTHBOOK_DECRYPTION_KEY : undefined, rudderstackKey: process.env.RUDDERSTACK_KEY, growthbookOptions: { + disableCache: process.env.NODE_ENV !== 'production', attributes: { account_type: account_type === 'null' ? 'unlogged' : account_type, app_id: String(getAppId()),