Fund
component provides a comprehensive solution for implementing cryptocurrency purchasing flows using fiat currency. It is designed to be highly customizable and composable, allowing developers to create tailored onramp experiences while maintaining a consistent and secure purchasing process.
The core features include:
Fund
component is composed of several subcomponents that work together to create the complete purchasing experience. This approach allows developers to customize the UI structure while maintaining the underlying functionality.
The main components are:
Fund
: The root wrapper component that provides the FundContext
and handles state managementFundTitle
: Renders the title for the fund interface (defaults to “Deposit [cryptoCurrency]”)FundForm
: Manages the multi-view form interface for amount input + payment selection, error screens, and transaction statusFundFooter
: The “Secured by Coinbase” footer componentFund
component accepts a children
prop that can be either React nodes or a render function. When using a render function, it receives the current FundState
as an argument, providing access to all state values without needing to use the useFundContext
hook directly.
Example of children
as a render function:
FundProvider
and accessed via the useFundContext
hook. This context contains:
country
, subdivision
: User’s location for regulatory compliancecryptoCurrency
, fiatCurrency
: Selected currencies for the transactionnetwork
: The blockchain network for the purchasecryptoAmount
, fiatAmount
: The amounts being purchased/spentselectedInputType
: Whether the user is entering crypto or fiat amountsselectedPaymentMethod
: The chosen payment methodexchangeRate
: Current exchange rate between currenciestransactionStatus
: Current status of the transaction (init, error, transactionSuccess, etc.)error
: Any error that occurred during the processpaymentMethods
: Available payment methods based on user locationFundForm
component is the core of the purchasing interface, managing the display of different views based on the state. It handles three main views:
form
: The main input interface for amount selection and payment methoderror
: Error display when something goes wrongtransaction-status
: Shows the status of an ongoing or completed transactionFundForm
provides a children
render prop that receives an object containing the current view
and the Content
component. This allows for wrapping the form content or injecting additional components based on the current state and view.
FundTitle
component displays a contextual title for the fund interface. By default, it shows “Deposit [cryptoCurrency]” but can be customized by providing children. It accepts an as
prop to render as different HTML elements (default is h2
).
init
: Initial state, ready for user inputexit
: User has exited the flowerror
: An error occurred during the processtransactionSuccess
: Transaction completed successfullytransactionPending
: Transaction is being processedonStatus
, onError
, and onSuccess
callbacks provided to the Fund component.
country
: ISO 3166-1 alpha-2 country codecryptoCurrency
: The cryptocurrency to purchase (e.g., “ETH”, “BTC”)fiatCurrency
: The fiat currency to use for payment (e.g., “USD”, “EUR”)network
: The blockchain network for the purchasefetchBuyQuote
: Async function to fetch exchange rate quotesfetchBuyOptions
: Async function to fetch available payment methodssubdivision
: ISO 3166-2 subdivision code (e.g., “NY” for New York)presetAmountInputs
: Array of preset fiat amounts for quick selectioninputType
: Initial input type (“fiat” or “crypto”)openIn
: Where to open the payment window (“tab” or “popup”)submitLabel
: Custom label for the submit buttontitle
: Custom title for the fund interfacelocale
: Locale for formatting (defaults to browser locale)cryptoDecimalPlaces
: Number of decimal places for crypto amountsfiatDecimalPlaces
: Number of decimal places for fiat amountsonStatus
: Callback for transaction status changesonSuccess
: Callback for successful transactionsonError
: Callback for transaction errorschildren
: React nodes or render function receiving FundState