Skip to content

Commit

Permalink
feat(idea/frontend): migrate to subsquid indexer (#1602)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitayutanov authored Jul 30, 2024
1 parent ee2773c commit fdd0a87
Show file tree
Hide file tree
Showing 247 changed files with 2,062 additions and 3,444 deletions.
1 change: 1 addition & 0 deletions idea/frontend/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
VITE_API_URL=
VITE_INDEXER_API_URL=
VITE_MAINNET_VOUCHERS_API_URL=
VITE_TESTNET_VOUCHERS_API_URL=
VITE_NODES_API_URL=
Expand Down
4 changes: 1 addition & 3 deletions idea/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"lodash.isequal": "4.5.0",
"lodash.isplainobject": "4.0.6",
"lodash.isstring": "4.0.1",
"lodash.throttle": "4.1.1",
"react": "18.2.0",
"react-dnd": "16.0.1",
"react-dnd-html5-backend": "16.0.1",
Expand All @@ -48,7 +47,6 @@
"@types/lodash.isequal": "4.5.6",
"@types/lodash.isplainobject": "4.0.7",
"@types/lodash.isstring": "4.0.7",
"@types/lodash.throttle": "4.1.7",
"@types/node": "20.8.4",
"@types/react": "18.2.36",
"@types/react-dom": "18.2.14",
Expand All @@ -66,7 +64,7 @@
"eslint-plugin-react-hooks": "4.6.0",
"eslint-plugin-react-refresh": "0.4.3",
"sass": "1.69.1",
"typescript": "5.2.2",
"typescript": "5.5.3",
"vite": "4.4.11",
"vite-plugin-checker": "0.6.2",
"vite-plugin-node-polyfills": "0.15.0",
Expand Down
3 changes: 0 additions & 3 deletions idea/frontend/src/api/code/index.ts

This file was deleted.

16 changes: 0 additions & 16 deletions idea/frontend/src/api/code/requests.ts

This file was deleted.

8 changes: 0 additions & 8 deletions idea/frontend/src/api/code/types.ts

This file was deleted.

12 changes: 11 additions & 1 deletion idea/frontend/src/api/consts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { getNextPageParam, select } from './utils';

enum OwnerFilter {
All = 'all',
User = 'user',
}

export { OwnerFilter };
// there's a problem with return type of select if those options are destructured to useInfiniteQuery,
// therefore a little bit of boilerplate is needed. need to figure it out
const INFINITE_QUERY = {
INITIAL_PAGE_PARAM: 0,
GET_NEXT_PAGE_PARAM: getNextPageParam,
SELECT: select,
};

export { OwnerFilter, INFINITE_QUERY };
27 changes: 6 additions & 21 deletions idea/frontend/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
import { NodeSection } from '@/entities/node';
import { NODES_API_URL } from '@/shared/config';
import { fetchCode, fetchCodes, addCodeName } from './code';
import { fetchProgram, fetchPrograms, addProgramName } from './program';

import { fetchTestBalance } from './balance';
import { fetchMessage, fetchMessages } from './message';
import { fetchMetadata, addMetadata } from './metadata';
import { addState, fetchStates, fetchState } from './state';
import { PaginationParameters, PaginationResponse } from './types';
import { INFINITE_QUERY } from './consts';

const getNodes = () => fetch(NODES_API_URL).then((result) => result.json() as unknown as NodeSection[]);

export {
getNodes,
fetchProgram,
addProgramName,
fetchPrograms,
addMetadata,
addCodeName,
fetchMetadata,
addState,
fetchStates,
fetchState,
fetchCode as getCode,
fetchCodes as getCodes,
fetchMessage as getMessage,
fetchMessages as getMessages,
fetchTestBalance as getTestBalance,
};
export { INFINITE_QUERY, getNodes, addMetadata, fetchMetadata, fetchTestBalance as getTestBalance };

export type { PaginationParameters, PaginationResponse };
3 changes: 0 additions & 3 deletions idea/frontend/src/api/message/index.ts

This file was deleted.

14 changes: 0 additions & 14 deletions idea/frontend/src/api/message/requests.ts

This file was deleted.

11 changes: 0 additions & 11 deletions idea/frontend/src/api/message/types.ts

This file was deleted.

5 changes: 0 additions & 5 deletions idea/frontend/src/api/program/index.ts

This file was deleted.

16 changes: 0 additions & 16 deletions idea/frontend/src/api/program/requests.ts

This file was deleted.

20 changes: 0 additions & 20 deletions idea/frontend/src/api/program/types.ts

This file was deleted.

3 changes: 0 additions & 3 deletions idea/frontend/src/api/state/index.ts

This file was deleted.

15 changes: 0 additions & 15 deletions idea/frontend/src/api/state/requests.ts

This file was deleted.

14 changes: 7 additions & 7 deletions idea/frontend/src/api/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
type PaginationModel = {
publicKeyRaw?: string | null;
source?: string | null;
destination?: string | null;
type PaginationParameters = {
limit?: number;
offset?: number;
type?: string;
query?: string;
};

export type { PaginationModel };
type PaginationResponse<T> = {
result: T[];
count: number;
};

export type { PaginationParameters, PaginationResponse };
17 changes: 17 additions & 0 deletions idea/frontend/src/api/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { DEFAULT_LIMIT } from '@/shared/config';

import { PaginationResponse } from './types';

const getNextPageParam = <T>({ result, count }: PaginationResponse<T>, allPages: PaginationResponse<T>[]) => {
const lastPageCount = result.length;
const fetchedCount = (allPages.length - 1) * DEFAULT_LIMIT + lastPageCount;

return fetchedCount < count ? fetchedCount : undefined;
};

const select = <T>({ pages }: { pages: PaginationResponse<T>[] }) => ({
result: pages.flatMap((page) => page.result),
count: pages[0].count,
});

export { getNextPageParam, select };
4 changes: 2 additions & 2 deletions idea/frontend/src/app/providers/blocks/Context.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createContext } from 'react';

import { IChainBlock } from '@/entities/chainBlock';
import { RecentBlock } from '@/features/recentBlocks';

const BlocksContext = createContext<IChainBlock[]>([]);
const BlocksContext = createContext<RecentBlock[]>([]);

export { BlocksContext };
6 changes: 3 additions & 3 deletions idea/frontend/src/app/providers/blocks/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ReactNode, useState, useEffect } from 'react';
import { useApi } from '@gear-js/react-hooks';
import { Header } from '@polkadot/types/interfaces';

import { IChainBlock } from '@/entities/chainBlock';
import { RecentBlock } from '@/features/recentBlocks';

import { BlocksContext } from './Context';
import { getTime, getBlock } from './helpers';
Expand All @@ -13,9 +13,9 @@ type Props = {

const BlocksProvider = ({ children }: Props) => {
const { api, isApiReady } = useApi();
const [blocks, setBlocks] = useState<IChainBlock[]>([]);
const [blocks, setBlocks] = useState<RecentBlock[]>([]);

const updateBlocks = (block: IChainBlock) =>
const updateBlocks = (block: RecentBlock) =>
setBlocks((prevBlocks) => {
const blocksTail = prevBlocks.length > 9 ? prevBlocks.slice(0, -1) : prevBlocks;

Expand Down
6 changes: 3 additions & 3 deletions idea/frontend/src/app/providers/chain/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ProviderProps, useApi } from '@gear-js/react-hooks';
import { useEffect, useState } from 'react';

import { RpcMethods } from '@/shared/config';
import { RPCService } from '@/shared/services/rpcService';
import { rpcService } from '@/shared/services/rpcService';

import { ChainContext } from './Context';

Expand All @@ -21,7 +21,7 @@ const ChainProvider = ({ children }: ProviderProps) => {

if (!genesis) return;

new RPCService().callRPC<boolean>(RpcMethods.NetworkData, { genesis }).then(({ result }) => setIsDevChain(!result));
rpcService.callRPC<boolean>(RpcMethods.NetworkData, { genesis }).then(({ result }) => setIsDevChain(!result));
}, [genesis]);

useEffect(() => {
Expand All @@ -32,7 +32,7 @@ const ChainProvider = ({ children }: ProviderProps) => {
if (isDevChain) {
setIsTestBalanceAvailable(true);
} else {
new RPCService()
rpcService
.callRPC<boolean>(RpcMethods.TestBalanceAvailable, { genesis })
.then(({ result }) => setIsTestBalanceAvailable(result));
}
Expand Down
2 changes: 1 addition & 1 deletion idea/frontend/src/app/providers/onboarding/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { disableScroll, enableScroll, isMobileDevice } from '@/shared/helpers';
import { OnboardingContext } from './Context';
import { getHeading, getText } from './helpers';

const steps = ['wallet', 'program', 'code', 'codes', 'message', 'messages', 'explorer', 'mailbox', 'apps', 'node'];
const steps = ['wallet', 'program', 'code', 'codes', 'message', 'explorer', 'mailbox', 'apps', 'node'];

const { Provider } = OnboardingContext;

Expand Down
18 changes: 6 additions & 12 deletions idea/frontend/src/app/providers/onboarding/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,15 @@ const getHeading = (stepIndex: number) => {
return 'This option allows you to send a message to a program';

case 5:
return 'The list of messages can be found here';

case 6:
return 'Explorer';

case 7:
case 6:
return 'Mailbox';

case 8:
case 7:
return 'App examples';

case 9:
case 8:
return 'Network switcher';

default:
Expand All @@ -53,18 +50,15 @@ const getText = (stepIndex: number) => {
return "Copy destination program's address where to send a message and provide necessary details in the Payload section, click the “Calculate gas” and “Send message” buttons. You will be prompted to sign the transaction for the message sending.";

case 5:
return 'You can navigate to necessary messages using search by program id, message id or applying filters';

case 6:
return 'Here you can get details about recent network events, search by block hash or block number or apply filters';

case 7:
case 6:
return 'Here you can check messages sent from programs to currently connected account.';

case 8:
case 7:
return 'If you do not have a program to upload, check a broad library of smart-contract examples created by Gear team and find what best fits your use cases. You can take it as is or adapt to your needs.';

case 9:
case 8:
return "Select the network you're working with, connect to your local test net or localhost Gear node";

default:
Expand Down
3 changes: 0 additions & 3 deletions idea/frontend/src/entities/chainBlock/index.ts

This file was deleted.

9 changes: 0 additions & 9 deletions idea/frontend/src/entities/chainBlock/model/types.ts

This file was deleted.

6 changes: 0 additions & 6 deletions idea/frontend/src/entities/code/index.ts

This file was deleted.

6 changes: 0 additions & 6 deletions idea/frontend/src/entities/code/model/consts.ts

This file was deleted.

5 changes: 0 additions & 5 deletions idea/frontend/src/entities/code/model/index.ts

This file was deleted.

Loading

0 comments on commit fdd0a87

Please sign in to comment.