Skip to content

Commit

Permalink
feat(bridge): add thirdparty bridge handler
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisloh95 authored and shellteo committed Apr 3, 2024
1 parent 2140c41 commit 1a9d408
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
10 changes: 10 additions & 0 deletions apps/bridge/public/thirdparty/external-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions apps/bridge/src/components/bridge/CTA.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { useIsChainID } from "@hooks/web3/read/useIsChainID";
import { useCallApprove } from "@hooks/web3/bridge/write/useCallApprove";
import { useSwitchToNetwork } from "@hooks/web3/write/useSwitchToNetwork";
import { useIsWalletMultisig } from "@hooks/useIsWalletMultisig";
import Link from "next/link";
import Image from "next/image";

// Contains a button & a modal to control allowance and deposits/withdrawals
export default function CTA({
Expand All @@ -37,8 +39,10 @@ export default function CTA({
allowance,
selectedTokenAmount = "",
destinationTokenAmount = "",
selectedToken,
setCTAPage,
setWalletModalOpen,
tokens,
} = useContext(StateContext);

// check that we're connected to the appropriate chain
Expand All @@ -64,6 +68,16 @@ export default function CTA({
// create an allowance approval request on the selected token
const { approve, approvalStatus } = useCallApprove(selected || {});

const type = chainId === L1_CHAIN_ID ? Direction.Deposit : Direction.Withdraw;

// get the selection Token
const selection =
tokens.find((v) => {
return selectedToken[type] === v.name && v.chainId === chainId;
}) ||
tokens[chainId === L1_CHAIN_ID ? 0 : 1] ||
{};

// ensure we don't overflow
const fixDecimals = useCallback(
(value: string) => {
Expand Down Expand Up @@ -169,6 +183,35 @@ export default function CTA({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [client?.address]);

if (selection.extensions?.thirdparty) {
return (
<div className="mt-4">
<Link
href={selection.extensions.thirdparty.url}
rel="noreferrer noopener"
target="_blank"
>
<Button
type="button"
size="full"
className="h-14 flex items-center justify-center gap-1"
>
{direction === Direction.Deposit
? `Deposit with ${selection.extensions.thirdparty.name}`
: `Withdraw with ${selection.extensions.thirdparty.name}`}
<Image
className="translate -translate-y-[2px]"
src="/thirdparty/external-dark.svg"
alt="external"
width={16}
height={16}
/>
</Button>
</Link>
</div>
);
}

return (
<div className="mt-4">
{!client?.address ? (
Expand Down
6 changes: 5 additions & 1 deletion apps/bridge/src/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,11 @@ export interface Token {
decimals: number;
logoURI: string;
extensions: {
optimismBridgeAddress: Address;
optimismBridgeAddress?: Address;
thirdparty?: {
name: string;
url: string;
};
};
balance?: BigNumberish;
allowance?: BigNumberish;
Expand Down

0 comments on commit 1a9d408

Please sign in to comment.