Skip to content

Commit

Permalink
[BOT] sandeep/bot-1164/ts-migration--stores (binary-com#14021)
Browse files Browse the repository at this point in the history
* refactor: ⚡ refactoring download-store and migrating it to TS

* refactor: 🚧 Migrated stores to TS along with the config

* chore: ⚡ cleanup and fixed sonarcloud code smells

* refactor: ⚡ removed download store and instead made utitlity methods

---------

Co-authored-by: Sandeep <sandeepsingh@Sandeep-Singhs-Mac-CX9PCJX3L9-Standard.local>
  • Loading branch information
sandeep-deriv and Sandeep committed Mar 20, 2024
1 parent 51f8a2b commit 602fa86
Show file tree
Hide file tree
Showing 8 changed files with 321 additions and 210 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ export const config = {
[localize('MACD'), '1'],
[localize('Signal'), '2'],
],
gd: {
scope: 'https://www.googleapis.com/auth/drive.file',
discovery_docs: 'https://www.googleapis.com/discovery/v1/apis/drive/v3/rest',
GOOGLE_DRIVE: {
SCOPE: 'https://www.googleapis.com/auth/drive.file',
DISCOVERY_DOCS: 'https://www.googleapis.com/discovery/v1/apis/drive/v3/rest',
},
workspaces: {
flyoutWorkspacesStartScale: 0.7,
Expand Down
63 changes: 59 additions & 4 deletions packages/bot-web-ui/src/components/download/download.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,81 @@ import React from 'react';
import { Button, Icon, Popover } from '@deriv/components';
import { observer } from '@deriv/stores';
import { localize } from '@deriv/translations';
import { downloadFile, getSuccessJournalMessage, TTransaction } from 'Utils/download';
import { useDBotStore } from 'Stores/useDBotStore';

type TDownloadProps = {
tab: string;
};

const Download = observer(({ tab }: TDownloadProps) => {
const { download, run_panel, transactions } = useDBotStore();
const { run_panel, transactions, journal } = useDBotStore();
const { is_clear_stat_disabled, is_running } = run_panel;
const { onClickDownloadTransaction, onClickDownloadJournal } = download;
const { filtered_messages } = journal;
const { transactions: transaction_list } = transactions;
let disabled = false;
let clickFunction, popover_message;

const downloadTransaction = () => {
const items = [
[
localize('Market'),
localize('Reference ID (buy)'),
localize('Reference ID (sell)'),
localize('Barrier'),
localize('Start Time'),
localize('Entry Spot'),
localize('Entry Spot Time'),
localize('Exit Spot'),
localize('Exit Spot Time'),
localize('Buy Price'),
localize('Profit/Loss'),
],
];
transaction_list.forEach(({ data }: { data: TTransaction }) =>
items.push([
data.display_name,
data.transaction_ids.buy,
data.transaction_ids.sell,
data.barrier,
data.date_start,
data.entry_tick,
data.entry_tick_time,
data.exit_tick,
data.exit_tick_time,
data.buy_price,
data.profit,
])
);

const content = items.map(e => e.join(',')).join('\n');
downloadFile(localize('Transactions'), content);
};

const downloadJournal = () => {
const items = [[localize('Date'), localize('Time'), localize('Message')]];

filtered_messages.map(item => {
let array_message;
if (item.message_type !== 'success') {
array_message = JSON.stringify(item.message);
} else {
array_message = getSuccessJournalMessage(item.message.toString(), item.extra);
}
const arr = [item.date, item.time, array_message?.replace('&#x2F;', '/')];
items.push(arr);
});
const content = items.map(e => e.join(',')).join('\n');
downloadFile(localize('Journal'), content);
};

if (tab === 'transactions') {
clickFunction = onClickDownloadTransaction;
clickFunction = downloadTransaction;
disabled = !transaction_list.length || is_running;
popover_message = localize('Download your transaction history.');
if (!transaction_list.length) popover_message = localize('No transaction or activity yet.');
} else if (tab === 'journal') {
clickFunction = onClickDownloadJournal;
clickFunction = downloadJournal;
popover_message = localize('Download your journal.');
disabled = is_clear_stat_disabled;
if (disabled) popover_message = localize('No transaction or activity yet.');
Expand Down
135 changes: 0 additions & 135 deletions packages/bot-web-ui/src/stores/download-store.js

This file was deleted.

Loading

0 comments on commit 602fa86

Please sign in to comment.