Skip to content

@openrampkit/vue ​

A thin Vue 3 wrapper over <openramp-modal>. It has the same API shape as @openrampkit/react. Peer dependency: vue >= 3.3.

It is safe for server rendering (Nuxt). @openrampkit/web (and Lit) loads only in the browser, in onMounted and in click handlers. The package has no .vue files, so you do not need a special build step.

ts
import {
  OpenRampProvider, provideOpenRamp, useOpenRamp, DepositButton, WithdrawButton, OpenRampEmbedded, useDepositController,
  lightTheme, darkTheme, autoTheme,
} from '@openrampkit/vue'

Callback props use the on prefix, so you can also write them as Vue listeners: :on-complete="fn" and @complete="fn" are the same.

OpenRampProvider ​

Holds the shared config and opens the modal.

vue
<script setup lang="ts">
import { OpenRampProvider, lightTheme } from '@openrampkit/vue'
</script>

<template>
  <OpenRampProvider base-url="/api/openramp" :theme="lightTheme()" :wallet="wallet" @event="track">
    <App />
  </OpenRampProvider>
</template>
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 (@event)(e: ClientEvent) => voidEvery browser event

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.

provideOpenRamp(config) ​

Does the same as OpenRampProvider, without a wrapper component. Call it in setup(), for example in App.vue or in a Nuxt layout. config can be an object, a ref or a getter. The function returns the same API as useOpenRamp().

ts
import { ref } from 'vue'
import { provideOpenRamp, lightTheme } from '@openrampkit/vue'

const theme = ref(lightTheme())
const ramp = provideOpenRamp(() => ({ baseUrl: '/api/openramp', theme: theme.value }))

When the scope of the caller stops, the modal closes.

useOpenRamp() ​

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

const session = await beginDeposit({
  clientSecret: () => fetch('/api/deposit-session', { method: 'POST' }).then((r) => r.json()).then((j) => j.clientSecret),
  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
isOpenReadonly<Ref<boolean>>Whether the modal is open

It throws when there is no OpenRampProvider or provideOpenRamp() above it.

DepositButton ​

A ready-made button that calls beginDeposit. It is disabled while the modal is open. The class attribute goes to the <button>.

vue
<DepositButton :get-client-secret="getClientSecret" class="btn" @complete="refreshBalance" @error="showError">
  Add funds
</DepositButton>
PropTypeDescription
getClientSecretstring | () => Promise<string>Required. A secret, or a function that fetches one on click.
labelstringDefault "Deposit". The default slot replaces it.
disabledboolean
onComplete (@complete)(session: PublicSession) => voidThe deposit completed
onError (@error)(error: OpenRampError) => voidThe modal closed before completion (code CLOSED, or the step's error)
onEvent (@event)(e: ClientEvent) => voidBrowser events for this deposit (in addition to the provider's)

DepositButton.Custom ​

Use your own markup. The default slot gets { open, isOpen }. The component is also exported as DepositButtonCustom.

vue
<DepositButton.Custom :get-client-secret="getClientSecret" @complete="refreshBalance">
  <template #default="{ open, isOpen }">
    <button class="my-button" :disabled="isOpen" @click="open">Top up</button>
  </template>
</DepositButton.Custom>

The props are the same as DepositButton without label 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 (or WithdrawButtonCustom) for your own markup.

vue
<WithdrawButton :get-client-secret="getWithdrawSecret" @complete="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. The class and style attributes go to the element.

vue
<OpenRampEmbedded :client-secret="clientSecret" style="max-width: 420px" @complete="router.push('/done')" />
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 (@event)(e) => voidCalled after the provider's onEvent
onComplete (@complete)(session) => voidThe deposit or withdrawal completed
onClose (@close)(session?) => voidThe user pressed Close or Done on a result or error screen
onController (@controller)(controller) => voidReceives the controller when it exists

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, change the key of the component.

useDepositController(controller) ​

Subscribes to a DepositController and returns its Snapshot as a shallow ref. Use it for a fully custom UI, or next to OpenRampEmbedded with @controller. controller can be a value, a ref or a getter.

ts
import { shallowRef } from 'vue'
import { useDepositController, type DepositController } from '@openrampkit/vue'

const controller = shallowRef<DepositController>()
const snap = useDepositController(controller)
// snap.value?.screen

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

Nuxt ​

Nothing more is necessary. The components render a plain <button> or <openramp-modal> on the server, and the modal code loads in the browser. To stop the Vue warning about an unknown element in your own templates, tell the compiler that openramp-modal is a custom element:

ts
// nuxt.config.ts
export default defineNuxtConfig({
  vue: { compilerOptions: { isCustomElement: (tag) => tag === 'openramp-modal' } },
})

You need this only when you write <openramp-modal> in a template yourself. OpenRampEmbedded does not need it.

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, DepositButtonSlotProps, WithdrawButtonProps, WithdrawButtonCustomProps, WithdrawButtonSlotProps, 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