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

fix: always send correct currency and date to updates_v2 #2110

Merged
merged 2 commits into from
Sep 23, 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
2 changes: 1 addition & 1 deletion src/components/token-row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface TokenRowProps {

export const TokenRow = ({item, checked = false, onPress}: TokenRowProps) => {
const priceInUSD = useMemo(() => {
return item?.value?.toFiat?.({fixed: 4});
return item?.value?.toFiat?.({fixed: 4, chainId: item.chain_id});
}, [item]);

const providerImage = useMemo(() => {
Expand Down
1 change: 0 additions & 1 deletion src/event-actions/on-wallets-balance-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ export const onWalletsBalanceCheck = createAsyncTask(async () => {
const updates = await Indexer.instance.updates(
accounts,
lastBalanceUpdates,
Currencies.selectedCurrency,
);

VariablesDate.set(
Expand Down
4 changes: 1 addition & 3 deletions src/helpers/safe-load-balances.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {Currencies} from '@app/models/currencies';
import {Provider} from '@app/models/provider';
import {Balance} from '@app/services/balance';
import {Indexer} from '@app/services/indexer';
Expand All @@ -15,8 +14,7 @@ export const safeLoadBalances = async (wallets: string[]) => {
try {
balances = await Indexer.instance.updates(
wallets.map(AddressUtils.toHaqq),
new Date(0),
Currencies.selectedCurrency,
new Date(),
);
} catch (e) {
logger.error('Failed to load balances from indexer', e);
Expand Down
5 changes: 2 additions & 3 deletions src/models/currencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ class CurrenciesStore {
const updates = await Indexer.instance.updates(
accounts,
lastBalanceUpdates,
selectedCurrency,
);

VariablesDate.set(
Expand All @@ -166,14 +165,14 @@ class CurrenciesStore {
this.setRates(updates.rates);
};

private _getProviderRates = (chainId?: number) =>
private _getProviderRates = (chainId?: ChainId) =>
this._rates[
Provider.isAllNetworks
? chainId ?? MAINNET_ETH_CHAIN_ID
: Provider.selectedProvider.ethChainId
];

convert = (balance: Balance, chainId?: number): Balance => {
convert = (balance: Balance, chainId?: ChainId): Balance => {
const currencyId = this.selectedCurrency?.toLocaleLowerCase();
const serialized = balance.toJsonString();
const cacheKey = `${serialized}-${Provider.selectedProviderId}-${currencyId}-${this._prevRatesHash}`;
Expand Down
4 changes: 3 additions & 1 deletion src/services/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {Wallet} from '@app/models/wallet';
import {
BalanceConstructor,
BalanceData,
ChainId,
HaqqEthereumAddress,
HexNumber,
IBalance,
Expand Down Expand Up @@ -377,8 +378,9 @@ export class Balance implements IBalance, ISerializable {
fixed?: number | 'auto';
precission?: number;
useDefaultCurrency?: boolean;
chainId?: ChainId;
}) => {
const convertedBalance = Currencies.convert(this);
const convertedBalance = Currencies.convert(this, props?.chainId);
const fixed = props?.fixed ?? NUM_PRECISION;
const precission = props?.precission ?? this.precission;
const useDefaultCurrency = props?.useDefaultCurrency ?? false;
Expand Down
45 changes: 21 additions & 24 deletions src/services/indexer/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import _ from 'lodash';

import {AddressUtils} from '@app/helpers/address-utils';
import {I18N, getText} from '@app/i18n';
import {Currencies} from '@app/models/currencies';
import {NftCollectionIndexer} from '@app/models/nft';
import {
ALL_NETWORKS_ID,
Expand Down Expand Up @@ -114,34 +115,30 @@ export class Indexer {
);
}

updates = createAsyncTask(
async (
accounts: string[],
lastUpdated: Date | undefined,
selectedCurrency?: string,
) => {
try {
this.checkIndexerAvailability();
updates = createAsyncTask(async (accounts: string[], lastUpdated?: Date) => {
try {
this.checkIndexerAvailability();

const updated = lastUpdated || new Date(0);
const updated = lastUpdated || new Date(0);

const result: IndexerUpdatesResponse = await jsonrpcRequest(
INDEXER_PROXY_ENDPOINT,
'updates_v2',
[this.getProvidersHeader(accounts), updated, selectedCurrency].filter(
Boolean,
),
);
const result: IndexerUpdatesResponse = await jsonrpcRequest(
INDEXER_PROXY_ENDPOINT,
'updates_v2',
[
this.getProvidersHeader(accounts),
updated,
Currencies.selectedCurrency,
].filter(Boolean),
);

return result;
} catch (err) {
if (err instanceof JSONRPCError) {
this.captureException(err, 'Indexer:updates', err.meta);
}
throw err;
return result;
} catch (err) {
if (err instanceof JSONRPCError) {
this.captureException(err, 'Indexer:updates', err.meta);
}
},
);
throw err;
}
});

async getContractNames(addresses: string[]): Promise<ContractNameMap> {
try {
Expand Down
Loading
Loading