-
Notifications
You must be signed in to change notification settings - Fork 621
Add Bridge.Onramp functions + port old functions #7076
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 50 commits
efc4687
6744d0a
77ad035
2c33488
02b1c4a
8112650
dfe29f0
421d959
cdaf130
91de2cc
727d0e9
abd77ec
1b00833
6eff0e0
ea05f7d
57ecf61
05516bd
267feda
c4a9fac
a7c1257
378993b
e701530
4bc4caf
b953056
72bc53b
c6af295
58ca5f7
b128358
6d8d185
197d85b
8aa198b
638dddc
2e6ad54
4eeca27
8bcecf5
f989121
a2a8723
c2bbb0d
cec95b0
e89ff31
7da5372
2b2b6cc
a1f5b91
1c64203
388eeb9
751746c
df465f1
696bff4
f3cb4a0
3d912bd
de79cf9
11dc870
3545b1a
d194566
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| --- | ||
| "thirdweb": patch | ||
| --- | ||
|
|
||
| Added Bridge.Onramp.prepare and Bridge.Onramp.status functions | ||
|
|
||
| ## Bridge.Onramp.prepare | ||
|
|
||
| Prepares an onramp transaction, returning a link from the specified provider to onramp to the specified token. | ||
|
|
||
| ```typescript | ||
| import { Bridge } from "thirdweb"; | ||
| import { ethereum } from "thirdweb/chains"; | ||
| import { NATIVE_TOKEN_ADDRESS, toWei } from "thirdweb/utils"; | ||
|
|
||
| const preparedOnramp = await Bridge.Onramp.prepare({ | ||
| client: thirdwebClient, | ||
| onramp: "stripe", | ||
| chainId: ethereum.id, | ||
| tokenAddress: NATIVE_TOKEN_ADDRESS, | ||
| receiver: "0x...", // receiver's address | ||
| amount: toWei("10"), // 10 of the destination token | ||
| // Optional params: | ||
| // sender: "0x...", // sender's address | ||
| // onrampTokenAddress: NATIVE_TOKEN_ADDRESS, // token to initially onramp to | ||
| // onrampChainId: 1, // chain to initially onramp to | ||
| // currency: "USD", | ||
| // maxSteps: 2, | ||
| // purchaseData: { customId: "123" } | ||
| }); | ||
|
|
||
| console.log(preparedOnramp.link); // URL to redirect the user to | ||
| console.log(preparedOnramp.destinationAmount); // Amount of token user will receive | ||
|
||
| ``` | ||
|
|
||
| ## Bridge.Onramp.status | ||
|
|
||
| Retrieves the status of an Onramp session created via Bridge.Onramp.prepare. | ||
|
|
||
| ```typescript | ||
| import { Bridge } from "thirdweb"; | ||
|
|
||
| const onrampStatus = await Bridge.Onramp.status({ | ||
| id: "022218cc-96af-4291-b90c-dadcb47571ec", | ||
| client: thirdwebClient, | ||
| }); | ||
|
|
||
| // Possible results: | ||
| // { | ||
| // status: "CREATED", | ||
| // transactions: [], | ||
| // purchaseData: { | ||
| // orderId: "abc-123", | ||
| // }, | ||
| // } | ||
| // | ||
| // or | ||
| // { | ||
| // status: "PENDING", | ||
| // transactions: [], | ||
| // purchaseData: { | ||
| // orderId: "abc-123", | ||
| // }, | ||
| // } | ||
| // | ||
| // or | ||
| // { | ||
| // status: "COMPLETED", | ||
| // transactions: [ | ||
| // { | ||
| // chainId: 1, | ||
| // transactionHash: "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef", | ||
| // }, | ||
| // ], | ||
| // purchaseData: { | ||
| // orderId: "abc-123", | ||
| // }, | ||
| // } | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,7 @@ Developers can turn on Test Mode to test both fiat-to-crypto transactions and cr | |
|
|
||
| ## Buy With Fiat | ||
|
|
||
| By setting `testMode` to `true` for Buy With Fiat, you can enable test experiences for our underlying providers (Stripe, Kado, and Transak). | ||
| By setting `testMode` to `true` for Buy With Fiat, you can enable test experiences for our underlying providers (Coinbase, Stripe, and Transak). | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't true at the moment
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, we'll have to fix that :D pretty important |
||
|
|
||
| <Tabs defaultValue="connectbutton"> | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| import { toWei } from "src/utils/units.js"; | ||
| import { describe, expect, it } from "vitest"; | ||
| import { TEST_CLIENT } from "~test/test-clients.js"; | ||
| import * as Onramp from "./Onramp.js"; | ||
|
|
||
| // Use the same receiver address as other bridge tests | ||
| const RECEIVER_ADDRESS = "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709"; | ||
| const NATIVE_TOKEN_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; | ||
|
|
||
| /** | ||
| * These tests call the real Bridge Onramp API. They are executed only when a | ||
| * `TW_SECRET_KEY` environment variable is present, mirroring the behaviour of | ||
| * the other bridge tests in this package. | ||
| */ | ||
| describe.runIf(process.env.TW_SECRET_KEY)("Bridge.Onramp.prepare", () => { | ||
| it("should prepare an onramp successfully", async () => { | ||
| const prepared = await Onramp.prepare({ | ||
| client: TEST_CLIENT, | ||
| onramp: "stripe", | ||
| chainId: 1, | ||
| tokenAddress: NATIVE_TOKEN_ADDRESS, | ||
| receiver: RECEIVER_ADDRESS, | ||
| amount: toWei("0.01"), | ||
| }); | ||
|
|
||
| expect(prepared).toBeDefined(); | ||
|
|
||
| // The destinationAmount should be a bigint and greater than zero | ||
| expect(typeof prepared.destinationAmount).toBe("bigint"); | ||
| expect(prepared.destinationAmount > 0n).toBe(true); | ||
|
|
||
| // A redirect link for the user should be provided | ||
| expect(prepared.link).toBeDefined(); | ||
| expect(typeof prepared.link).toBe("string"); | ||
|
|
||
| // Intent must be present and reference the correct receiver | ||
| expect(prepared.intent).toBeDefined(); | ||
| expect(prepared.intent.receiver.toLowerCase()).toBe( | ||
| RECEIVER_ADDRESS.toLowerCase(), | ||
| ); | ||
|
|
||
| // Steps array should be defined (it may be empty if the provider supports the destination token natively) | ||
| expect(Array.isArray(prepared.steps)).toBe(true); | ||
| }); | ||
|
|
||
| it("should surface any errors", async () => { | ||
| await expect( | ||
| Onramp.prepare({ | ||
| client: TEST_CLIENT, | ||
| onramp: "stripe", | ||
| chainId: 444, // Unsupported chain ID | ||
| tokenAddress: NATIVE_TOKEN_ADDRESS, | ||
| receiver: RECEIVER_ADDRESS, | ||
| amount: toWei("0.01"), | ||
| }), | ||
| ).rejects.toThrowError(); | ||
| }); | ||
|
|
||
| it("should prepare a Coinbase onramp successfully", async () => { | ||
| const prepared = await Onramp.prepare({ | ||
| client: TEST_CLIENT, | ||
| onramp: "coinbase", | ||
| chainId: 1, | ||
| tokenAddress: NATIVE_TOKEN_ADDRESS, | ||
| receiver: RECEIVER_ADDRESS, | ||
| amount: toWei("0.01"), | ||
| }); | ||
|
|
||
| expect(prepared).toBeDefined(); | ||
|
|
||
| // The destinationAmount should be a bigint and greater than zero | ||
| expect(typeof prepared.destinationAmount).toBe("bigint"); | ||
| expect(prepared.destinationAmount > 0n).toBe(true); | ||
|
|
||
| // A redirect link for the user should be provided | ||
| expect(prepared.link).toBeDefined(); | ||
| expect(typeof prepared.link).toBe("string"); | ||
|
|
||
| // Intent must be present and reference the correct receiver | ||
| expect(prepared.intent).toBeDefined(); | ||
| expect(prepared.intent.receiver.toLowerCase()).toBe( | ||
| RECEIVER_ADDRESS.toLowerCase(), | ||
| ); | ||
|
|
||
| // Steps array should be defined (it may be empty if the provider supports the destination token natively) | ||
| expect(Array.isArray(prepared.steps)).toBe(true); | ||
| }); | ||
|
|
||
| it("should prepare a Transak onramp successfully", async () => { | ||
| const prepared = await Onramp.prepare({ | ||
| client: TEST_CLIENT, | ||
| onramp: "transak", | ||
| chainId: 1, | ||
| tokenAddress: NATIVE_TOKEN_ADDRESS, | ||
| receiver: RECEIVER_ADDRESS, | ||
| amount: toWei("0.01"), | ||
| }); | ||
|
|
||
| expect(prepared).toBeDefined(); | ||
|
|
||
| // The destinationAmount should be a bigint and greater than zero | ||
| expect(typeof prepared.destinationAmount).toBe("bigint"); | ||
| expect(prepared.destinationAmount > 0n).toBe(true); | ||
|
|
||
| // A redirect link for the user should be provided | ||
| expect(prepared.link).toBeDefined(); | ||
| expect(typeof prepared.link).toBe("string"); | ||
|
|
||
| // Intent must be present and reference the correct receiver | ||
| expect(prepared.intent).toBeDefined(); | ||
| expect(prepared.intent.receiver.toLowerCase()).toBe( | ||
| RECEIVER_ADDRESS.toLowerCase(), | ||
| ); | ||
|
|
||
| // Steps array should be defined (it may be empty if the provider supports the destination token natively) | ||
| expect(Array.isArray(prepared.steps)).toBe(true); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should include an optional country param in case calling from the server
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw i dont think the ip country detection works, its letting me see stripe stuff which is not available in NZ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it does either and I don't know why