-
Notifications
You must be signed in to change notification settings - Fork 128
Feat: saving last block query for next fetching #716
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
adfeb83
cc4529f
1ddfa65
b7c5c33
1497084
6569356
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -185,6 +185,8 @@ const accountsAtom = (() => { | |
| ); | ||
| })(); | ||
|
|
||
| const LATEST_SYNCED_HEIGHT_STORAGE = "latest-synced-height" | ||
|
|
||
| const balancesAtom = (() => { | ||
| const base = atom<{ [address: Address]: TokenBalances }>({}); | ||
|
|
||
|
|
@@ -223,7 +225,13 @@ const balancesAtom = (() => { | |
| set(base, { ...get(base), [address]: balance }); | ||
| }); | ||
|
|
||
| await namada.sync(); | ||
| const lastHeight = await namada.queryLastBlock(); | ||
| const startHeightStorage = Number(localStorage.getItem(LATEST_SYNCED_HEIGHT_STORAGE)); | ||
| const startHeight = startHeightStorage ? startHeightStorage : undefined; | ||
| await namada.sync(startHeight,lastHeight); | ||
| if(lastHeight){ | ||
|
||
| localStorage.setItem(LATEST_SYNCED_HEIGHT_STORAGE, lastHeight.toString()) | ||
| } | ||
|
|
||
| const shieldedBalances = await Promise.all( | ||
| queryBalance(namada, shieldedAccounts, token) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,11 +90,15 @@ export default class Namada implements Integration<Account, Signer> { | |
|
|
||
| // TODO: fix this | ||
| return { | ||
| NAM: mapUndefined((amount) => new BigNumber(amount), balances[0].amount), | ||
| NAM: mapUndefined((amount) => new BigNumber(amount), balances[0]?.amount), | ||
| }; | ||
| } | ||
|
|
||
| public async sync(): Promise<void> { | ||
| await this._namada?.shieldedSync(); | ||
| public async sync(startHeight?: number, lastHeight?: number): Promise<void> { | ||
| await this._namada?.shieldedSync({ startHeight, lastHeight }); | ||
| } | ||
|
|
||
| public async queryLastBlock(): Promise<number | undefined> { | ||
|
||
| return await this._namada?.queryLastBlock(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,8 +18,9 @@ use namada::sdk::masp_primitives::zip32::ExtendedFullViewingKey; | |
| use namada::sdk::rpc::{ | ||
| format_denominated_amount, get_public_key_at, get_token_balance, get_total_staked_tokens, | ||
| query_epoch, query_native_token, query_proposal_by_id, query_proposal_votes, | ||
| query_storage_value, | ||
| query_storage_value, query_block | ||
| }; | ||
| use namada::storage::BlockHeight; | ||
| use namada::token; | ||
| use namada::uint::I256; | ||
| use std::collections::{BTreeMap, HashMap, HashSet}; | ||
|
|
@@ -255,7 +256,19 @@ impl Query { | |
| Ok(result) | ||
| } | ||
|
|
||
| pub async fn shielded_sync(&self, owners: Box<[JsValue]>) -> Result<(), JsError> { | ||
| pub async fn query_last_block(&self) -> u64 { | ||
| let last_block_height_opt = query_block(&self.client).await.unwrap(); | ||
| let last_block_height = | ||
| last_block_height_opt.map_or_else(BlockHeight::first, |block| block.height); | ||
| last_block_height.0 | ||
| } | ||
|
|
||
| pub async fn shielded_sync( | ||
| &self, | ||
| owners: Box<[JsValue]>, | ||
| start_height: Option<u64>, | ||
| last_height: Option<u64>, | ||
| ) -> Result<(), JsError> { | ||
| let owners: Vec<ViewingKey> = owners | ||
| .into_iter() | ||
| .filter_map(|owner| owner.as_string()) | ||
|
|
@@ -278,12 +291,22 @@ impl Query { | |
|
|
||
| let _ = shielded.save().await?; | ||
|
|
||
| let start_query_height = match start_height { | ||
|
||
| Some(x) => Some(BlockHeight(x)), | ||
| None => None | ||
| }; | ||
|
|
||
| let last_query_height = match last_height { | ||
| Some(x) => Some(BlockHeight(x)), | ||
| None => None | ||
| }; | ||
|
|
||
| shielded | ||
| .fetch( | ||
| &self.client, | ||
| &DefaultLogger::new(&WebIo), | ||
| None, | ||
| None, | ||
| start_query_height, | ||
| last_query_height, | ||
|
||
| 1, | ||
| &[], | ||
| &owners, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think last block info should be stored in extension local storage.
https://github.com/anoma/namada-interface/blob/ec3dec8070219f29ccf95e8a50c880da3f032566/apps/extension/src/storage/LocalStorage.ts#L86