Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimise rendering of crypto history #2580

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 48 additions & 20 deletions lib/saito/ui/saito-crypto/overlays/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
<a target="_blank" href="/explorer" class="saito-history-msg">
View SAITO history on block explorer
<i class="fa-solid fa-arrow-up-right-from-square"></i>
</a>`;
} else {
let html = '';
if (d.length > 0) {
for (let i = (d.length - 1); i >= 0; i--) {
Expand Down Expand Up @@ -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 = `<div class="saito-identicon-container">
<img class="saito-identicon" src="${identicon}">
<div class="history-address-container">
Expand Down Expand Up @@ -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 =
'<p class="mixin-no-history">No account history found.</p>';
`<p class="mixin-no-history">No account history found for ${this.mod.ticker}</p>`;

document.querySelectorAll('.pagination-button').forEach(function(btn, key){
btn.classList.add('disabled');
});
}
});
} else {
document.querySelector(
'.mixin-txn-his-container .saito-table-body'
).innerHTML = `
<a target="_blank" href="/explorer" class="saito-history-msg">
View SAITO history on block explorer
<i class="fa-solid fa-arrow-up-right-from-square"></i>
</a>`;
}

}

});

this.attachEvents();
}
Expand Down
3 changes: 2 additions & 1 deletion lib/saito/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '') {
Expand Down
4 changes: 2 additions & 2 deletions mods/mixin/lib/mixinmodule.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down