Skip to content

Commit

Permalink
get pairs tokens to multiple assets
Browse files Browse the repository at this point in the history
Signed-off-by: Ruben <rubdeivis@gmail.com>
  • Loading branch information
rubenguc committed Nov 9, 2023
1 parent cb7b4f2 commit d4044b9
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 17 deletions.
11 changes: 8 additions & 3 deletions src/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
21 changes: 18 additions & 3 deletions src/stealthex/dtos/get-pairs-tokens.dto.ts
Original file line number Diff line number Diff line change
@@ -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 = []
}
19 changes: 14 additions & 5 deletions src/stealthex/stealhtex.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 6 additions & 6 deletions src/stealthex/stealthex.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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,
}
}

Expand Down

0 comments on commit d4044b9

Please sign in to comment.