Skip to content

Commit

Permalink
fix: improve typesafety of buildSwapTransaction and getSwapQuote (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dschlabach authored Jan 21, 2025
1 parent cc1ac71 commit bbaceed
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
8 changes: 3 additions & 5 deletions src/core/api/buildSwapTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { getSwapErrorCode } from '../../swap/utils/getSwapErrorCode';
import { CDP_GET_SWAP_TRADE } from '../network/definitions/swap';
import { sendRequest } from '../network/request';
import type {
APIError,
BuildSwapTransactionParams,
BuildSwapTransactionResponse,
SwapAPIParams,
Expand All @@ -23,14 +22,13 @@ export async function buildSwapTransaction(
isAmountInDecimals: false,
};

const apiParamsOrError = getAPIParamsForToken({
let apiParams = getAPIParamsForToken({
...defaultParams,
...params,
});
if ((apiParamsOrError as APIError).error) {
return apiParamsOrError as APIError;
if ('error' in apiParams) {
return apiParams;
}
let apiParams = apiParamsOrError as SwapAPIParams;

if (!params.useAggregator) {
apiParams = {
Expand Down
8 changes: 3 additions & 5 deletions src/core/api/getSwapQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { getSwapErrorCode } from '../../swap/utils/getSwapErrorCode';
import { CDP_GET_SWAP_QUOTE } from '../network/definitions/swap';
import { sendRequest } from '../network/request';
import type {
APIError,
GetSwapQuoteParams,
GetSwapQuoteResponse,
SwapAPIParams,
Expand All @@ -21,14 +20,13 @@ export async function getSwapQuote(
amountReference: 'from',
isAmountInDecimals: false,
};
const apiParamsOrError = getAPIParamsForToken({
let apiParams = getAPIParamsForToken({
...defaultParams,
...params,
});
if ((apiParamsOrError as APIError).error) {
return apiParamsOrError as APIError;
if ('error' in apiParams) {
return apiParams;
}
let apiParams = apiParamsOrError as SwapAPIParams;

if (!params.useAggregator) {
apiParams = {
Expand Down

0 comments on commit bbaceed

Please sign in to comment.