Introduction
If you want to embed any onramp provider in the widget, we’ve got your back! In this example we’ll integrate the Coinbase onramp but the principle is exactly the same for any other.Pre-requisites
We assume you already have Dynamic integrated into a React based app, and are using the Dynamic Widget. The plan is to override the existing Buy button in the user profile page of the widget, so make sure you have onramps enabled in your Dynamic dashboard for that to show up.Full Demo
You can find the full example app of this implementation code here, and the deployment at https://custom-onramp-example.vercel.app/.Implementation
Install dependancies
The only other library we will need is the Coinbase Pay javascript SDK:Scaffold our override file
Create a new file in your codebase calledcustomOnramp.js
. In it let’s add the imports and declarations needed to get started:
setupCoinbaseButtonOverride
function.
Setup the pay instance
Inside the setupCoinbaseButtonOverride, let’s set up a few things, including the CB pay instance:Find the current Buy button
Add a new function (still inside setupCoinbaseButtonOverride) calledfindButtonInShadowDOM
which is responsible for detecting the button in the shadow dom:
Override the current button
Add another new function (still inside setupCoinbaseButtonOverride) calledsetupOverride
which is responsible replacing the existing button functionality with our own: