Skip to content

Commit

Permalink
Merge branch 'james/acx-1651-op-update-bridge-fees-preview-if-optimis…
Browse files Browse the repository at this point in the history
…m-is-destination' into james/acx-1624-update-rewards-page
  • Loading branch information
james-a-morris committed Nov 9, 2023
2 parents 0bd88bf + fcea605 commit 2061f8c
Show file tree
Hide file tree
Showing 32 changed files with 1,960 additions and 564 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ REACT_APP_CHAIN_137_PROVIDER_URL=
# E.g. https://arbitrum-mainnet.g.alchemy.com/v2/YOUR-API-KEY
REACT_APP_CHAIN_42161_PROVIDER_URL=

# Create a project on https://walletconnect.com/ and add the project ID to this variable.
REACT_APP_WALLET_CONNECT_PROJECT_ID=

#########################
### OPTIONAL ENV VARS ###
#########################
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ yarn-error.log*

# storybook
build-storybook.log
storybook-static

# Amplitude
ampli.json
28 changes: 28 additions & 0 deletions api/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1246,3 +1246,31 @@ export function getDefaultRelayerAddress(
return sdk.constants.DEFAULT_SIMULATED_RELAYER_ADDRESS;
}
}

/**
* Performs the needed function calls to return a Vercel Response
* @param response The response client provided by Vercel
* @param body A payload in JSON format to send to the client
* @param statusCode The status code - defaults to 200
* @param cacheSeconds The cache time in non-negative whole seconds
* @param staleWhileRevalidateSeconds The stale while revalidate time in non-negative whole seconds
* @returns The response object
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
* @see https://datatracker.ietf.org/doc/html/rfc7234
* @note Be careful to not set anything negative please. The comment in the fn explains why
*/
export function sendResponse(
response: VercelResponse,
body: Record<string, unknown>,
statusCode: number,
cacheSeconds: number,
staleWhileRevalidateSeconds: number
) {
// Invalid (non-positive/non-integer) values will be considered undefined per RFC-7234.
// Most browsers will consider these invalid and will request fresh data.
response.setHeader(
"Cache-Control",
`s-maxage=${cacheSeconds}, stale-while-revalidate=${staleWhileRevalidateSeconds}`
);
return response.status(statusCode).json(body);
}
11 changes: 4 additions & 7 deletions api/limits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
HUB_POOL_CHAIN_ID,
ENABLED_ROUTES,
getDefaultRelayerAddress,
sendResponse,
} from "./_utils";

const LimitsQueryParamsSchema = object({
Expand Down Expand Up @@ -225,18 +226,14 @@ const handler = async (
liquidReserves
).toString(),
};

// Instruct Vercel to cache limit data for this token for 5 minutes. Caching can be used to limit number of
// Vercel invocations and run time for this serverless function and trades off potential inaccuracy in times of
// high volume. "max-age=0" instructs browsers not to cache, while s-maxage instructs Vercel edge caching
// to cache the responses and invalidate when deployments update.
logger.debug({
at: "Limits",
message: "Response data",
responseJson,
});
response.setHeader("Cache-Control", "s-maxage=300");
response.status(200).json(responseJson);
// Respond with a 200 status code and 4 minutes of cache cache with
// a minute of stale-while-revalidate.
sendResponse(response, responseJson, 200, 240, 60);
} catch (error: unknown) {
return handleErrorCondition("limits", response, logger, error);
}
Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@fortawesome/free-solid-svg-icons": "^6.1.1",
"@fortawesome/react-fontawesome": "^0.2.0",
"@google-cloud/logging": "^10.1.1",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@reach/dialog": "^0.16.2",
"@safe-global/safe-apps-provider": "^0.18.0",
"@safe-global/safe-apps-sdk": "^8.1.0",
Expand Down Expand Up @@ -94,16 +95,15 @@
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
"@ethersproject/experimental": "^5.6.3",
"@storybook/addon-actions": "^7.5.1",
"@storybook/addon-essentials": "^7.5.1",
"@storybook/addon-interactions": "^7.5.1",
"@storybook/addon-links": "^7.5.1",
"@storybook/addon-actions": "^7.5.3",
"@storybook/addon-essentials": "^7.5.3",
"@storybook/addon-interactions": "^7.5.3",
"@storybook/addon-links": "^7.5.3",
"@storybook/addon-onboarding": "^1.0.8",
"@storybook/blocks": "^7.5.1",
"@storybook/builder-vite": "^7.5.1",
"@storybook/node-logger": "^7.5.1",
"@storybook/react": "^7.5.1",
"@storybook/react-vite": "^7.5.1",
"@storybook/blocks": "^7.5.3",
"@storybook/node-logger": "^7.5.3",
"@storybook/react": "^7.5.3",
"@storybook/react-vite": "^7.5.3",
"@storybook/testing-library": "^0.2.2",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "12.1.5",
Expand Down Expand Up @@ -144,7 +144,7 @@
"postinstall-postinstall": "^2.1.0",
"prettier": "^2.4.1",
"serve": "^14.0.1",
"storybook": "^7.5.1",
"storybook": "^7.5.3",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"tsconfig-paths-webpack-plugin": "^4.0.0",
Expand Down
141 changes: 141 additions & 0 deletions src/components/DepositsTable/DataRow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import styled from "@emotion/styled";
import { BigNumber, utils } from "ethers";
import { DateTime } from "luxon";

import { Deposit } from "hooks/useDeposits";
import {
COLORS,
getConfig,
fallbackSuggestedRelayerFeePct,
suggestedFeesDeviationBufferMultiplier,
fixedPointAdjustment,
} from "utils";

import { HeaderCells, ColumnKey } from "./HeadRow";
import { AssetCell } from "./cells/AssetCell";
import { AmountCell } from "./cells/AmountCell";
import { RouteCell } from "./cells/RouteCell";
import { AddressCell } from "./cells/AddressCell";
import { DateCell } from "./cells/DateCell";
import { StatusCell } from "./cells/StatusCell";
import { TxCell } from "./cells/TxCell";
import { FeeCell } from "./cells/FeeCell";
import { RateCell } from "./cells/RateCell";
import { RewardsCell } from "./cells/RewardsCell";
import { ActionsCell } from "./cells/ActionsCell";

type Props = {
deposit: Deposit;
headerCells: HeaderCells;
disabledColumns?: ColumnKey[];
onClickSpeedUp?: () => void;
};

const config = getConfig();

const MAX_PENDING_STATE_TIME_UNTIL_SLOW = 15 * 60; // 15 mins

function isColumnDisabled(disabledColumns: ColumnKey[], column: ColumnKey) {
return disabledColumns.includes(column);
}

export function DataRow({
deposit,
headerCells,
disabledColumns = [],
onClickSpeedUp,
}: Props) {
const token = config.getTokenInfoByAddressSafe(
deposit.sourceChainId,
deposit.assetAddr
);

const isProfitable = BigNumber.from(
deposit.suggestedRelayerFeePct || fallbackSuggestedRelayerFeePct
).lte(
BigNumber.from(deposit.depositRelayerFeePct)
.mul(utils.parseEther(String(suggestedFeesDeviationBufferMultiplier)))
.div(fixedPointAdjustment)
);
const isSlowRelay =
deposit.status === "pending" &&
DateTime.fromSeconds(deposit.depositTime).diffNow("seconds").as("seconds") <
MAX_PENDING_STATE_TIME_UNTIL_SLOW;

// Hide unsupported or unknown token deposits
if (!token) {
return null;
}

return (
<StyledRow>
{isColumnDisabled(disabledColumns, "asset") ? null : (
<AssetCell token={token} width={headerCells.asset.width} />
)}
{isColumnDisabled(disabledColumns, "amount") ? null : (
<AmountCell
deposit={deposit}
token={token}
width={headerCells.amount.width}
/>
)}
{isColumnDisabled(disabledColumns, "route") ? null : (
<RouteCell
deposit={deposit}
token={token}
width={headerCells.route.width}
/>
)}
{isColumnDisabled(disabledColumns, "address") ? null : (
<AddressCell deposit={deposit} width={headerCells.address.width} />
)}
{isColumnDisabled(disabledColumns, "date") ? null : (
<DateCell deposit={deposit} width={headerCells.date.width} />
)}
{isColumnDisabled(disabledColumns, "status") ? null : (
<StatusCell
deposit={deposit}
width={headerCells.status.width}
isProfitable={isProfitable}
/>
)}
{isColumnDisabled(disabledColumns, "transactions") ? null : (
<TxCell deposit={deposit} width={headerCells.transactions.width} />
)}
{isColumnDisabled(disabledColumns, "netFee") ? null : (
<FeeCell deposit={deposit} width={headerCells.netFee.width} />
)}
{isColumnDisabled(disabledColumns, "loyaltyRate") ? null : (
<RateCell deposit={deposit} width={headerCells.loyaltyRate.width} />
)}
{isColumnDisabled(disabledColumns, "rewards") ? null : (
<RewardsCell deposit={deposit} width={headerCells.rewards.width} />
)}
{isColumnDisabled(disabledColumns, "actions") ? null : (
<ActionsCell
deposit={deposit}
isProfitable={isProfitable}
isSlowRelay={isSlowRelay}
onClickSpeedUp={onClickSpeedUp}
/>
)}
</StyledRow>
);
}

const StyledRow = styled.tr`
display: flex;
flex-direction: row;
align-items: center;
gap: 16px;
padding: 0px 24px;
border-width: 0px 1px 1px 1px;
border-style: solid;
border-color: ${COLORS["grey-600"]};
:hover {
#speed-up-icon {
display: block;
}
}
`;
48 changes: 48 additions & 0 deletions src/components/DepositsTable/DepositsTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import styled from "@emotion/styled";

import { HeadRow, headerCells, ColumnKey } from "./HeadRow";
import { DataRow } from "./DataRow";
import { Deposit } from "hooks/useDeposits";

type Props = {
disabledColumns?: ColumnKey[];
onClickSpeedUp?: () => void;
deposits: Deposit[];
};

export function DepositsTable({
disabledColumns = [],
deposits,
onClickSpeedUp,
}: Props) {
return (
<Wrapper>
<StyledTable>
<HeadRow disabledColumns={disabledColumns} />
<tbody>
{deposits.map((deposit) => (
<DataRow
disabledColumns={disabledColumns}
headerCells={headerCells}
key={deposit.depositId}
deposit={deposit}
onClickSpeedUp={onClickSpeedUp}
/>
))}
</tbody>
</StyledTable>
</Wrapper>
);
}

const Wrapper = styled.div`
display: flex;
flex-direction: column;
overflow-x: auto;
`;

const StyledTable = styled.table`
width: 1666px;
white-space: nowrap;
table-layout: fixed;
`;
Loading

0 comments on commit 2061f8c

Please sign in to comment.