Skip to content

Commit

Permalink
improve: pipe recipient address into suggested fees
Browse files Browse the repository at this point in the history
  • Loading branch information
james-a-morris committed Oct 27, 2023
1 parent ffa5191 commit 04e68e0
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 8 deletions.
11 changes: 9 additions & 2 deletions src/hooks/useBridgeFees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ export function useBridgeFees(
amount: ethers.BigNumber,
fromChainId?: ChainId,
toChainId?: ChainId,
tokenSymbol?: string
tokenSymbol?: string,
recipientAddress?: string
) {
const { block } = useBlock(toChainId);
const enabledQuery =
!!toChainId && !!fromChainId && !!block && !!tokenSymbol && amount.gt(0);
!!toChainId &&
!!fromChainId &&
!!block &&
!!tokenSymbol &&
amount.gt(0) &&
!!recipientAddress;
const queryKey = enabledQuery
? bridgeFeesQueryKey(
tokenSymbol,
Expand All @@ -38,6 +44,7 @@ export function useBridgeFees(
blockTimestamp: block!.timestamp,
toChainId: toChainId!,
fromChainId: fromChainId!,
recipientAddress: recipientAddress!,
});
},
{
Expand Down
5 changes: 4 additions & 1 deletion src/utils/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type GetBridgeFeesArgs = {
blockTimestamp: number;
fromChainId: ChainId;
toChainId: ChainId;
recipientAddress: string;
};

export type GetBridgeFeesResult = BridgeFees & {
Expand All @@ -52,6 +53,7 @@ export async function getBridgeFees({
tokenSymbol,
fromChainId,
toChainId,
recipientAddress,
}: GetBridgeFeesArgs): Promise<GetBridgeFeesResult> {
const timeBeforeRequests = Date.now();
const {
Expand All @@ -66,7 +68,8 @@ export async function getBridgeFees({
amount,
getConfig().getTokenInfoBySymbol(fromChainId, tokenSymbol).address,
toChainId,
fromChainId
fromChainId,
recipientAddress
);
const timeAfterRequests = Date.now();

Expand Down
3 changes: 2 additions & 1 deletion src/utils/serverless-api/mocked/suggested-fees.mocked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export async function suggestedFeesMockedApiCall(
_amount: ethers.BigNumber,
_originToken: string,
_toChainid: ChainId,
_fromChainid: ChainId
_fromChainid: ChainId,
_recipientAddress: string
): Promise<SuggestedApiFeeReturnType> {
return {
relayerFee: {
Expand Down
4 changes: 3 additions & 1 deletion src/utils/serverless-api/prod/suggested-fees.prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ export async function suggestedFeesApiCall(
amount: ethers.BigNumber,
originToken: string,
toChainid: ChainId,
fromChainid: ChainId
fromChainid: ChainId,
recipientAddress: string
): Promise<SuggestedApiFeeReturnType> {
const response = await axios.get(`/api/suggested-fees`, {
params: {
token: originToken,
destinationChainId: toChainid,
originChainId: fromChainid,
recipientAddress,
amount: amount.toString(),
skipAmountLimit: true,
},
Expand Down
3 changes: 2 additions & 1 deletion src/utils/serverless-api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export type SuggestedApiFeeType = (
amount: ethers.BigNumber,
originToken: string,
toChainid: ChainId,
fromChainid: ChainId
fromChainid: ChainId,
recipientAddress: string
) => Promise<SuggestedApiFeeReturnType>;

export type RetrieveLinkedWalletType = (
Expand Down
3 changes: 2 additions & 1 deletion src/views/Bridge/hooks/useTransferQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export function useTransferQuote(
amountToBridge,
selectedRoute.fromChain,
selectedRoute.toChain,
selectedRoute.fromTokenSymbol
selectedRoute.fromTokenSymbol,
toAddress
);
const limitsQuery = useBridgeLimits(
selectedRoute.fromTokenSymbol,
Expand Down
3 changes: 2 additions & 1 deletion src/views/Transactions/hooks/useSpeedUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export function useSpeedUp(transfer: Deposit, token: Token) {
BigNumber.from(transfer.amount),
transfer.sourceChainId,
transfer.destinationChainId,
token.symbol
token.symbol,
transfer.depositorAddr
);

const [speedUpTxLink, setSpeedUpTxLink] = useState<string>("");
Expand Down

0 comments on commit 04e68e0

Please sign in to comment.