This repository was archived by the owner on Apr 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
85 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
packages/swapper/src/swappers/zrx/approvalNeeded/approvalNeeded.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Web3 from 'web3' | ||
import { HDWallet } from '@shapeshiftoss/hdwallet-core' | ||
import { ChainTypes } from '@shapeshiftoss/types' | ||
import { ChainAdapterManager } from '@shapeshiftoss/chain-adapters' | ||
import { approvalNeeded } from './approvalNeeded' | ||
import { setupQuote } from '../utils/test-data/setupSwapQuote' | ||
|
||
const setup = () => { | ||
const unchainedUrls = { | ||
[ChainTypes.Ethereum]: 'http://localhost:31300/api/v1' | ||
} | ||
const ethNodeUrl = 'http://localhost:1000' | ||
const adapterManager = new ChainAdapterManager(unchainedUrls) | ||
const web3Provider = new Web3.providers.HttpProvider(ethNodeUrl) | ||
const web3 = new Web3(web3Provider) | ||
|
||
return { web3, adapterManager } | ||
} | ||
|
||
describe('approvalNeeded', () => { | ||
const args = setup() | ||
const wallet = <HDWallet>{} | ||
const { quoteInput, sellAsset } = setupQuote() | ||
|
||
it('returns false if sellAsset symbol is ETH', async () => { | ||
const input = { quote: { ...quoteInput, sellAsset: { ...sellAsset, symbol: 'ETH' } }, wallet } | ||
|
||
expect(await approvalNeeded(args, input)).toEqual({ approvalNeeded: false }) | ||
}) | ||
}) |
22 changes: 22 additions & 0 deletions
22
packages/swapper/src/swappers/zrx/approvalNeeded/approvalNeeded.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { AxiosResponse } from 'axios' | ||
import { ChainAdapter } from '@shapeshiftoss/chain-adapters' | ||
import { ApprovalNeededInput, ApprovalNeededOutput, ChainTypes, QuoteResponse } from '@shapeshiftoss/types' | ||
import { DEFAULT_SLIPPAGE, AFFILIATE_ADDRESS, DEFAULT_ETH_PATH } from '../utils/constants' | ||
|
||
import { ZrxSwapperDeps } from '../ZrxSwapper' | ||
import { zrxService } from '../utils/zrxService' | ||
const APPROVAL_BUY_AMOUNT = '100000000000000000' // A valid buy amount - 0.1 ETH | ||
|
||
export async function approvalNeeded( | ||
{ adapterManager }: ZrxSwapperDeps, | ||
{ quote, wallet }: ApprovalNeededInput | ||
): Promise<ApprovalNeededOutput> { | ||
const { sellAsset } = quote | ||
|
||
if (sellAsset.symbol === 'ETH' || sellAsset.chain !== ChainTypes.Ethereum) { | ||
return { approvalNeeded: false } | ||
} | ||
|
||
|
||
return { approvalNeeded: true } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters