From 2bd77f8e9a0f5eeeeaff2014fb27aad4e0d67e4c Mon Sep 17 00:00:00 2001 From: Umair Khan Date: Tue, 27 Aug 2024 02:53:37 +0500 Subject: [PATCH] Optimise rendering of crypto history --- lib/saito/ui/saito-crypto/overlays/history.js | 68 +++++++++++++------ lib/saito/wallet.ts | 3 +- mods/mixin/lib/mixinmodule.js | 4 +- 3 files changed, 52 insertions(+), 23 deletions(-) diff --git a/lib/saito/ui/saito-crypto/overlays/history.js b/lib/saito/ui/saito-crypto/overlays/history.js index d06e43c5c1..f4e1499c37 100644 --- a/lib/saito/ui/saito-crypto/overlays/history.js +++ b/lib/saito/ui/saito-crypto/overlays/history.js @@ -31,11 +31,24 @@ class MixinHistory { maximumFractionDigits: decimals }); - if (this.mod.ticker != 'SAITO') { - this.mod.returnHistory(this.mod.asset_id, 1000, async (d) => { - this.history_data = d; - - console.log('history data:', d); + let tmp_user_data = {}; + let tmp_identicon = {}; + let tmp_identifer = {}; + + await this.mod.returnHistory(this.mod.asset_id, 1000, async (d) => { + this.history_data = d; + + console.log('history data:', d); + + if (d === false) { + document.querySelector( + '.mixin-txn-his-container .saito-table-body' + ).innerHTML = ` + + View SAITO history on block explorer + + `; + } else { let html = ''; if (d.length > 0) { for (let i = (d.length - 1); i >= 0; i--) { @@ -65,13 +78,35 @@ class MixinHistory { let sender_html = ''; if (opponnent != null && opponnent != '') { // Showing details for internal mixin transaction details - let user_data = await this.mod.getAddressByUserId(opponnent, this.mod.asset_id); + + let user_data = null; + if (opponnent in tmp_user_data) { + user_data = tmp_user_data[opponnent]; + } else { + user_data = await this.mod.getAddressByUserId(opponnent, this.mod.asset_id); + tmp_user_data[opponnent] = user_data; + } + if (user_data != null) { let public_key = user_data.publickey; let address = user_data.address; - let identicon = this_history.app.keychain.returnIdenticon(public_key); - let username = this_history.app.keychain.returnIdentifierByPublicKey(public_key, true); + let identicon = null; + if (public_key in tmp_identicon) { + identicon = tmp_identicon[public_key]; + } else { + identicon = this_history.app.keychain.returnIdenticon(public_key); + tmp_identicon[public_key] = identicon; + } + + let username = null; + if (public_key in tmp_identifer) { + username = tmp_identifer[public_key]; + } else { + username = this_history.app.keychain.returnIdentifierByPublicKey(public_key, true); + tmp_identifer[public_key] = username; + } + sender_html = `
@@ -111,27 +146,20 @@ class MixinHistory { document.querySelector( '.mixin-txn-his-container .saito-table-body' ).innerHTML += html; - this.attachEvents(); } else { document.querySelector( '.mixin-txn-his-container .saito-table-body' ).innerHTML = - '

No account history found.

'; + `

No account history found for ${this.mod.ticker}

`; document.querySelectorAll('.pagination-button').forEach(function(btn, key){ btn.classList.add('disabled'); }); } - }); - } else { - document.querySelector( - '.mixin-txn-his-container .saito-table-body' - ).innerHTML = ` - - View SAITO history on block explorer - - `; - } + + } + + }); this.attachEvents(); } diff --git a/lib/saito/wallet.ts b/lib/saito/wallet.ts index 68327a78e0..034e86538a 100644 --- a/lib/saito/wallet.ts +++ b/lib/saito/wallet.ts @@ -118,9 +118,10 @@ export default class Wallet extends SaitoWallet { } } - returnHistory(asset_id = '', records = 20, callback = null) { + async returnHistory(asset_id = '', records = 20, callback = null) { // to be implemented in future // redirecting users to block explorer for now + return callback(false); } async sendPayment(amount, to_address, unique_hash = '') { diff --git a/mods/mixin/lib/mixinmodule.js b/mods/mixin/lib/mixinmodule.js index 96c308e52c..b74964abf7 100644 --- a/mods/mixin/lib/mixinmodule.js +++ b/mods/mixin/lib/mixinmodule.js @@ -492,8 +492,8 @@ class MixinModule extends CryptoModule { * @abstract * @return {Function} Callback function */ - returnHistory(asset_id = '', records = 20, callback = null) { - return this.mixin.fetchSafeSnapshots(asset_id, records, callback); + async returnHistory(asset_id = '', records = 20, callback = null) { + return await this.mixin.fetchSafeSnapshots(asset_id, records, callback); } async returnUtxo(state = 'unspent', limit = 500, order = 'DESC', callback = null) {