diff --git a/src/schema.graphql b/src/schema.graphql index ca20336..8a54595 100644 --- a/src/schema.graphql +++ b/src/schema.graphql @@ -26,15 +26,20 @@ type EstimatedAmount { minAmount: String! } -type PairTokensFromNativeCurrency { - pairTokens: [String!]! +type GetPairTokens { + pairs: [Pairs!]! +} + +type Pairs { + asset: String! + pairs: [String!]! } type Query { createSwap(addressTo: String! = "", amountFrom: String! = "", currencyFrom: String! = "", currencyTo: String! = ""): CreateSwap! getActiveSwaps(swapsIds: [String!]! = []): [ActiveSwaps!]! getEstimatedAmount(amount: String! = "", from: String! = "", to: String! = ""): EstimatedAmount! - getPairTokensFromNativeCurrency(nativeCurrency: String! = ""): PairTokensFromNativeCurrency! + getPairTokensFromNativeCurrency(nativeCurrencies: [String!]! = []): GetPairTokens! getTokens: Tokens! status: String! version: String! diff --git a/src/stealthex/dtos/get-pairs-tokens.dto.ts b/src/stealthex/dtos/get-pairs-tokens.dto.ts index 3be1847..084370e 100644 --- a/src/stealthex/dtos/get-pairs-tokens.dto.ts +++ b/src/stealthex/dtos/get-pairs-tokens.dto.ts @@ -1,7 +1,22 @@ -import { ArgsType, Field } from '@nestjs/graphql' +import { ArgsType, Field, ObjectType } from '@nestjs/graphql' @ArgsType() -export class GetPairTokens { +export class GetPairTokensArgs { + @Field(() => [String]) + nativeCurrencies: string[] = [] +} + +@ObjectType() +export class Pairs { @Field(() => String) - nativeCurrency: string = '' + asset: string = '' + + @Field(() => [String]) + pairs: string[] = [] +} + +@ObjectType() +export class GetPairTokens { + @Field(() => [Pairs]) + pairs = [] } diff --git a/src/stealthex/stealhtex.service.ts b/src/stealthex/stealhtex.service.ts index db86b7c..03e02a3 100644 --- a/src/stealthex/stealhtex.service.ts +++ b/src/stealthex/stealhtex.service.ts @@ -53,11 +53,20 @@ export class StealthExService { return data } - async getPairTokensFromNativeCurrency({ nativeCurrency }: { nativeCurrency: string }) { - const { data } = await this.sendPetition({ - path: `pairs/${nativeCurrency}`, - method: 'get', - }) + async getPairTokensFromNativeCurrency({ nativeCurrencies }: { nativeCurrencies: string[] }) { + const data = await Promise.all( + nativeCurrencies.map(async (nativeCurrency) => { + const { data } = await this.sendPetition({ + path: `pairs/${nativeCurrency}`, + method: 'get', + }) + + return { + asset: nativeCurrency, + pairs: data, + } + }), + ) return data } diff --git a/src/stealthex/stealthex.resolver.ts b/src/stealthex/stealthex.resolver.ts index f5da6e7..8e11859 100644 --- a/src/stealthex/stealthex.resolver.ts +++ b/src/stealthex/stealthex.resolver.ts @@ -2,8 +2,8 @@ import { Args, Query, Resolver } from '@nestjs/graphql' import { CreateSwapArgs, CreateSwap } from './dtos/create-swap.dto' import { ActiveSwaps, ActiveSwapsArgs } from './dtos/get-active-swaps.dto' import { EstimatedAmount, GetEstimatedAmount } from './dtos/get-estimated-amount.dto' -import { GetPairTokens } from './dtos/get-pairs-tokens.dto' -import { PairTokensFromNativeCurrency, Tokens } from './dtos/get-tokens.dto' +import { GetPairTokens, GetPairTokensArgs } from './dtos/get-pairs-tokens.dto' +import { Tokens } from './dtos/get-tokens.dto' import { StealthExService } from './stealhtex.service' @Resolver() @@ -24,11 +24,11 @@ export class StealhExResolver { } } - @Query(() => PairTokensFromNativeCurrency) - async getPairTokensFromNativeCurrency(@Args() args: GetPairTokens) { - const pairTokens = await this.stealthexService.getPairTokensFromNativeCurrency(args) + @Query(() => GetPairTokens) + async getPairTokensFromNativeCurrency(@Args() args: GetPairTokensArgs) { + const pairs = await this.stealthexService.getPairTokensFromNativeCurrency(args) return { - pairTokens, + pairs, } }