Skip to content

Commit 46e0f18

Browse files
Merge pull request #1944 from Solid-Money/mayank/fix/soETH-interst
Mayank/fix/so eth interst
2 parents 7b9b0ce + 94b5886 commit 46e0f18

5 files changed

Lines changed: 56 additions & 25 deletions

File tree

app/(protected)/(tabs)/savings.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export default function Savings() {
9393

9494
const { data: userDepositTransactions, isLoading: isTransactionsLoading } = useUserTransactions(
9595
user?.safeAddress,
96+
currentVault.type,
9697
);
9798

9899
const { firstDepositTimestamp } = useDepositCalculations(

graphql/clients/index.tsx

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ import { ApolloClient, HttpLink, InMemoryCache } from '@apollo/client';
1010

1111
// Singleton instances (created on first access)
1212
let _infoClient: ReturnType<typeof createInfoClient> | null = null;
13+
let _infoClientFuse: ReturnType<typeof createInfoClient> | null = null;
14+
let _infoClientEth: ReturnType<typeof createInfoClient> | null = null;
1315
let _algebraInfoClient: ReturnType<typeof createAlgebraInfoClient> | null = null;
1416

15-
const createInfoClient = () =>
17+
const createInfoClient = (uri?: string) =>
1618
new ApolloClient({
17-
link: new HttpLink({ uri: process.env.EXPO_PUBLIC_INFO_GRAPH }),
19+
link: new HttpLink({ uri: uri ?? process.env.EXPO_PUBLIC_INFO_GRAPH }),
1820
cache: new InMemoryCache(),
1921
});
2022

@@ -35,6 +37,26 @@ export const getInfoClient = () => {
3537
return _infoClient;
3638
};
3739

40+
/**
41+
* Get the FUSE vault info graph Apollo client.
42+
*/
43+
export const getInfoClientFuse = () => {
44+
if (!_infoClientFuse) {
45+
_infoClientFuse = createInfoClient(process.env.EXPO_PUBLIC_INFO_GRAPH_FUSE);
46+
}
47+
return _infoClientFuse;
48+
};
49+
50+
/**
51+
* Get the ETH vault info graph Apollo client.
52+
*/
53+
export const getInfoClientEth = () => {
54+
if (!_infoClientEth) {
55+
_infoClientEth = createInfoClient(process.env.EXPO_PUBLIC_INFO_GRAPH_ETH);
56+
}
57+
return _infoClientEth;
58+
};
59+
3860
/**
3961
* Get the algebra info graph Apollo client.
4062
* Client is lazily created on first access.

hooks/useAnalytics.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { formatUnits } from 'viem';
44
import { fuse, mainnet } from 'viem/chains';
55

66
import { explorerUrls, layerzero } from '@/constants/explorers';
7-
import { getInfoClient } from '@/graphql/clients';
7+
import { getInfoClient, getInfoClientEth, getInfoClientFuse } from '@/graphql/clients';
88
import {
99
GetUserTransactionsDocument,
1010
GetUserTransactionsQuery,
@@ -51,8 +51,14 @@ const ApyToDays = {
5151
thirtyDay: 30,
5252
};
5353

54-
const getAnalyticsVaultKey = (vault?: VaultType): VaultType.USDC | VaultType.FUSE | VaultType.ETH =>
55-
vault === VaultType.FUSE ? VaultType.FUSE : vault === VaultType.ETH ? VaultType.ETH : VaultType.USDC;
54+
const getAnalyticsVaultKey = (
55+
vault?: VaultType,
56+
): VaultType.USDC | VaultType.FUSE | VaultType.ETH =>
57+
vault === VaultType.FUSE
58+
? VaultType.FUSE
59+
: vault === VaultType.ETH
60+
? VaultType.ETH
61+
: VaultType.USDC;
5662

5763
const safeFormatUnits = (
5864
value: string | number | bigint | null | undefined,
@@ -133,11 +139,20 @@ const filterTransfers = (transfers: BlockscoutTransactions) => {
133139
});
134140
};
135141

136-
export const userTransactionsQueryOptions = (safeAddress: string | undefined) => ({
137-
queryKey: ['user-transactions', safeAddress?.toLowerCase()],
142+
export const userTransactionsQueryOptions = (
143+
safeAddress: string | undefined,
144+
vault?: VaultType,
145+
) => ({
146+
queryKey: ['user-transactions', safeAddress?.toLowerCase(), vault],
138147
queryFn: async () => {
139148
if (!safeAddress) return undefined;
140-
const { data } = await getInfoClient().query<GetUserTransactionsQuery>({
149+
const client =
150+
vault === VaultType.ETH
151+
? getInfoClientEth()
152+
: vault === VaultType.FUSE
153+
? getInfoClientFuse()
154+
: getInfoClient();
155+
const { data } = await client.query<GetUserTransactionsQuery>({
141156
query: GetUserTransactionsDocument,
142157
variables: {
143158
address: safeAddress.toLowerCase(),
@@ -150,11 +165,11 @@ export const userTransactionsQueryOptions = (safeAddress: string | undefined) =>
150165
staleTime: secondsToMilliseconds(30), // Data is fresh for 30 seconds
151166
gcTime: secondsToMilliseconds(300), // Keep in cache for 5 minutes
152167
refetchInterval: secondsToMilliseconds(30), // Poll every 30 seconds
153-
placeholderData: keepPreviousData, // Show stale data while fetching new data
168+
// placeholderData: vault ? undefined : keepPreviousData, // Disable placeholder when vault changes to avoid cross-vault data contamination
154169
});
155170

156-
export const useUserTransactions = (safeAddress: string | undefined) => {
157-
return useQuery(userTransactionsQueryOptions(safeAddress));
171+
export const useUserTransactions = (safeAddress: string | undefined, vault?: VaultType) => {
172+
return useQuery(userTransactionsQueryOptions(safeAddress, vault));
158173
};
159174

160175
export const useSendTransactions = (address: string) => {

hooks/useDepositCalculations.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useMemo, useRef } from 'react';
1+
import { useMemo } from 'react';
22

33
import { calculateOriginalDepositAmount, getEarliestDepositTimestamp } from '@/lib/financial';
44

@@ -8,34 +8,27 @@ export const useDepositCalculations = (
88
lastTimestamp?: number,
99
decimals: number = 6,
1010
) => {
11-
// Stabilize userDepositTransactions reference using JSON comparison
12-
// This prevents infinite re-renders when React Query returns new object references
11+
// Stabilize userDepositTransactions using JSON comparison
12+
// This prevents re-computation when React Query returns new object references
1313
// with identical data
14-
const transactionsRef = useRef(userDepositTransactions);
1514
const transactionsKey = useMemo(
1615
() => JSON.stringify(userDepositTransactions ?? null),
1716
[userDepositTransactions],
1817
);
1918

20-
// Update ref only when actual data changes (not just reference)
21-
useEffect(() => {
22-
transactionsRef.current = userDepositTransactions;
23-
}, [transactionsKey, userDepositTransactions]);
24-
2519
const originalDepositAmount = useMemo(() => {
2620
if (!balance || balance <= 0) return 0;
2721

28-
const calculated = calculateOriginalDepositAmount(transactionsRef.current, decimals);
22+
const calculated = calculateOriginalDepositAmount(userDepositTransactions, decimals);
2923
return calculated > 0 ? calculated : balance;
3024
// eslint-disable-next-line react-hooks/exhaustive-deps -- transactionsKey is intentional: stable JSON key replaces unstable object reference
3125
}, [transactionsKey, balance, decimals]);
3226

3327
const firstDepositTimestamp = useMemo(() => {
3428
if (!balance || balance <= 0) return undefined;
3529

36-
const fromSubgraph = getEarliestDepositTimestamp(transactionsRef.current, lastTimestamp);
30+
const fromSubgraph = getEarliestDepositTimestamp(userDepositTransactions, lastTimestamp);
3731
const now = Math.floor(Date.now() / 1000);
38-
const depositsLength = transactionsRef.current?.deposits?.length ?? 0;
3932

4033
let result: number | undefined;
4134
if (fromSubgraph && fromSubgraph > 0 && fromSubgraph <= now) {
@@ -44,7 +37,7 @@ export const useDepositCalculations = (
4437
result = lastTimestamp && lastTimestamp > 0 ? lastTimestamp : undefined;
4538
}
4639
return result;
47-
// eslint-disable-next-line react-hooks/exhaustive-deps -- transactionsKey is intentional: stable JSON key replaces unstable object reference
40+
// eslint-disable-next-line react-hooks/exhaustive-deps
4841
}, [transactionsKey, lastTimestamp, balance]);
4942

5043
return {

hooks/useSavingsYield.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export function useSavingsYield({
9797
return;
9898
}
9999

100-
// soUSD: subgraph-based calculation
100+
// soUSD / soETH: subgraph-based calculation
101101
let cancelled = false;
102102
const now = Math.floor(Date.now() / 1000);
103103
calculateYield(

0 commit comments

Comments
 (0)