@salad-labs/loopz-typescript
Version:
The Official Loopz TypeScript SDK
33 lines • 1.3 kB
JavaScript
import React from "react";
import { createRoot } from "react-dom/client";
import { v4 as uuid } from "uuid";
import { Auth, Order } from "..";
import { PrivyContext } from "../react/components/privycontext";
export default class PrivyAdapter {
constructor(privyAdapterOptions) {
this._container = null;
this._root = null;
this._privyAppId = privyAdapterOptions.appId;
this._container = document.createElement("div");
this._container.id = uuid();
document.body.appendChild(this._container);
this._root = createRoot(this._container);
this._privyConfig = privyAdapterOptions.options;
}
render() {
if (!this._root)
throw new Error("Root object must be initializated.");
if (!this._privyConfig)
throw new Error("Privy configuration must be setup.");
const auth = Auth.getInstance();
const order = Order.getInstance();
this._root.render(React.createElement(PrivyContext, { auth: auth, order: order, appId: this._privyAppId, config: this._privyConfig }));
}
cleanup() {
if (this._container && this._root) {
this._root.unmount();
document.body.removeChild(this._container);
}
}
}
//# sourceMappingURL=privyadapter.js.map