Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Commit

Permalink
add throw error when passed wrong chain to approvalNeeded
Browse files Browse the repository at this point in the history
  • Loading branch information
DaoDev44 committed Oct 5, 2021
1 parent 916b49e commit c4ec9bd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
6 changes: 3 additions & 3 deletions packages/swapper/src/swappers/thorchain/ThorchainSwapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class ThorchainSwapper implements Swapper {

getMinMax(input: GetQuoteInput): Promise<MinMaxOutput> {
console.info(input)
throw new Error('Method not implemented.')
throw new Error('ThorchainSwapper: getMinMax unimplemented')
}

getAvailableAssets(assets: Asset[]): Asset[] {
Expand All @@ -47,10 +47,10 @@ export class ThorchainSwapper implements Swapper {
}

getDefaultPair(): Partial<Asset>[] {
throw new Error('Method not implemented.')
throw new Error('ThorchainSwapper: getDefaultPair unimplemented')
}

async approvalNeeded(): Promise<ApprovalNeededOutput> {
throw new Error('ThorchainSwapper: executeQuote unimplemented')
throw new Error('ThorchainSwapper: approvalNeeded unimplemented')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ describe('approvalNeeded', () => {
expect(await approvalNeeded(args, input)).toEqual({ approvalNeeded: false })
})

it('returns false if sellAsset chain is not ETH', async () => {
it('throws an error if sellAsset chain is not ETH', async () => {
const input = {
quote: { ...quoteInput, sellAsset: { ...sellAsset, chain: ChainTypes.Bitcoin } },
wallet
}

expect(await approvalNeeded(args, input)).toEqual({ approvalNeeded: false })
await expect(approvalNeeded(args, input)).rejects.toThrow(
'ZrxSwapper:approvalNeeded only Ethereum chain type is supported'
)
})

it('returns false if allowanceOnChain is greater than quote.sellAmount', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
DEFAULT_SLIPPAGE
} from '../utils/constants'

import { SwapError } from '../../../api'
import { ZrxSwapperDeps } from '../ZrxSwapper'
import { zrxService } from '../utils/zrxService'
import { getERC20Allowance } from '../utils/helpers/helpers'
Expand All @@ -26,10 +27,14 @@ export async function approvalNeeded(
): Promise<ApprovalNeededOutput> {
const { sellAsset } = quote

if (sellAsset.symbol === 'ETH' || sellAsset.chain !== ChainTypes.Ethereum) {
if (sellAsset.symbol === 'ETH') {
return { approvalNeeded: false }
}

if (sellAsset.chain !== ChainTypes.Ethereum) {
throw new SwapError('ZrxSwapper:approvalNeeded only Ethereum chain type is supported')
}

const adapter: ChainAdapter = adapterManager.byChain(sellAsset.chain)
const receiveAddress = await adapter.getAddress({ wallet, path: DEFAULT_ETH_PATH })

Expand Down

0 comments on commit c4ec9bd

Please sign in to comment.