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

Order processor UI #208

Merged
merged 25 commits into from
Aug 15, 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
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ WS_REGIONX_COCOS_CHAIN="WSS endpoint of the regionx chain"

ROCOCO_CORETIME_INDEXER="Subquery indexer for Rococo Coretime"
KUSAMA_CORETIME_INDEXER="Subquery indexer for Kusama Coretime"
COCOS_INDEXER="Subquery indexer for RegionX Cocos"

ROCOCO_CORETIME_DICT="Subquery dictionary for Rococo Coretime"
KUSAMA_CORETIME_DICT="Subquery dictionary for Kusama Coretime"
Expand Down
2 changes: 2 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const nextConfig = {
WS_KUSAMA_CORETIME_CHAIN: process.env.WS_KUSAMA_CORETIME_CHAIN || '',
WS_WESTEND_CORETIME_CHAIN: process.env.WS_WESTEND_CORETIME_CHAIN || '',

COCOS_INDEXER: process.env.COCOS_INDEXER || '',

ROCOCO_CORETIME_INDEXER: process.env.ROCOCO_CORETIME_INDEXER || '',
KUSAMA_CORETIME_INDEXER: process.env.KUSAMA_CORETIME_INDEXER || '',
SUBSCAN_CORETIME_WESTEND_INDEXER:
Expand Down
34 changes: 34 additions & 0 deletions src/apis/accounts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { fetchGraphql } from '@/utils/fetchGraphql';

import { API_CORETIME_DICT } from '@/consts';
import { Address, ApiResponse, NetworkType } from '@/models';

export const fetchAccountExtrinsics = async (
network: NetworkType,
address: Address,
after: string | null,
orderBy = 'BLOCK_HEIGHT_DESC'
): Promise<ApiResponse> => {
const query = `{
extrinsics(
after: ${after}
filter: {signer: {equalTo: "${address}"}}
orderBy: ${orderBy}
) {
nodes {
id
module
call
blockHeight
success
timestamp
}
pageInfo {
hasNextPage
endCursor
}
totalCount
}
}`;
return fetchGraphql(API_CORETIME_DICT[network], query);
};
151 changes: 3 additions & 148 deletions src/apis/index.ts
Original file line number Diff line number Diff line change
@@ -1,148 +1,3 @@
import { API_CORETIME_DICT, API_CORETIME_INDEXER } from '@/consts';
import { Address, ApiResponse, NetworkType } from '@/models';

import { fetchGraphql } from '../utils/fetchGraphql';

export const fetchBurnInfo = async (
network: NetworkType
): Promise<ApiResponse> => {
const query = `{
stats {
nodes {
id
saleCycle
totalBurn
}
}
sales(
orderBy: HEIGHT_DESC,
first: 2
) {
nodes {
burn
}
}
}`;
return fetchGraphql(API_CORETIME_INDEXER[network], query);
};

export const fetchPurchaseHistoryData = async (
network: NetworkType,
regionBegin: number,
after: string | null,
orderBy = 'HEIGHT_DESC'
): Promise<ApiResponse> => {
const query = `{
purchases(
after: ${after}
filter: {begin: {equalTo: ${regionBegin}}}
orderBy: ${orderBy}
) {
nodes {
account
core
extrinsicId
height
price
purchaseType
timestamp
}
pageInfo {
hasNextPage
endCursor
}
totalCount
}
}`;
return fetchGraphql(API_CORETIME_INDEXER[network], query);
};

export const fetchSaleDetailsData = async (
network: NetworkType,
saleCycle: number,
after: string | null,
orderBy = 'HEIGHT_DESC'
): Promise<ApiResponse> => {
const query = `{
purchases(
filter: {saleCycle: {equalTo: ${saleCycle}}}
after: ${after ? `"${after}"` : null}
orderBy: ${orderBy}
) {
nodes {
account
core
extrinsicId
height
price
purchaseType
timestamp
}
pageInfo {
hasNextPage
endCursor
}
totalCount
}
}`;
return fetchGraphql(API_CORETIME_INDEXER[network], query);
};

export const fetchSalesHistoryData = async (
network: NetworkType,
after: string | null
): Promise<ApiResponse> => {
const query = `{
sales(
after: ${after},
orderBy: SALE_CYCLE_DESC
) {
nodes {
saleCycle
regionBegin
regionEnd
height
saleEnd
timestamp
tsSaleEnd
startPrice
endPrice
}
pageInfo {
hasNextPage
endCursor
}
}
}`;
return fetchGraphql(API_CORETIME_INDEXER[network], query);
};

export const fetchAccountExtrinsics = async (
network: NetworkType,
address: Address,
after: string | null,
orderBy = 'BLOCK_HEIGHT_DESC'
): Promise<ApiResponse> => {
const query = `{
extrinsics(
after: ${after}
filter: {signer: {equalTo: "${address}"}}
orderBy: ${orderBy}
) {
nodes {
id
module
call
blockHeight
success
timestamp
}
pageInfo {
hasNextPage
endCursor
}
totalCount
}
}`;
return fetchGraphql(API_CORETIME_DICT[network], query);
};
export * from './accounts';
export * from './orders';
export * from './sales';
77 changes: 77 additions & 0 deletions src/apis/orders.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { fetchGraphql } from '@/utils/fetchGraphql';

import { API_COCOS_INDEXER } from '@/consts';
import { Address, ApiResponse } from '@/models';

export const fetchContribution = async (
orderId: number,
address: Address | undefined,
after: string | null
): Promise<ApiResponse> => {
const query = `{
orderContributions(
after: ${after}
filter: {orderId: {equalTo: ${orderId}}, account: {equalTo: "${address}"}}
) {
nodes {
amount
}
pageInfo {
hasNextPage
endCursor
}
}
}`;
return fetchGraphql(API_COCOS_INDEXER, query);
};

export const fetchOrders = async (
after: string | null
): Promise<ApiResponse> => {
const query = `{
orders(after: ${after}) {
nodes {
orderId
begin
end
creator
exist
coreOccupancy
contribution
paraId
processed
}
pageInfo {
hasNextPage
endCursor
}
}
}`;
return fetchGraphql(API_COCOS_INDEXER, query);
};

export const fetchProcessedOrders = async (
after: string | null,
order = 'ORDER_ID_ASC'
): Promise<ApiResponse> => {
const query = `{
processedOrders(after: ${after}, orderBy: ${order}) {
nodes {
orderId
height
extrinsicId
timestamp
begin
core
mask
seller
reward
}
pageInfo {
hasNextPage
endCursor
}
}
}`;
return fetchGraphql(API_COCOS_INDEXER, query);
};
Loading
Loading