Skip to content

Commit

Permalink
add configureSDK function with options (#90)
Browse files Browse the repository at this point in the history
* add configureSDK function with options

* also swaps

* Update sdk/src/slippage.ts

remove unnecessary comment

Co-authored-by: Bruno Barbieri <[email protected]>

---------

Co-authored-by: Bruno Barbieri <[email protected]>
  • Loading branch information
BrodyHughes and brunobar79 authored Oct 9, 2024
1 parent 6942d67 commit 0c8fd8a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
23 changes: 18 additions & 5 deletions sdk/src/quotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ import { signPermit } from './utils/permit';
import { getReferrerCode } from './utils/referrer';
import { sanityCheckAddress } from './utils/sanity_check';


/**
* Configure SDK for mocking or fallback to API_BASE_URL
*
*/
export let sdkConfig = {
apiBaseUrl: API_BASE_URL
};

export function configureSDK(options: { apiBaseUrl?: string }) {
sdkConfig = { ...sdkConfig, ...options };
}

/**
* Function to get the rainbow router contract address based on the chainId
*
Expand Down Expand Up @@ -97,7 +110,7 @@ const buildRainbowQuoteUrl = ({
? { feePercentageBasisPoints: String(feePercentageBasisPoints) }
: {}),
});
return `${API_BASE_URL}/v1/quote?` + searchParams.toString();
return `${sdkConfig.apiBaseUrl}/v1/quote?` + searchParams.toString();
};

/**
Expand Down Expand Up @@ -151,7 +164,7 @@ export const buildRainbowCrosschainQuoteUrl = ({
? { feePercentageBasisPoints: String(feePercentageBasisPoints) }
: {}),
});
return `${API_BASE_URL}/v1/quote?bridgeVersion=4&` + searchParams.toString();
return `${sdkConfig.apiBaseUrl}/v1/quote?bridgeVersion=4&` + searchParams.toString();
};

/**
Expand Down Expand Up @@ -192,7 +205,7 @@ export const buildRainbowClaimBridgeQuoteUrl = ({
source: Source.CrosschainAggregatorRelay.toString(),
toChainId: String(toChainId),
});
return `${API_BASE_URL}/v1/quote?bridgeVersion=4&` + searchParams.toString();
return `${sdkConfig.apiBaseUrl}/v1/quote?bridgeVersion=4&` + searchParams.toString();
};

/**
Expand All @@ -207,7 +220,7 @@ export const getMinRefuelAmount = async (params: {
toChainId: ChainId;
}) => {
const { chainId, toChainId } = params;
const url = `${API_BASE_URL}/v1/chains`;
const url = `${sdkConfig.apiBaseUrl}/v1/chains`;
const response = await fetch(url);
const chainsData = (await response.json()) as SocketChainsData;

Expand Down Expand Up @@ -680,4 +693,4 @@ export const getCrosschainQuoteExecutionDetails = (
value,
},
};
};
};
4 changes: 2 additions & 2 deletions sdk/src/slippage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
SlippageError,
SlippageParams,
} from './types';
import { API_BASE_URL } from './utils/constants';
import { sdkConfig } from './quotes';

/**
* Function to get a slippage formatted quote url to use with backend
Expand Down Expand Up @@ -43,7 +43,7 @@ const buildRainbowSlippageUrl = ({
? { sellAmount: String(sellAmount) }
: { buyAmount: String(buyAmount) }),
});
return `${API_BASE_URL}/v1/slippage?` + searchParams.toString();
return `${sdkConfig.apiBaseUrl}/v1/slippage?` + searchParams.toString();
};

/**
Expand Down

0 comments on commit 0c8fd8a

Please sign in to comment.