Skip to content

@openrampkit/solid ​

A thin Solid wrapper over <openramp-modal>. It has the same API shape as @openrampkit/react. Peer dependency: solid-js ^1.8.

It is safe for server rendering (SolidStart). @openrampkit/web (and Lit) loads only in the browser, in onMount and in click handlers. The package has no JSX in its build, so you do not need a Babel preset for it.

tsx
import {
  OpenRampProvider, useOpenRamp, DepositButton, WithdrawButton, OpenRampEmbedded, useDepositController,
  lightTheme, darkTheme, autoTheme,
} from '@openrampkit/solid'

The differences from React are the Solid conventions: class in place of className, and isOpen is an accessor (isOpen()).

OpenRampProvider ​

Holds the shared config and opens the modal.

tsx
<OpenRampProvider baseUrl="/api/openramp" theme={lightTheme()} wallet={wallet} onEvent={track}>
  <App />
</OpenRampProvider>
PropTypeDescription
baseUrlstringRequired. Base URL of your OpenRampKit server.
walletWalletAdapterEnables "Pay with wallet"
themeThemePushed live to an open modal
appearanceAppearancePushed live to an open modal
localestringBCP 47. Pushed live to an open modal.
messagesPartial<Messages>Applied when the modal opens
providerRenderersRecord<string, ProviderRenderer>Renderers for PROVIDER_SDK surfaces
onEvent(e: ClientEvent) => voidEvery browser event
childrenJSX.Element

Only one modal is open at a time. When you open a new modal, the previous modal closes. When the provider unmounts, the modal closes.

useOpenRamp() ​

ts
const { beginDeposit, beginWithdraw, close, isOpen } = useOpenRamp()

const session = await beginDeposit({ clientSecret: getClientSecret, onEvent: (e) => {} })
MemberTypeDescription
beginDeposit({ clientSecret, onEvent? })Promise<PublicSession>Opens the modal. Resolves when the deposit completes. Rejects (with an OpenRampError) when the modal closes first. Rejects on the server.
beginWithdraw({ clientSecret, onEvent? })Promise<PublicSession>The same for a withdraw session (created with direction: 'withdraw').
close()() => voidCloses the modal
isOpenAccessor<boolean>Whether the modal is open

It throws when there is no OpenRampProvider above it.

DepositButton ​

A ready-made button that calls beginDeposit. It is disabled while the modal is open.

tsx
<DepositButton getClientSecret={getClientSecret} label="Add funds" class="btn" onComplete={refreshBalance} onError={showError} />
PropTypeDescription
getClientSecretstring | () => Promise<string>Required. A secret, or a function that fetches one on click.
labelJSX.ElementDefault "Deposit"
classstring
disabledboolean
onComplete(session: PublicSession) => voidThe deposit completed
onError(error: OpenRampError) => voidThe modal closed before completion (code CLOSED, or the step's error)
onEvent(e: ClientEvent) => voidBrowser events for this deposit (in addition to the provider's)

DepositButton.Custom ​

Use your own markup. children is a function that gets { open, isOpen }.

tsx
<DepositButton.Custom getClientSecret={getClientSecret} onComplete={refreshBalance}>
  {({ open, isOpen }) => (
    <button onClick={open} disabled={isOpen()} class="my-button">
      Top up
    </button>
  )}
</DepositButton.Custom>

The props are the same as DepositButton without label, class and disabled.

WithdrawButton ​

A ready-made "Withdraw" button that calls beginWithdraw. getClientSecret must return the secret of a withdraw session. See Withdrawals. The props are the same as DepositButton. The default label is "Withdraw". Use WithdrawButton.Custom for your own markup.

tsx
<WithdrawButton getClientSecret={getWithdrawSecret} onComplete={refreshBalance} />

OpenRampEmbedded ​

Renders <openramp-modal embedded> inline, without an overlay. It follows the direction of the session, so it works for deposit and withdraw sessions.

tsx
<OpenRampEmbedded clientSecret={clientSecret} onComplete={() => navigate('/done')} style={{ 'max-width': '420px' }} />
PropTypeDescription
clientSecretstring | () => Promise<string>Required
baseUrlstringDefault: the provider's baseUrl. Required when there is no provider.
wallet, theme, appearance, messages, localeDefault: the provider's values
onEvent(e) => voidCalled after the provider's onEvent
onComplete(session) => voidThe deposit or withdrawal completed
onClose(session?) => voidThe user pressed Close or Done on a result or error screen
onController(controller) => voidReceives the controller when it exists
class, styleFor the element

It makes one controller for each client secret. A new string secret starts a new session. A new function does not. To start again with a function, render the component again, for example with <Show keyed>.

useDepositController(controller) ​

Subscribes to a DepositController and returns its Snapshot as an accessor. Use it for a fully custom UI, or next to OpenRampEmbedded with onController. controller can be a value or an accessor.

tsx
function Status(props: { controller?: DepositController }) {
  const snap = useDepositController(() => props.controller)
  return <p>{snap()?.screen}</p>
}

The value is undefined when controller is undefined or null. It does not subscribe during server rendering.

Re-exports ​

Themes: lightTheme, darkTheme, autoTheme (from @openrampkit/web/theme, no Lit). Types: Theme, ThemeOptions, ThemeColors, Appearance, RadiusScale, DepositController, WithdrawController, RampController, Snapshot, PublicSession, OpenRampError, ClientEvent, WalletAdapter, OpenRampConfig, OpenRampApi, OpenRampProviderProps, BeginDepositOptions, BeginWithdrawOptions, DepositButtonProps, DepositButtonCustomProps, DepositButtonRenderProps, WithdrawButtonProps, WithdrawButtonCustomProps, WithdrawButtonRenderProps, OpenRampEmbeddedProps.

Flow options ​

beginDeposit() and beginWithdraw() take flow and autoClose, and the embedded component takes them as props. They work as in openDeposit: flow sets the first tab, a method to open at once, the amount, presets, default tokens and a withdraw balance, and autoClose closes the modal when the payment completes.

MIT licensed