Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request deriv-com#513 from aizad-org/aizad_8136_demo-reset…
Browse files Browse the repository at this point in the history
…-btn

Aizad/ chore: added reset button to account switcher and also reset function
  • Loading branch information
matin-deriv authored Mar 29, 2023
2 parents 5e9c210 + b05e7c8 commit e54bccd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ const TopUpVirtualPopup = (() => {

return {
init,
doTopUp,
shouldShow: shouldShowPopup,
show : showTopUpPopup,
};
Expand Down
19 changes: 16 additions & 3 deletions src/javascript/app/pages/user/update_balance.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const BinarySocket = require('../../base/socket');
const formatMoney = require('../../common/currency').formatMoney;
const TopUpVirtualPopup = require('../../pages/user/account/top_up_virtual/pop_up');
const getPropertyValue = require('../../../_common/utility').getPropertyValue;
const createElement = require('../../../_common/utility').createElement;
const localize = require('../../../_common/localize').localize;

const updateBalance = (response) => {
if (getPropertyValue(response, 'error')) {
Expand All @@ -18,14 +20,25 @@ const updateBalance = (response) => {

const updateBalanceByAccountId = (account_id, updated_balance, account_currency) => {
const el_balance_span = document.querySelector(`.account__switcher-balance-${account_id}`);
const reset_button = createElement('button', { text: localize('Reset balance'), class: 'account__switcher-balance btn btn--secondary btn__small reset_btn' });

const is_virtual = /^VRT/.test(account_id);
const is_current = Client.get('loginid') === account_id;

if (el_balance_span) {
const display_balance = formatMoney(account_currency, updated_balance);

el_balance_span.innerHTML = display_balance;

const is_virtual = /^VRT/.test(account_id);
const is_current = Client.get('loginid') === account_id;

// show reset button
if (updated_balance !== 10000 && is_virtual && is_current) {
el_balance_span.innerHTML = null;
el_balance_span.appendChild(reset_button);
reset_button.addEventListener('click', (e) => {
e.preventDefault();
TopUpVirtualPopup.doTopUp();
});
}

if (is_current) {
document.getElementById('header__acc-balance').innerHTML = display_balance;
Expand Down

0 comments on commit e54bccd

Please sign in to comment.