mirror of
https://github.com/MetaFam/TheGame.git
synced 2026-04-24 03:00:09 -04:00
added token balance from seed-graph (#380)
This commit is contained in:
@@ -39,3 +39,15 @@ generates:
|
||||
content: '/* eslint-disable */'
|
||||
config:
|
||||
avoidOptionals: true
|
||||
./src/lib/autogen/seedgraph-sdk.ts:
|
||||
schema: 'https://api.thegraph.com/subgraphs/name/dan13ram/seed-graph'
|
||||
documents:
|
||||
- ./src/handlers/remote-schemas/resolvers/getTokenBalance/**/(!(*.d)).ts
|
||||
plugins:
|
||||
- typescript
|
||||
- typescript-operations
|
||||
- typescript-graphql-request
|
||||
- add:
|
||||
content: '/* eslint-disable */'
|
||||
config:
|
||||
avoidOptionals: true
|
||||
|
||||
@@ -2,6 +2,7 @@ interface IConfig {
|
||||
port: number;
|
||||
graphqlURL: string;
|
||||
daoHausGraphqlURL: string;
|
||||
seedGraphqlURL: string;
|
||||
adminKey: string;
|
||||
ipfsEndpoint: string;
|
||||
imgixToken: string;
|
||||
@@ -28,6 +29,10 @@ export const CONFIG: IConfig = {
|
||||
process.env.GRAPHQL_URL,
|
||||
'http://localhost:8080/v1/graphql',
|
||||
),
|
||||
seedGraphqlURL: parseEnv(
|
||||
process.env.SEED_GRAPHQL_URL,
|
||||
'https://api.thegraph.com/subgraphs/name/dan13ram/seed-graph',
|
||||
),
|
||||
daoHausGraphqlURL: parseEnv(
|
||||
process.env.DAOHAUS_GRAPHQL_URL,
|
||||
'https://api.thegraph.com/subgraphs/name/odyssy-automaton/daohaus',
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import { gql } from 'graphql-request/dist';
|
||||
|
||||
export const GetTokenBalance = gql`
|
||||
query GetTokenBalance($address: String!) {
|
||||
userTokens(where: { address: $address }) {
|
||||
id
|
||||
seedBalance
|
||||
pSeedBalance
|
||||
}
|
||||
}
|
||||
`;
|
||||
@@ -0,0 +1,17 @@
|
||||
import { seedGraphClient } from '../../../../lib/seedGraphClient';
|
||||
import { QueryResolvers } from '../../autogen/types';
|
||||
|
||||
export const getTokenBalance: QueryResolvers['getTokenBalance'] = async (
|
||||
_,
|
||||
{ address },
|
||||
) => {
|
||||
if (!address) return null;
|
||||
const res = await seedGraphClient.GetTokenBalance({
|
||||
address: address.toLowerCase(),
|
||||
});
|
||||
|
||||
if (res && res.userTokens && res.userTokens.length > 0) {
|
||||
return res.userTokens[0];
|
||||
}
|
||||
return null;
|
||||
};
|
||||
@@ -3,6 +3,7 @@ import { makeExecutableSchema } from 'graphql-tools';
|
||||
import { getBrightIdStatus } from './resolvers/brightId/resolver';
|
||||
import { getDaoHausMemberships } from './resolvers/daohaus/resolver';
|
||||
import { getBoxProfile } from './resolvers/getBoxProfile/resolver';
|
||||
import { getTokenBalance } from './resolvers/getTokenBalance/resolver';
|
||||
import { typeDefs } from './typeDefs';
|
||||
import { uuid } from './types/uuid';
|
||||
|
||||
@@ -11,6 +12,7 @@ const resolvers = {
|
||||
getBoxProfile,
|
||||
getDaoHausMemberships,
|
||||
getBrightIdStatus,
|
||||
getTokenBalance,
|
||||
},
|
||||
uuid,
|
||||
};
|
||||
|
||||
@@ -7,6 +7,7 @@ export const typeDefs = gql`
|
||||
getBoxProfile(address: String): BoxProfile
|
||||
getDaoHausMemberships(memberAddress: String): [Member!]!
|
||||
getBrightIdStatus(contextId: uuid): BrightIdStatus
|
||||
getTokenBalance(address: String): UserToken
|
||||
}
|
||||
|
||||
type BrightIdStatus {
|
||||
@@ -55,4 +56,10 @@ export const typeDefs = gql`
|
||||
exists: Boolean!
|
||||
kicked: Boolean
|
||||
}
|
||||
|
||||
type UserToken {
|
||||
id: ID!
|
||||
seedBalance: String!
|
||||
pSeedBalance: String!
|
||||
}
|
||||
`;
|
||||
|
||||
6
packages/backend/src/lib/seedGraphClient.ts
Normal file
6
packages/backend/src/lib/seedGraphClient.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { GraphQLClient } from 'graphql-request';
|
||||
|
||||
import { CONFIG } from '../config';
|
||||
import { getSdk } from './autogen/seedgraph-sdk';
|
||||
|
||||
export const seedGraphClient = getSdk(new GraphQLClient(CONFIG.seedGraphqlURL));
|
||||
Reference in New Issue
Block a user