2021-08-12 09:58:13 +00:00
|
|
|
//
|
|
|
|
// Copyright 2021 Vulcanize, Inc.
|
|
|
|
//
|
|
|
|
|
2021-07-07 05:40:10 +00:00
|
|
|
import { gql } from '@apollo/client/core';
|
2022-09-09 11:43:01 +00:00
|
|
|
import { GraphQLClient, GraphQLConfig } from '@cerc-io/ipld-eth-client';
|
2021-07-06 11:25:11 +00:00
|
|
|
|
2021-07-07 05:40:10 +00:00
|
|
|
import { queryName, queryDecimals, queryTotalSupply, querySymbol } from './queries';
|
2021-07-06 11:25:11 +00:00
|
|
|
|
|
|
|
export class Client {
|
2021-07-07 05:40:10 +00:00
|
|
|
_config: GraphQLConfig;
|
2021-07-06 11:25:11 +00:00
|
|
|
_client: GraphQLClient;
|
|
|
|
|
2021-07-07 05:40:10 +00:00
|
|
|
constructor (config: GraphQLConfig) {
|
2021-07-06 11:25:11 +00:00
|
|
|
this._config = config;
|
|
|
|
|
|
|
|
this._client = new GraphQLClient(config);
|
|
|
|
}
|
|
|
|
|
2021-07-07 05:40:10 +00:00
|
|
|
async getSymbol (blockHash: string, token: string): Promise<any> {
|
2021-07-06 11:25:11 +00:00
|
|
|
const { symbol } = await this._client.query(
|
|
|
|
gql(querySymbol),
|
|
|
|
{ blockHash, token }
|
|
|
|
);
|
|
|
|
|
|
|
|
return symbol;
|
|
|
|
}
|
2021-07-07 05:40:10 +00:00
|
|
|
|
|
|
|
async getName (blockHash: string, token: string): Promise<any> {
|
|
|
|
const { name } = await this._client.query(
|
|
|
|
gql(queryName),
|
|
|
|
{ blockHash, token }
|
|
|
|
);
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
async getTotalSupply (blockHash: string, token: string): Promise<any> {
|
|
|
|
const { totalSupply } = await this._client.query(
|
|
|
|
gql(queryTotalSupply),
|
|
|
|
{ blockHash, token }
|
|
|
|
);
|
|
|
|
|
|
|
|
return totalSupply;
|
|
|
|
}
|
|
|
|
|
|
|
|
async getDecimals (blockHash: string, token: string): Promise<any> {
|
|
|
|
const { decimals } = await this._client.query(
|
|
|
|
gql(queryDecimals),
|
|
|
|
{ blockHash, token }
|
|
|
|
);
|
|
|
|
|
|
|
|
return decimals;
|
|
|
|
}
|
2021-07-06 11:25:11 +00:00
|
|
|
}
|