Skip to content

Commit

Permalink
Merge pull request #153 from shafin-deriv/shafin/BOT-2418/chore-add-r…
Browse files Browse the repository at this point in the history
…eset-balance-and-journal-fix

chore: fix journal filter and add reset balance for demo
  • Loading branch information
shafin-deriv authored Nov 27, 2024
2 parents edc0874 + 5e8a7af commit da610da
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 19 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 2 additions & 9 deletions src/components/journal/journal-components/filters.tsx
Original file line number Diff line number Diff line change
@@ -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) => (
<div ref={wrapper_ref} className={className}>
{filters.map(item => {
const hasFilter = Array.isArray(checked_filters) && checked_filters.includes(item.id);
return (
<Checkbox
key={item.id}
labelClassName={classNameLabel}
checked={hasFilter}
label={item.label}
onChange={() => filterMessage(!hasFilter, item.id)}
name={item.id}
defaultChecked={hasFilter}
/>
);
})}
Expand Down
20 changes: 19 additions & 1 deletion src/components/layout/header/account-switcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type TAccountSwitcherProps = {
isVirtual?: boolean;
modifiedAccountList: TModifiedAccount[];
switchAccount: (loginId: number) => void;
activeLoginId?: string;
};

type TAccountSwitcher = {
Expand All @@ -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;

Expand Down Expand Up @@ -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
}
/>
</span>
))}
Expand Down Expand Up @@ -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;
Expand All @@ -192,13 +208,15 @@ const AccountSwitcher = observer(({ activeAccount }: TAccountSwitcher) => {
<RenderAccountItems
modifiedAccountList={modifiedAccountList as TModifiedAccount[]}
switchAccount={switchAccount}
activeLoginId={activeAccount?.loginid}
/>
</UIAccountSwitcher.Tab>
<UIAccountSwitcher.Tab title={tabs_labels.demo}>
<RenderAccountItems
modifiedAccountList={modifiedAccountList as TModifiedAccount[]}
switchAccount={switchAccount}
isVirtual
activeLoginId={activeAccount?.loginid}
/>
</UIAccountSwitcher.Tab>
</UIAccountSwitcher>
Expand Down
10 changes: 10 additions & 0 deletions src/components/layout/header/header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 8 additions & 0 deletions src/components/shared_ui/checkbox/checkbox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
&__input {
display: none;
}

&__box {
display: flex;
width: 16px;
Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/shared_ui/checkbox/checkbox.tsx
Original file line number Diff line number Diff line change
@@ -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<React.HTMLProps<HTMLInputElement>, 'value' | 'label'> & {
Expand Down Expand Up @@ -86,7 +86,7 @@ const Checkbox = React.forwardRef<HTMLInputElement, TCheckBoxProps>(
tabIndex={withTabIndex}
onKeyDown={handleKeyDown}
>
{!!checked && <Icon icon='IcCheckmark' color='active' />}
{!!checked && <LabelPairedCheckCaptionFillIcon />}
</span>
</span>
<Text
Expand Down
2 changes: 1 addition & 1 deletion src/stores/journal-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default class JournalStore {
restoreStoredJournals() {
const client = this.core.client as RootStore['client'];
const { loginid } = client;
this.journal_filters = getSetting('journal_filter') || this.filters.map(filter => filter.id);
this.journal_filters = getSetting('journal_filter') ?? this.filters.map(filter => filter.id);
this.unfiltered_messages = getStoredItemsByUser(this.JOURNAL_CACHE, loginid, []);
}

Expand Down
3 changes: 2 additions & 1 deletion src/stores/run-panel-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/utils/analytics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down

0 comments on commit da610da

Please sign in to comment.