import { TokenDistributeRequestEntity } from '../../types'; import { splitAddress } from './utils'; export const TOKEN_DISTRIBUTE_REQUESTS_QUERY = `query tokenDistributeRequests($limit: Int, $offset: Int, $address: Bytes!) { tokenDistributeRequests( first: $limit skip: $offset orderBy: createdAt orderDirection: desc where: {sender: $address} ) { id status name maxAmountPerAddress expiry token { id } sender { id name } coordinate cooltime amountPerWithdrawal amount totalAmount createdAt txHash } }`; export interface TokenDistributeRequestsEntities { tokenDistributeRequests: { id: string; status: 'PENDING' | 'COMPLETED' | 'CANCELLED'; name: string; maxAmountPerAddress: string; expiry: string; token: { id: string; }; sender: { id: string; name?: string; }; coordinate: string; cooltime: string; amountPerWithdrawal: string; amount: string; totalAmount: string; createdAt: string; txHash: string; }[]; } export function transform( entities: TokenDistributeRequestsEntities ): TokenDistributeRequestEntity[] { return entities.tokenDistributeRequests.map((entity) => ({ id: entity.id, status: entity.status, name: entity.name, maxAmountPerAddress: BigInt(entity.maxAmountPerAddress), expiry: Number(entity.expiry), token: entity.token.id, sender: entity.sender.id, senderName: entity.sender.name || splitAddress(entity.sender.id), coordinate: entity.coordinate, cooltime: Number(entity.cooltime), amountPerWithdrawal: BigInt(entity.amountPerWithdrawal), amount: BigInt(entity.amount), totalAmount: BigInt(entity.totalAmount), createdAt: Number(entity.createdAt), txHash: entity.txHash, })); }