Skip to content

Commit b721e89

Browse files
authored
fix(tangle-dapp): update result type and reduce refetch interval in useCredits (#3026)
1 parent 9a530cf commit b721e89

File tree

9 files changed

+27
-31
lines changed

9 files changed

+27
-31
lines changed

apps/leaderboard/src/features/leaderboard/components/LeaderboardTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ export const LeaderboardTable = () => {
204204
});
205205

206206
// TODO: Add network tabs when we support both mainnet and testnet
207-
const [networkTab] = useState<NetworkType.Testnet>(NetworkType.Testnet);
207+
const [networkTab] = useState<NetworkType>('TESTNET');
208208

209209
const {
210210
data: latestBlock,

apps/leaderboard/src/features/leaderboard/queries/accountIdentitiesQuery.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { NetworkType } from '@tangle-network/tangle-shared-ui/graphql/graphql';
21
import {
32
getMultipleAccountInfo,
43
IdentityType,
@@ -9,13 +8,13 @@ import { getRpcEndpoint } from '../../../utils/getRpcEndpoint';
98
import { Account } from '../types';
109

1110
const fetcher = async (accounts: Pick<Account, 'id' | 'network'>[]) => {
12-
const { testnetRpc, mainnetRpc } = getRpcEndpoint('all');
11+
const { testnetRpc, mainnetRpc } = getRpcEndpoint('ALL');
1312

1413
const testnetAccounts: string[] = [];
1514
const mainnetAccounts: string[] = [];
1615

1716
accounts.forEach((account) => {
18-
if (account.network === NetworkType.Testnet) {
17+
if (account.network === 'TESTNET') {
1918
testnetAccounts.push(account.id);
2019
} else {
2120
mainnetAccounts.push(account.id);

apps/leaderboard/src/features/leaderboard/utils/createAccountExplorerUrl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ export const createAccountExplorerUrl = (
1313
network: NetworkType,
1414
) => {
1515
switch (network) {
16-
case NetworkType.Mainnet:
16+
case 'MAINNET':
1717
return TANGLE_MAINNET_NETWORK.createExplorerAccountUrl(address);
18-
case NetworkType.Testnet:
18+
case 'TESTNET':
1919
return TANGLE_TESTNET_NATIVE_NETWORK.createExplorerAccountUrl(address);
2020
default:
2121
console.error(`Unsupported network: ${network}`);

apps/leaderboard/src/features/leaderboard/utils/processLeaderboardRecord.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { ZERO_BIG_INT } from '@tangle-network/dapp-config/constants';
2-
import { NetworkType } from '@tangle-network/tangle-shared-ui/graphql/graphql';
32
import type { IdentityType } from '@tangle-network/tangle-shared-ui/utils/polkadot/identity';
43
import { toBigInt } from '@tangle-network/ui-components';
54
import find from 'lodash/find';
@@ -252,6 +251,6 @@ export const processLeaderboardRecord = (
252251
lastUpdatedAtTimestamp: record.lastUpdatedAtTimestamp,
253252
identity,
254253
// TODO: This should fetch from the API once the server supports multi-chain
255-
network: NetworkType.Testnet,
254+
network: 'TESTNET',
256255
} satisfies Account;
257256
};

apps/leaderboard/src/queries/latestFinalizedBlockQuery.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { NetworkType } from '@tangle-network/tangle-shared-ui/graphql/graphql';
21
import { getApiPromise } from '@tangle-network/tangle-shared-ui/utils/polkadot/api';
32
import { useQuery } from '@tanstack/react-query';
43
import { LATEST_FINALIZED_BLOCK_QUERY_KEY } from '../constants/query';
@@ -11,12 +10,12 @@ type UseLatestFinalizedBlockResult<TNetwork extends Network> =
1110
mainnetBlock: number;
1211
testnetBlock: number;
1312
}
14-
: TNetwork extends NetworkType.Testnet
13+
: TNetwork extends 'TESTNET'
1514
? {
1615
mainnetBlock: never;
1716
testnetBlock: number;
1817
}
19-
: TNetwork extends NetworkType.Mainnet
18+
: TNetwork extends 'MAINNET'
2019
? {
2120
mainnetBlock: number;
2221
testnetBlock: never;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import { NetworkType } from '@tangle-network/tangle-shared-ui/graphql/graphql';
22

3-
export type Network = 'all' | NetworkType.Testnet | NetworkType.Mainnet;
3+
export type Network = 'ALL' | NetworkType;

apps/leaderboard/src/utils/getRpcEndpoint.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,41 @@
1-
import { NetworkType } from '@tangle-network/tangle-shared-ui/graphql/graphql';
2-
import { Network } from '../types';
31
import {
42
TANGLE_MAINNET_WS_DWELLIR_RPC_ENDPOINT,
53
TANGLE_TESTNET_WS_RPC_ENDPOINT,
64
} from '@tangle-network/dapp-config';
5+
import { Network } from '../types';
76

8-
type GetRpcEndpointResult<TNetwork extends Network> =
9-
TNetwork extends NetworkType.Testnet
7+
type GetRpcEndpointResult<TNetwork extends Network> = TNetwork extends 'TESTNET'
8+
? {
9+
testnetRpc: typeof TANGLE_TESTNET_WS_RPC_ENDPOINT;
10+
mainnetRpc: undefined;
11+
}
12+
: TNetwork extends 'MAINNET'
1013
? {
11-
testnetRpc: typeof TANGLE_TESTNET_WS_RPC_ENDPOINT;
12-
mainnetRpc: undefined;
14+
testnetRpc: undefined;
15+
mainnetRpc: typeof TANGLE_MAINNET_WS_DWELLIR_RPC_ENDPOINT;
1316
}
14-
: TNetwork extends NetworkType.Mainnet
17+
: TNetwork extends 'ALL'
1518
? {
16-
testnetRpc: undefined;
19+
testnetRpc: typeof TANGLE_TESTNET_WS_RPC_ENDPOINT;
1720
mainnetRpc: typeof TANGLE_MAINNET_WS_DWELLIR_RPC_ENDPOINT;
1821
}
19-
: TNetwork extends 'all'
20-
? {
21-
testnetRpc: typeof TANGLE_TESTNET_WS_RPC_ENDPOINT;
22-
mainnetRpc: typeof TANGLE_MAINNET_WS_DWELLIR_RPC_ENDPOINT;
23-
}
24-
: never;
22+
: never;
2523

2624
export function getRpcEndpoint<TNetwork extends Network>(
2725
network: TNetwork,
2826
): GetRpcEndpointResult<TNetwork> {
2927
switch (network) {
30-
case NetworkType.Testnet:
28+
case 'TESTNET':
3129
return {
3230
testnetRpc: TANGLE_TESTNET_WS_RPC_ENDPOINT,
3331
mainnetRpc: undefined,
3432
} as GetRpcEndpointResult<TNetwork>;
35-
case NetworkType.Mainnet:
33+
case 'MAINNET':
3634
return {
3735
testnetRpc: undefined,
3836
mainnetRpc: TANGLE_MAINNET_WS_DWELLIR_RPC_ENDPOINT,
3937
} as GetRpcEndpointResult<TNetwork>;
40-
case 'all':
38+
case 'ALL':
4139
return {
4240
testnetRpc: TANGLE_TESTNET_WS_RPC_ENDPOINT,
4341
mainnetRpc: TANGLE_MAINNET_WS_DWELLIR_RPC_ENDPOINT,

apps/tangle-dapp/src/data/credits/useCredits.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const responseSchema = z.union([
7575
z.object({
7676
id: z.number(),
7777
jsonrpc: z.string(),
78-
result: z.bigint(),
78+
result: z.bigint().or(z.number()),
7979
}),
8080
]);
8181

@@ -149,7 +149,7 @@ export function getQueryOptions(
149149
queryKey: [ReactQueryKey.GetCredits, rpcEndpoint, activeSubstrateAddress],
150150
queryFn: () => fetcher(rpcEndpoint, activeSubstrateAddress),
151151
retry: 3,
152-
refetchInterval: 30000, // Refetch every 30 seconds
152+
refetchInterval: 6000, // Refetch every 6 seconds
153153
placeholderData: (prev) => prev,
154154
});
155155
}

codegen.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const config: CodegenConfig = {
1717
config: {
1818
defaultScalarType: 'unknown',
1919
documentMode: 'string',
20+
enumsAsTypes: true,
2021
scalars: {
2122
BigFloat: 'string',
2223
Date: 'Date',

0 commit comments

Comments
 (0)