import { createRampClient, createZecSendStore } from "@0xramp/sdk";
// One durable, secure storage namespace per unlocked wallet.
const sendStore = createZecSendStore({
get: key => secureWalletStorage.get(key),
set: (key, value) => secureWalletStorage.set(key, value),
});
const ramp = createRampClient({
environment: "production",
partnerId: "<issued-by-0xramp>",
sendStore,
});
// 1 -- open a session
await secureSessionStorage.saveCreationIntent(partnerSessionId);
const session = await ramp.createSession({
direction: "sell",
asset: "ZEC",
fiat: "BRL",
partnerSessionId,
});
await secureSessionStorage.save(session);
// 2 -- attach before loading the pane
const bridge = ramp.attachPaneBridge({
sessionRef: session.sessionRef,
transport: myTransport,
onZecSendRequest: (request, { signal }) =>
myWallet.confirmAndSend(request, { signal }),
onSendRecoveryRequired: showRecoveryScreen,
onResult: () => { void refreshAuthoritativeStatus(); },
onClose: teardownPane,
});
// 3 -- load the pane (check origin first)
if (!ramp.isAllowedPaneUrl(session.sessionUrl)) throw new Error("origin refused");
loadWebView(session.sessionUrl);
// 4 -- authoritative status
const status = await ramp.getStatus(session.sessionRef);
// 5 -- close detaches listeners
bridge.close();