Skip to content

Commit

Permalink
only use web3auth client ID in NFT checkout plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
tanguyenvn committed Dec 3, 2024
1 parent fc6f69c commit 55905b9
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 33 deletions.
4 changes: 2 additions & 2 deletions demo/vue-app-new/src/MainView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { computed, onBeforeMount, ref, watch } from "vue";
import AppDashboard from "./components/AppDashboard.vue";
import AppHeader from "./components/AppHeader.vue";
import AppSettings from "./components/AppSettings.vue";
import { chainConfigs, clientIds, getDefaultBundlerUrl } from "./config";
import { chainConfigs, clientIds, getDefaultBundlerUrl, NFT_CHECKOUT_CLIENT_ID } from "./config";
import { formDataStore } from "./store/form";
const formData = formDataStore;
Expand All @@ -40,7 +40,7 @@ const walletPlugins = computed(() => {
const plugins = [];
if (formData.nftCheckoutPlugin.enable) {
const nftCheckoutPlugin = new NFTCheckoutPlugin({
apiKey: "pk_test_4ca499b1f017c2a96bac63493dca4ac2eb08d1e91de0a796d87137dc7278e0af",
web3AuthClientId: NFT_CHECKOUT_CLIENT_ID,
});
plugins.push(nftCheckoutPlugin);
}
Expand Down
7 changes: 1 addition & 6 deletions demo/vue-app-new/src/components/AppDashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ import {
signTypedMessage,
} from "../services/ethHandlers";
import { signAllTransactions, signAndSendTransaction, signMessage, signTransaction as signSolTransaction } from "../services/solHandlers";
import {
walletSendEth,
walletSignPersonalMessage,
walletSignTransaction as walletSignEthTransaction,
walletSignTypedMessage,
} from "../services/walletServiceHandlers";
import { walletSendEth, walletSignPersonalMessage, walletSignTypedMessage } from "../services/walletServiceHandlers";
import { formDataStore } from "../store/form";
const { t } = useI18n({ useScope: "global" });
Expand Down
2 changes: 2 additions & 0 deletions demo/vue-app-new/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,5 @@ export const NFT_CHECKOUT_CONTRACT_ID = {
FREE_MINT: "b5b4de3f-0212-11ef-a08f-0242ac190003",
PAID_MINT: "d1145a8b-98ae-44e0-ab63-2c9c8371caff",
};

export const NFT_CHECKOUT_CLIENT_ID = "BHgArYmWwSeq21czpcarYh0EVq2WWOzflX-NTK-tY1-1pauPzHKRRLgpABkmYiIV_og9jAvoIxQ8L3Smrwe04Lw";
22 changes: 2 additions & 20 deletions packages/plugins/nft-checkout-plugin/src/embed.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { randomId } from "@toruslabs/base-controllers";
import { THEME_MODES, WEB3AUTH_NETWORK_TYPE, WhiteLabelData } from "@web3auth/auth";
import { THEME_MODES, WhiteLabelData } from "@web3auth/auth";
import log from "loglevel";

import {
Expand Down Expand Up @@ -36,34 +36,18 @@ import { getTheme, htmlToElement } from "./utils";
export class NFTCheckoutEmbed {
web3AuthClientId: string;

web3AuthNetwork: WEB3AUTH_NETWORK_TYPE;

isInitialized: boolean;

private modalZIndex: number;

private apiKey: string;

private buildEnv: NFT_CHECKOUT_BUILD_ENV_TYPE;

private readonly embedNonce = randomId();

constructor({
modalZIndex = 99999,
apiKey,
web3AuthClientId,
web3AuthNetwork,
}: {
modalZIndex?: number;
apiKey: string;
web3AuthClientId?: string;
web3AuthNetwork?: WEB3AUTH_NETWORK_TYPE;
}) {
constructor({ modalZIndex = 99999, web3AuthClientId }: { modalZIndex?: number; web3AuthClientId: string }) {
this.isInitialized = false;
this.modalZIndex = modalZIndex;
this.apiKey = apiKey;
this.web3AuthClientId = web3AuthClientId;
this.web3AuthNetwork = web3AuthNetwork;
}

public async init(params: { buildEnv?: NFT_CHECKOUT_BUILD_ENV_TYPE; whiteLabel?: WhiteLabelData }): Promise<void> {
Expand Down Expand Up @@ -106,9 +90,7 @@ export class NFTCheckoutEmbed {
nftCheckoutIframe.contentWindow.postMessage(
{
type: MESSAGE_INIT,
apiKey: this.apiKey,
web3AuthClientId: this.web3AuthClientId,
web3AuthNetwork: this.web3AuthNetwork,
whiteLabel,
},
nftCheckoutIframeUrl.origin
Expand Down
7 changes: 2 additions & 5 deletions packages/plugins/nft-checkout-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SafeEventEmitter, WEB3AUTH_NETWORK_TYPE, type WhiteLabelData } from "@web3auth/auth";
import { SafeEventEmitter, type WhiteLabelData } from "@web3auth/auth";
import {
ADAPTER_STATUS,
EVM_PLUGINS,
Expand Down Expand Up @@ -30,7 +30,7 @@ export class NFTCheckoutPlugin extends SafeEventEmitter implements IPlugin {

private receiverAddress: string | null = null;

constructor(params: { modalZIndex?: number; apiKey: string; web3AuthClientId?: string; web3AuthNetwork?: WEB3AUTH_NETWORK_TYPE }) {
constructor(params: { modalZIndex?: number; web3AuthClientId: string }) {
super();
this.nftCheckoutEmbedInstance = new NFTCheckoutEmbed(params);
}
Expand All @@ -40,9 +40,6 @@ export class NFTCheckoutPlugin extends SafeEventEmitter implements IPlugin {
if (!web3auth) throw NFTCheckoutPluginError.web3authRequired();

this.web3auth = web3auth;
this.nftCheckoutEmbedInstance.web3AuthClientId = web3auth.coreOptions.clientId;
this.nftCheckoutEmbedInstance.web3AuthNetwork = web3auth.coreOptions.web3AuthNetwork;

await this.nftCheckoutEmbedInstance.init({
whiteLabel,
});
Expand Down

0 comments on commit 55905b9

Please sign in to comment.