Skip to content

Commit a5005e0

Browse files
authored
Coinbase pay (ribbon-finance#645)
* coinbase pay * wait for initOnRamp to run * rm onrampinstance dependency * add isinitializing boolean * fix * fix * fix * change to generateOnRampURL
1 parent 05ab140 commit a5005e0

File tree

6 files changed

+124
-3
lines changed

6 files changed

+124
-3
lines changed

shared/src/assets/icons/icons.tsx

+15
Original file line numberDiff line numberDiff line change
@@ -1796,3 +1796,18 @@ export const BoostIcon: React.FC<SVGPropsWithColor> = ({
17961796
/>
17971797
</svg>
17981798
);
1799+
1800+
export const BuyIcon: React.FC<SVGPropsWithColor> = () => (
1801+
<svg
1802+
width="24"
1803+
height="24"
1804+
viewBox="0 0 1024 1024"
1805+
fill="none"
1806+
xmlns="http://www.w3.org/2000/svg"
1807+
>
1808+
<path
1809+
d="M512.147 692C412.697 692 332.146 611.45 332.146 512C332.146 412.55 412.697 332 512.147 332C601.247 332 675.197 396.95 689.447 482H870.797C855.497 297.2 700.846 152 512.147 152C313.396 152 152.146 313.25 152.146 512C152.146 710.75 313.396 872 512.147 872C700.846 872 855.497 726.8 870.797 542H689.297C675.047 627.05 601.247 692 512.147 692Z"
1810+
fill="white"
1811+
/>
1812+
</svg>
1813+
);

webapp/.env.sample

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ REACT_APP_TESTNET_URI=your_testnet_uri
77
REACT_APP_AVAX_URI=https://api.avax.network/ext/bc/C/rpc
88
REACT_APP_FUJI_URI=https://api.avax-test.network/ext/bc/C/rpc
99
REACT_APP_SUBGRAPHQL_URL=https://api.thegraph.com/subgraphs/name/kenchangh/ribbon-finance
10-
REACT_APP_SUBGRAPHQL_REARN_URL=https://api.studio.thegraph.com/query/36282/ribbonearn/v0.0.2
10+
REACT_APP_SUBGRAPHQL_REARN_URL=https://api.studio.thegraph.com/query/36282/ribbonearn/v0.0.8
1111
REACT_APP_KOVAN_SUBGRAPHQL_URL=https://api.thegraph.com/subgraphs/name/kenchangh/ribbon-finance-kovan
1212
REACT_APP_AVAX_SUBGRAPHQL_URL=https://api.thegraph.com/subgraph/name/kenchangh/ribbon-avax
13-
REACT_APP_ETHERSCAN_API_KEY=
14-
REACT_APP_SNOWTRACE_API_KEY=
13+
REACT_APP_COINBASE_APPID=
1514
REACT_APP_SOLANA_TESTNET_URI=https://api.devnet.solana.com
1615
REACT_APP_SOLANA_MAINNET_URI=https://solana-api.projectserum.com

webapp/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"url": "https://github.com/ribbon-finance/ribbon-frontend.git"
1616
},
1717
"dependencies": {
18+
"@coinbase/cbpay-js": "^1.6.0",
1819
"@craco/craco": "^6.1.1",
1920
"@davatar/react": "^1.8.1",
2021
"@project-serum/anchor": "0.24.2",

webapp/src/components/Header/Header.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { useGlobalState } from "shared/lib/store/store";
2121
import FilterDropdown from "shared/lib/components/Common/FilterDropdown";
2222
import { useHistory } from "react-router-dom";
2323
import { useLendLink } from "shared/lib/hooks/useLendLink";
24+
import { BuyButton } from "../Wallet/BuyButton";
2425

2526
const HeaderContainer = styled.div<MobileMenuOpenProps>`
2627
height: ${theme.header.height}px;
@@ -284,6 +285,11 @@ const Header = () => {
284285
</HeaderButtonContainer>
285286
)}
286287

288+
{active && (
289+
<HeaderButtonContainer>
290+
<BuyButton />
291+
</HeaderButtonContainer>
292+
)}
287293
<AccountStatus variant="desktop" />
288294

289295
{/* MOBILE MENU */}
+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import React, { useEffect, useState } from "react";
2+
import styled from "styled-components";
3+
import { generateOnRampURL } from "@coinbase/cbpay-js";
4+
import theme from "shared/lib/designSystem/theme";
5+
import colors from "shared/lib/designSystem/colors";
6+
import { useWeb3Wallet } from "shared/lib/hooks/useWeb3Wallet";
7+
import { Chains, ID_TO_CHAINS } from "shared/lib/constants/constants";
8+
import { BuyIcon } from "shared/lib/assets/icons/icons";
9+
10+
const ButtonContainer = styled.div`
11+
display: flex;
12+
align-items: center;
13+
justify-content: center;
14+
border-radius: ${theme.border.radius};
15+
background: ${colors.background.two};
16+
height: 48px;
17+
width: 48px;
18+
19+
&:hover {
20+
svg {
21+
path {
22+
opacity: ${theme.hover.opacity};
23+
}
24+
}
25+
}
26+
`;
27+
28+
const IconContainer = styled.div`
29+
height: 24px;
30+
width: 24px;
31+
display: flex;
32+
align-items: center;
33+
justify-content: center;
34+
`;
35+
36+
type DestinationWallet = {
37+
address: string;
38+
blockchains: string[];
39+
};
40+
41+
export const BuyButton: React.FC = () => {
42+
const [onrampURL, setOnrampURL] = useState<string>();
43+
const { account, chainId } = useWeb3Wallet();
44+
45+
useEffect(() => {
46+
const destinationWallets: DestinationWallet[] = [];
47+
const addWallet = (
48+
blockchain: "ethereum" | "avalanche-c-chain" | "solana"
49+
) => {
50+
if (!account) {
51+
return;
52+
}
53+
destinationWallets.push({
54+
address: account,
55+
blockchains: [blockchain],
56+
});
57+
};
58+
if (account && account.length > 0 && chainId) {
59+
switch (ID_TO_CHAINS[chainId]) {
60+
case Chains.Ethereum:
61+
addWallet("ethereum");
62+
break;
63+
case Chains.Avalanche:
64+
addWallet("avalanche-c-chain");
65+
break;
66+
case Chains.Solana:
67+
addWallet("solana");
68+
}
69+
}
70+
if (destinationWallets.length < 1) {
71+
return;
72+
}
73+
74+
const appId = process.env.REACT_APP_COINBASE_APPID;
75+
if (!appId) return;
76+
77+
setOnrampURL(
78+
generateOnRampURL({
79+
appId,
80+
destinationWallets,
81+
})
82+
);
83+
}, [account, chainId]);
84+
85+
if (!account || !onrampURL) return <></>;
86+
return (
87+
<a href={onrampURL} target="_blank" rel="noreferrer noopener">
88+
<ButtonContainer>
89+
<IconContainer>
90+
<BuyIcon />
91+
</IconContainer>
92+
</ButtonContainer>
93+
</a>
94+
);
95+
};

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -1252,6 +1252,11 @@
12521252
exec-sh "^0.3.2"
12531253
minimist "^1.2.0"
12541254

1255+
"@coinbase/cbpay-js@^1.6.0":
1256+
version "1.6.0"
1257+
resolved "https://registry.yarnpkg.com/@coinbase/cbpay-js/-/cbpay-js-1.6.0.tgz#23f4456ba57f3e6ba1583e21376e9a2337fd1aaa"
1258+
integrity sha512-jt1BUaMLbA2/xfHc2YC/Uq+rYD0LIpU5s70ms8VpxImNGiMLUEgUZnAzjk1aIqWiTpQWRmwqyq+WvKTb0Yv05Q==
1259+
12551260
"@craco/craco@^6.1.1":
12561261
version "6.2.0"
12571262
resolved "https://registry.yarnpkg.com/@craco/craco/-/craco-6.2.0.tgz#93847ae20899f5e810359443f2055bcf2b1a584e"

0 commit comments

Comments
 (0)