Created
June 8, 2022 19:46
-
-
Save cfluke-cb/715ae7cef93f57fe523b17d080046645 to your computer and use it in GitHub Desktop.
Mui Button Coinbase Pay Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useRef, useState, useEffect } from 'react'; | |
import { initOnRamp } from '@coinbase/cbpay-js'; | |
import { Button } from '@mui/material'; | |
export const PayWithCoinbaseButton = () => { | |
const onrampInstance = useRef(); | |
const [isReady, setIsReady] = useState(false); | |
useEffect(() => { | |
console.log('initializing'); | |
onrampInstance.current = initOnRamp({ | |
appId: '', | |
widgetParameters: { | |
destinationWallets: [ | |
{ | |
address: '', | |
blockchains: ['solana'], | |
//assets: ['ETH', 'USDC'], | |
}, | |
], | |
}, | |
onReady: () => { | |
setIsReady(true); | |
}, | |
onSuccess: () => { | |
console.log('success'); | |
}, | |
onExit: (event: any) => { | |
console.log('exit', event); | |
}, | |
onEvent: (event: any) => { | |
console.log('event', event); | |
}, | |
experienceLoggedIn: 'embedded', //'embedded', 'popup', or 'newtab', | |
experienceLoggedOut: 'embedded', | |
closeOnExit: true, | |
closeOnSuccess: true, | |
}); | |
console.log('initialized', onrampInstance); | |
return () => { | |
onrampInstance.current?.destroy(); | |
}; | |
}, []); | |
const handleClick = () => { | |
console.log(onrampInstance); | |
onrampInstance.current?.open(); | |
}; | |
return ( | |
<Button variant="contained" onClick={handleClick} disabled={!isReady}> | |
Add crypto with Pay | |
</Button> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment