Skip to content

Commit 1745a0f

Browse files
authored
chore(ONRAMP-843): FundCard accept sessionToken param (#366)
1 parent 67883c2 commit 1745a0f

3 files changed

Lines changed: 36 additions & 29 deletions

File tree

-53.4 KB
Binary file not shown.

docs/onchainkit/latest/components/fund/fund-button.mdx

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,27 @@ Coinbase account.
4343
</OnchainKitProvider>
4444
```
4545
</Step>
46+
47+
<Step title="Get sessionToken">
48+
[Getting session token](https://docs.cdp.coinbase.com/onramp-&-offramp/session-token-authentication)
49+
</Step>
50+
4651
<Step title="Drop in the<FundButton /> component">
4752
```tsx
4853
import { FundButton } from '@coinbase/onchainkit/fund';
4954

50-
<FundButton />
55+
56+
const sessionToken = "YOUR_SESSION_TOKEN";
57+
58+
<FundButton sessionToken={sessionToken} />
5159
```
5260

5361
<App>
5462
<FundWrapper>
5563
{({ address }) => {
5664
if (address) {
5765
return (
58-
<FundButton />
66+
<FundButton sessionToken={sessionToken} />
5967
)
6068
}
6169
return <>
@@ -72,20 +80,6 @@ Coinbase account.
7280
</Step>
7381
</Steps>
7482

75-
76-
<Tip>
77-
**Troubleshooting**
78-
79-
If you see a "something went wrong" error message when navigating to pay.coinbase.com, make sure you have "enforce
80-
secure initialization" disabled on the [Onramp config page in Coinbase Developer Platform Dashboard](https://portal.cdp.coinbase.com/products/onramp).
81-
82-
<Frame>
83-
<img alt="OnchainKit require secure init" src="/images/onchainkit/onramp-secure-init.png" />
84-
</Frame>
85-
86-
</Tip>
87-
88-
8983
## Customizing the funding experience
9084

9185
You can customize the Coinbase Onramp experience by bringing your own Onramp URL and passing it to the ```<FundButton />```
@@ -100,9 +94,7 @@ const projectId = 'YOUR_CDP_PROJECT_ID';
10094
const { address } = useAccount();
10195

10296
const onrampBuyUrl = getOnrampBuyUrl({
103-
projectId,
104-
addresses: { [address]: ['base'] },
105-
assets: ['USDC'],
97+
sessionToken: "YOUR_SESSION_TOKEN"
10698
presetFiatAmount: 20,
10799
fiatCurrency: 'USD'
108100
});
@@ -120,9 +112,7 @@ const onrampBuyUrl = getOnrampBuyUrl({
120112
{({ address, projectId }) => {
121113
if (address && projectId) {
122114
const onrampBuyUrl = getOnrampBuyUrl({
123-
projectId,
124-
addresses: { [address]: ['base'] },
125-
assets: ['USDC'],
115+
sessionToken: "YOUR_SESSION_TOKEN"
126116
presetFiatAmount: 20,
127117
fiatCurrency: 'USD'
128118
});
@@ -145,7 +135,7 @@ const onrampBuyUrl = getOnrampBuyUrl({
145135
You can choose to have the funding URL open in a popup or a new tab using the `openIn` prop.
146136

147137
```tsx
148-
<FundButton openIn={"tab"} />
138+
<FundButton openIn={"tab"} sessionToken={sessionToken} />
149139
```
150140

151141
<iframe
@@ -158,7 +148,7 @@ You can choose to have the funding URL open in a popup or a new tab using the `o
158148
{({ address }) => {
159149
if (address) {
160150
return (
161-
<FundButton openIn={"tab"} />
151+
<FundButton openIn={"tab"} sessionToken={sessionToken} />
162152
)
163153
}
164154
return <>
@@ -178,7 +168,7 @@ You can choose to have the funding URL open in a popup or a new tab using the `o
178168
You can override the text on the fund button using the `text` prop, and hide the icon with the `hideIcon` prop.
179169

180170
```tsx
181-
<FundButton text={"Onramp"} hideIcon={true} />
171+
<FundButton text={"Onramp"} hideIcon={true} sessionToken={sessionToken} />
182172
```
183173

184174
<iframe
@@ -191,7 +181,7 @@ You can override the text on the fund button using the `text` prop, and hide the
191181
{({ address }) => {
192182
if (address) {
193183
return (
194-
<FundButton text={"Onramp"} hideIcon={true} />
184+
<FundButton text={"Onramp"} hideIcon={true} sessionToken={sessionToken} />
195185
)
196186
}
197187
return <>
@@ -209,7 +199,7 @@ You can override the text on the fund button using the `text` prop, and hide the
209199
You can hide the text with the `hideText` prop.
210200

211201
```tsx
212-
<FundButton hideText={true} />
202+
<FundButton hideText={true} sessionToken={sessionToken} />
213203
```
214204

215205
<iframe
@@ -223,7 +213,7 @@ You can hide the text with the `hideText` prop.
223213
if (address) {
224214
return (
225215
<>
226-
<FundButton hideText={true} />
216+
<FundButton hideText={true} sessionToken={sessionToken} />
227217
</>
228218
)
229219
}
@@ -279,6 +269,8 @@ type FundButtonBaseProps = {
279269
onPopupClose?: () => void;
280270
/** A callback function that will be called when the button is clicked */
281271
onClick?: () => void;
272+
/** An optional prop to provide a session token. Required if no fundingUrl is provided */
273+
sessionToken?: string;
282274
};
283275
```
284276

docs/onchainkit/latest/components/fund/fund-card.mdx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ To use the `FundCard` component, you'll need to provide a Client API Key in `Onc
2929
This component requires a `projectId` to be set in the `OnchainKitProvider`. You can find your `projectId` on [Coinbase Developer Platform](https://portal.cdp.coinbase.com/products/onchainkit).
3030
</Note>
3131

32+
<Note>
33+
You'll need a session token for authentication. Learn how to obtain one in the [session token documentation](https://docs.cdp.coinbase.com/onramp-&-offramp/session-token-authentication).
34+
</Note>
35+
3236

3337
## Usage
3438

@@ -37,7 +41,10 @@ This component requires a `projectId` to be set in the `OnchainKitProvider`. You
3741
```tsx
3842
import { FundCard } from '@coinbase/onchainkit/fund';
3943

44+
const sessionToken = "YOUR_SESSION_TOKEN";
45+
4046
<FundCard
47+
sessionToken={sessionToken}
4148
assetSymbol="ETH"
4249
country="US"
4350
currency="USD"
@@ -53,7 +60,7 @@ import { FundCard } from '@coinbase/onchainkit/fund';
5360
<FundWrapper>
5461
{({ address }) => {
5562
if (address) {
56-
return <FundCard assetSymbol="ETH" country="US" currency="USD" />;
63+
return <FundCard sessionToken={sessionToken} assetSymbol="ETH" country="US" currency="USD" />;
5764
}
5865
return (
5966
<>
@@ -77,6 +84,7 @@ You can customize the header and button text:
7784

7885
```tsx
7986
<FundCard
87+
sessionToken={sessionToken}
8088
assetSymbol="ETH"
8189
country="US"
8290
currency="USD"
@@ -96,6 +104,7 @@ You can customize the header and button text:
96104
if (address) {
97105
return (
98106
<FundCard
107+
sessionToken={sessionToken}
99108
assetSymbol="ETH"
100109
country="US"
101110
currency="USD"
@@ -124,6 +133,7 @@ You can specify which fiat currency to use:
124133

125134
```tsx
126135
<FundCard
136+
sessionToken={sessionToken}
127137
assetSymbol="ETH"
128138
country="GB"
129139
currency="GBP"
@@ -138,6 +148,7 @@ You can specify preset amount buttons:
138148
const presetAmountInputs = ['10', '20', '50'] as const;
139149

140150
<FundCard
151+
sessionToken={sessionToken}
141152
assetSymbol="ETH"
142153
country="US"
143154
currency="USD"
@@ -156,6 +167,7 @@ You can provide custom children to completely customize the card content while k
156167

157168
```tsx
158169
<FundCard
170+
sessionToken={sessionToken}
159171
assetSymbol="ETH"
160172
country="US"
161173
currency="USD"
@@ -184,6 +196,7 @@ import {
184196
} from '@coinbase/onchainkit/fund';
185197

186198
<FundCard
199+
sessionToken={sessionToken}
187200
assetSymbol="ETH"
188201
country="US"
189202
currency="USD"
@@ -253,6 +266,8 @@ type FundCardProps = {
253266
currency?: string;
254267
className?: string;
255268
presetAmountInputs?: PresetAmountInputs;
269+
/** An optional prop to provide a session token. Required if no fundingUrl is provided */
270+
sessionToken?: string;
256271
} & LifecycleEvents;
257272
```
258273

0 commit comments

Comments
 (0)