Skip to content

Commit

Permalink
Merge pull request #1246 from multiversx/development
Browse files Browse the repository at this point in the history
2.38.8
  • Loading branch information
arhtudormorar authored Aug 29, 2024
2 parents 61fc73b + 347f4d3 commit aafdeed
Show file tree
Hide file tree
Showing 7 changed files with 321 additions and 279 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [[v2.38.8]](https://github.com/multiversx/mx-sdk-dapp/pull/1246)] - 2024-08-29
- [Added sign screens cached tokens functionality](https://github.com/multiversx/mx-sdk-dapp/pull/1245)

## [[v2.38.7]](https://github.com/multiversx/mx-sdk-dapp/pull/1244)] - 2024-08-28
- [Updated metamask sign screens to use ledger sign screens](https://github.com/multiversx/mx-sdk-dapp/pull/1243)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-dapp",
"version": "2.38.7",
"version": "2.38.8",
"description": "A library to hold the main logic for a dapp on the MultiversX blockchain",
"author": "MultiversX",
"license": "GPL-3.0-or-later",
Expand Down
25 changes: 25 additions & 0 deletions src/apiCalls/tokens/getPersistedToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { axiosInstance } from 'apiCalls/utils/axiosInstance';
import { networkSelector } from 'reduxStore/selectors/networkConfigSelectors';
import { store } from 'reduxStore/store';
import { tokenDataStorage } from './tokenDataStorage';

export async function getPersistedToken<T>(url: string): Promise<T> {
const { apiAddress, apiTimeout } = networkSelector(store.getState());

const config = {
baseURL: apiAddress,
timeout: Number(apiTimeout)
};

const cachedToken: T | null = await tokenDataStorage.getItem(url);

if (cachedToken) {
return cachedToken;
}

const response = await axiosInstance.get<T>(url, config);

await tokenDataStorage.setItem(url, response.data);

return response.data;
}
30 changes: 30 additions & 0 deletions src/apiCalls/tokens/tokenDataStorage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
let memoryCache: Record<string, string> = {};

export let tokenDataStorage = {
setItem: async <T>(key: string, tokenData: T) => {
try {
memoryCache[key] = JSON.stringify(tokenData);
} catch (e) {
console.error('tokenDataStorage unable to serialize', e);
}
},
getItem: async (key: string) => {
try {
return JSON.parse(memoryCache[key]);
} catch (e) {
console.error('tokenDataStorage unable to parse', e);
}
},
clear: async () => {
memoryCache = {};
},
removeItem: async (key: string) => {
delete memoryCache[key];
}
};

export const setTokenDataStorage = (
tokenDataCacheStorage: typeof tokenDataStorage
) => {
tokenDataStorage = tokenDataCacheStorage;
};
14 changes: 9 additions & 5 deletions src/apiCalls/transactions/getTransactionsByHashes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axios from 'axios';
import { TRANSACTIONS_ENDPOINT } from 'apiCalls/endpoints';
import { apiAddressSelector } from 'reduxStore/selectors';
import { store } from 'reduxStore/store';
import { ServerTransactionType } from 'types';
Expand All @@ -12,12 +13,15 @@ export const getTransactionsByHashes = async (
): Promise<GetTransactionsByHashesReturnType> => {
const apiAddress = apiAddressSelector(store.getState());
const hashes = pendingTransactions.map((tx) => tx.hash);
const { data: responseData } = await axios.get(`${apiAddress}/transactions`, {
params: {
hashes: hashes.join(','),
withScResults: true
const { data: responseData } = await axios.get(
`${apiAddress}/${TRANSACTIONS_ENDPOINT}`,
{
params: {
hashes: hashes.join(','),
withScResults: true
}
}
});
);

return pendingTransactions.map(({ hash, previousStatus }) => {
const txOnNetwork = responseData.find(
Expand Down
12 changes: 3 additions & 9 deletions src/hooks/transactions/useGetTokenDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import useSwr from 'swr';

import { NFTS_ENDPOINT, TOKENS_ENDPOINT } from 'apiCalls/endpoints';
import { axiosFetcher } from 'apiCalls/utils/axiosFetcher';
import { getPersistedToken } from 'apiCalls/tokens/getPersistedToken';
import { useGetNetworkConfig } from 'hooks/useGetNetworkConfig';
import { NftEnumType } from 'types/tokens.types';
import { getIdentifierType } from 'utils/validation/getIdentifierType';
Expand Down Expand Up @@ -50,12 +50,6 @@ interface TokenInfoResponse {
price: number;
}

interface TokenInfoResponseDataType {
data?: TokenInfoResponse;
error?: string;
isLoading?: boolean;
}

export function useGetTokenDetails({
tokenId
}: {
Expand All @@ -71,11 +65,11 @@ export function useGetTokenDetails({
data: selectedToken,
error,
isLoading
}: TokenInfoResponseDataType = useSwr(
} = useSwr<TokenInfoResponse>(
Boolean(tokenIdentifier)
? `${network.apiAddress}/${tokenEndpoint}/${tokenIdentifier}`
: null,
axiosFetcher
getPersistedToken
);

if (!tokenIdentifier) {
Expand Down
Loading

0 comments on commit aafdeed

Please sign in to comment.