- + RanchiMall - + @@ -418,6 +418,7 @@ You transaction activities will appear here. + Requests @@ -475,104 +476,7 @@ - - - - - - - - - - - - - - - - - - - - - - - Account summary - - - - Deposit - Loan - - - - - - - - - - - - - Total deposit - - - - - - - - - - Total loan - - - - - - - - - - My balance - - Refresh - - - - - - - - - Rupee - - - - - - - - - FLO - - - - +
@@ -799,28 +703,13 @@ floGlobals.connectionErrorNotification = notify('There seems to be a problem connecting to the internet, Please check you internet connection.', 'error') }) window.addEventListener('online', () => { - getRef('notification_drawer').remove(floGlobals.connectionErrorNotification) + getById('notification_drawer').remove(floGlobals.connectionErrorNotification) notify('We are back online.', 'success') }) // Use instead of document.getElementById - function getRef(elementId) { - if (!domRefs.hasOwnProperty(elementId)) { - domRefs[elementId] = { - count: 1, - ref: null, - }; - return document.getElementById(elementId); - } else { - if (domRefs[elementId].count < 3) { - domRefs[elementId].count = domRefs[elementId].count + 1; - return document.getElementById(elementId); - } else { - if (!domRefs[elementId].ref) - domRefs[elementId].ref = document.getElementById(elementId); - return domRefs[elementId].ref; - } - } + function getById(elementId) { + return document.getElementById(elementId) } // returns dom with specified element @@ -843,8 +732,8 @@ // function required for popups or modals to appear function openPopup(popupId, pinned) { zIndex++ - getRef(popupId).setAttribute('style', `z-index: ${zIndex}`) - return getRef(popupId).show({ pinned }) + getById(popupId).setAttribute('style', `z-index: ${zIndex}`) + return getById(popupId).show({ pinned }) } // hides the popup or modal @@ -856,14 +745,14 @@ document.addEventListener('popupopened', e => { switch (e.target.id) { case 'profile_popup': - renderElem(getRef('profile_popup__content'), render.profile()) + renderElem(getById('profile_popup__content'), render.profile()) break; } }) document.addEventListener('popupclosed', e => { switch (e.target.id) { case 'profile_popup': - renderElem(getRef('profile_popup__content'), html``) + renderElem(getById('profile_popup__content'), html``) break; } zIndex--; @@ -872,10 +761,10 @@ const getConfirmation = (title, options = {}) => { return new Promise(resolve => { const { message = '', cancelText = 'Cancel', confirmText = 'OK', danger = false } = options - getRef('confirm_title').innerText = title; - getRef('confirm_message').innerText = message; - const cancelButton = getRef('confirmation_popup').querySelector('.cancel-button'); - const confirmButton = getRef('confirmation_popup').querySelector('.confirm-button') + getById('confirm_title').innerText = title; + getById('confirm_message').innerText = message; + const cancelButton = getById('confirmation_popup').querySelector('.cancel-button'); + const confirmButton = getById('confirmation_popup').querySelector('.confirm-button') confirmButton.textContent = confirmText cancelButton.textContent = cancelText if (danger) @@ -915,7 +804,7 @@ if (mode === 'error') { console.error(message) } - return getRef("notification_drawer").push(message, { icon, ...options }); + return getById("notification_drawer").push(message, { icon, ...options }); } function getFormattedTime(timestamp, format) { @@ -955,7 +844,7 @@ } } - window.addEventListener('hashchange', e => showPage(window.location.hash)) + window.addEventListener('hashchange', e => routeTo(window.location.hash)) window.addEventListener("load", () => { document.body.classList.remove('hidden') document.querySelectorAll('sm-input[data-private-key]').forEach(input => input.customValidation = floCrypto.getPubKeyHex) @@ -980,7 +869,7 @@ let accountLoader let accountChart let adminRequestsLoader - async function showPage(targetPage, options = {}) { + async function routeTo(targetPage, options = {}) { const { firstLoad, hashChange } = options let pageId let subPageId @@ -1020,24 +909,24 @@ switch (pageId) { case 'sign_in': setTimeout(() => { - getRef('private_key_field').focusIn() + getById('private_key_field').focusIn() }, 0); break; case 'sign_up': const { floID, privKey } = floCrypto.generateNewID() - getRef('generated_flo_id').value = floID - getRef('generated_private_key').value = privKey + getById('generated_flo_id').value = floID + getById('generated_private_key').value = privKey break; case 'deposit': const { I_s } = bank_app.getRates() - getRef('deposit_interest_rate').textContent = (I_s * 100).toFixed(2) + getById('deposit_interest_rate').textContent = (I_s * 100).toFixed(2) // checks if there is transaction pending, if so then shows warning checkIfAllowed('deposit') checkTouchSupport(window.matchMedia("(any-hover: hover)")) break; case 'loan': const { I_b } = bank_app.getRates() - getRef('loan_interest_rate').textContent = (I_b * 100).toFixed(2) + getById('loan_interest_rate').textContent = (I_b * 100).toFixed(2) checkIfAllowed('loan') checkTouchSupport(window.matchMedia("(any-hover: hover)")) break; @@ -1052,8 +941,8 @@ break; } document.querySelector('.page:not(.hidden)')?.classList.add('hidden') - getRef(pageId)?.classList.remove('hidden') - getRef(pageId)?.animate([ + getById(pageId)?.classList.remove('hidden') + getById(pageId)?.animate([ { opacity: 0, }, @@ -1067,9 +956,19 @@ }) } if (subPageId) { - getRef('all_responses_list').innerHTML = '' - getRef('all_requests_list').innerHTML = '' - getRef('user_accounts').innerHTML = '' + getById('all_responses_list').innerHTML = '' + getById('all_requests_list').innerHTML = '' + getById('user_accounts').innerHTML = '' + if (floGlobals.isMobileView) { + if (accountChart) + accountChart.destroy() + renderElem(getById('user_section'), html``) + } else { + renderElem(getById('user_section'), render.accountSummary()) + chartObserver.disconnect() + chartObserver.observe(getById('account_chart_container')) + refreshBalance() + } switch (subPageId) { case 'dashboard': if (pagesData.openedSubPages.includes(subPageId)) { @@ -1081,8 +980,8 @@ checkPendingTransaction() hideProcess('deposit') hideProcess('loan') - getRef('get_deposit_amount').value = '' - getRef('get_loan_amount').value = '' + getById('get_deposit_amount').value = '' + getById('get_loan_amount').value = '' break; case 'admin': if (pagesData.openedSubPages.includes(subPageId)) { @@ -1099,7 +998,7 @@ responseLoader = new LazyLoader('#all_responses_list', getResponses, render.responseCard, { batchSize: 10 }) responseLoader.init() } - getRef('notifications_page_button').classList.remove('has-notification') + getById('notifications_page_button').classList.remove('has-notification') break; case 'history': if (pagesData.openedSubPages.includes(subPageId)) { @@ -1109,12 +1008,18 @@ requestLoader.init() } break; + case 'account_summary': + renderElem(getById('account_summary'), render.accountSummary()) + refreshBalance() + chartObserver.disconnect() + chartObserver.observe(getById('account_chart_container')) + break; } document.querySelector('.sub-page:not(.hidden)')?.classList.add('hidden') - getRef(subPageId)?.classList.remove('hidden') - getRef('main_nav').querySelectorAll('.nav-item--active').forEach(item => item.classList.remove('nav-item--active')) - getRef('main_nav').querySelector(`.nav-item[href="#/${pageId}/${subPageId ? subPageId : ''}"]`).classList.add('nav-item--active') - getRef(subPageId)?.animate([ + getById(subPageId)?.classList.remove('hidden') + getById('main_nav').querySelectorAll('.nav-item--active').forEach(item => item.classList.remove('nav-item--active')) + getById('main_nav').querySelector(`.nav-item[href="#/${pageId}/${subPageId ? subPageId : ''}"]`).classList.add('nav-item--active') + getById(subPageId)?.animate([ { opacity: 0, transform: 'translateY(1rem)' @@ -1212,6 +1117,21 @@ this.render() } } + const mobileQuery = window.matchMedia('(max-width: 40rem)') + function handleMobileChange(e) { + floGlobals.isMobileView = e.matches + routeTo(window.location.hash) + if (floGlobals.isMobileView) { + } else { + } + } + mobileQuery.addEventListener('change', handleMobileChange) + handleMobileChange(mobileQuery) + const reduceMotionQuery = window.matchMedia('(prefers-reduced-motion: reduce)'); + reduceMotionQuery.addEventListener('change', () => { + floGlobals.prefersReducedMotion = reduceMotionQuery.matches + }); + floGlobals.prefersReducedMotion = reduceMotionQuery.matches