Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/nft checkout plugin #2018

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
225 changes: 124 additions & 101 deletions demo/vue-app-new/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions demo/vue-app-new/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@web3auth/ethereum-provider": "file:../../packages/providers/ethereum-provider",
"@web3auth/modal": "file:../../packages/modal",
"@web3auth/modal-vue-composables": "file:../../packages/composables/modal-vue-composables",
"@web3auth/nft-checkout-plugin": "file:../../packages/plugins/nft-checkout-plugin",
"@web3auth/no-modal": "file:../../packages/no-modal",
"@web3auth/sign-in-with-ethereum": "^4.2.2",
"@web3auth/solana-provider": "file:../../packages/providers/solana-provider",
Expand Down
24 changes: 18 additions & 6 deletions demo/vue-app-new/src/MainView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { getInjectedAdapters as getInjectedSolanaAdapters } from "@web3auth/defa
import { EthereumPrivateKeyProvider } from "@web3auth/ethereum-provider";
import { type Web3AuthOptions } from "@web3auth/modal";
import { Web3AuthProvider } from "@web3auth/modal-vue-composables";
import { NFTCheckoutPlugin } from "@web3auth/nft-checkout-plugin";
import { SolanaPrivateKeyProvider } from "@web3auth/solana-provider";
import { TorusWalletAdapter } from "@web3auth/torus-evm-adapter";
import { SolanaWalletAdapter } from "@web3auth/torus-solana-adapter";
Expand All @@ -35,12 +36,22 @@ const formData = formDataStore;
const externalAdapters = ref<IAdapter<unknown>[]>([]);

const walletPlugins = computed(() => {
if (formData.chainNamespace !== CHAIN_NAMESPACES.EIP155 || !formData.walletPlugin.enable) return [];
const { logoDark, logoLight } = formData.walletPlugin;
const walletServicesPlugin = new WalletServicesPlugin({
walletInitOptions: { whiteLabel: { showWidgetButton: true, logoDark: logoDark || "logo", logoLight: logoLight || "logo" } },
});
return [walletServicesPlugin];
if (formData.chainNamespace !== CHAIN_NAMESPACES.EIP155) return [];
const plugins = [];
if (formData.nftCheckoutPlugin.enable) {
const nftCheckoutPlugin = new NFTCheckoutPlugin({
apiKey: "pk_test_4ca499b1f017c2a96bac63493dca4ac2eb08d1e91de0a796d87137dc7278e0af",
});
plugins.push(nftCheckoutPlugin);
}
if (formData.walletPlugin.enable) {
const { logoDark, logoLight } = formData.walletPlugin;
const walletServicesPlugin = new WalletServicesPlugin({
walletInitOptions: { whiteLabel: { showWidgetButton: true, logoDark: logoDark || "logo", logoLight: logoLight || "logo" } },
});
plugins.push(walletServicesPlugin);
}
return plugins;
});

const chainOptions = computed(() =>
Expand Down Expand Up @@ -200,6 +211,7 @@ onBeforeMount(() => {
formData.network = json.network;
formData.whiteLabel = json.whiteLabel;
formData.walletPlugin = json.walletPlugin;
formData.nftCheckoutPlugin = json.nftCheckoutPlugin || {};
formData.useAccountAbstractionProvider = json.useAccountAbstractionProvider;
formData.smartAccountType = json.smartAccountType;
formData.bundlerUrl = json.bundlerUrl;
Expand Down
22 changes: 22 additions & 0 deletions demo/vue-app-new/src/components/AppDashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
import { Button, Card } from "@toruslabs/vue-components";
import { CHAIN_NAMESPACES, IProvider, log, WALLET_ADAPTERS, WALLET_PLUGINS } from "@web3auth/base";
import { useWeb3Auth } from "@web3auth/modal-vue-composables";
import { NFTCheckoutPlugin } from "@web3auth/nft-checkout-plugin";
import { WalletServicesPlugin } from "@web3auth/wallet-services-plugin";
import { useI18n } from "vue-i18n";

import { NFT_CHECKOUT_CONTRACT_ID } from "../config";
import {
getAccounts,
getBalance,
Expand Down Expand Up @@ -42,12 +44,23 @@ const isDisplay = (name: string): boolean => {
web3Auth.value?.connectedAdapterName === WALLET_ADAPTERS.AUTH
);

case "nftCheckoutServices":
return formData.chainNamespace === CHAIN_NAMESPACES.EIP155 && formData.nftCheckoutPlugin.enable;

default: {
return false;
}
}
};

const showPaidMintNFTCheckout = async () => {
const nftCheckoutPlugin = web3Auth.value?.getPlugin(WALLET_PLUGINS.NFT_CHECKOUT) as NFTCheckoutPlugin;
nftCheckoutPlugin.show({ contractId: NFT_CHECKOUT_CONTRACT_ID.PAID_MINT });
};
const showFreeMintNFTCheckout = async () => {
const nftCheckoutPlugin = web3Auth.value?.getPlugin(WALLET_PLUGINS.NFT_CHECKOUT) as NFTCheckoutPlugin;
nftCheckoutPlugin.show({ contractId: NFT_CHECKOUT_CONTRACT_ID.FREE_MINT });
};
const showWalletUI = async () => {
const walletPlugin = web3Auth.value?.getPlugin(WALLET_PLUGINS.WALLET_SERVICES) as WalletServicesPlugin;
await walletPlugin.showWalletUi();
Expand Down Expand Up @@ -207,6 +220,15 @@ const onSignPersonalMsg = async () => {
{{ $t("app.buttons.btnShowCheckout") }}
</Button>
</Card>
<Card v-if="isDisplay('nftCheckoutServices')" class="!h-auto lg:!h-[calc(100dvh_-_240px)] gap-4 px-4 py-4 mb-2" :shadow="false">
<div class="mb-2 text-xl font-bold leading-tight text-left">NFT Checkout Service</div>
<Button block size="xs" pill class="mb-2" @click="showFreeMintNFTCheckout">
{{ $t("app.buttons.btnShowFreeMintNFTCheckout") }}
</Button>
<Button block size="xs" pill class="mb-2" @click="showPaidMintNFTCheckout">
{{ $t("app.buttons.btnShowPaidMintNFTCheckout") }}
</Button>
</Card>
<Card v-if="isDisplay('ethServices')" class="px-4 py-4 gap-4 !h-auto lg:!h-[calc(100dvh_-_240px)]" :shadow="false">
<div class="mb-2 text-xl font-bold leading-tight text-left">Sample Transaction</div>
<Button block size="xs" pill class="mb-2" @click="onGetAccounts">
Expand Down
17 changes: 17 additions & 0 deletions demo/vue-app-new/src/components/AppSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ const isDisabled = (name: string): boolean => {
case "walletServicePlugin":
return formData.chainNamespace !== CHAIN_NAMESPACES.EIP155;

case "nftCheckoutPlugin":
return formData.chainNamespace !== CHAIN_NAMESPACES.EIP155;

case "btnConnect":
return !isInitialized.value;

Expand Down Expand Up @@ -99,6 +102,9 @@ const onChainNamespaceChange = (value: string) => {
Wallet Plugin
</Tab>
<Tab v-if="formData.chainNamespace === CHAIN_NAMESPACES.EIP155" variant="underline" :active="isActiveTab(4)" @click="onTabChange(4)">
NFT Checkout Plugin
</Tab>
<Tab v-if="formData.chainNamespace === CHAIN_NAMESPACES.EIP155" variant="underline" :active="isActiveTab(5)" @click="onTabChange(5)">
Account Abstraction Provider
</Tab>
</Tabs>
Expand Down Expand Up @@ -352,6 +358,17 @@ const onChainNamespaceChange = (value: string) => {
/>
</Card>
<Card v-if="isActiveTab(4)" class="grid grid-cols-1 gap-2 px-4 py-4" :shadow="false">
<Toggle
v-model="formData.nftCheckoutPlugin.enable"
:disabled="isDisabled('nftCheckoutPlugin')"
:show-label="true"
:size="'small'"
:label-disabled="$t('app.nftCheckoutPlugin.title')"
:label-enabled="$t('app.nftCheckoutPlugin.title')"
class="mb-2"
/>
</Card>
<Card v-if="isActiveTab(5)" class="grid grid-cols-1 gap-2 px-4 py-4" :shadow="false">
<Toggle
v-model="formData.useAccountAbstractionProvider"
data-testid="accountAbstractionProvider"
Expand Down
8 changes: 8 additions & 0 deletions demo/vue-app-new/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ export type FormData = {
logoDark: string;
logoLight: string;
};
nftCheckoutPlugin: {
enable: boolean;
};
useAccountAbstractionProvider: boolean;
useAAWithExternalWallet?: boolean;
smartAccountType?: SmartAccountType;
Expand Down Expand Up @@ -240,3 +243,8 @@ export const getV4TypedData = (chainId: string): SignTypedDataMessageV4 => ({
contents: "Hello, Bob!",
},
});

export const NFT_CHECKOUT_CONTRACT_ID = {
FREE_MINT: "b5b4de3f-0212-11ef-a08f-0242ac190003",
PAID_MINT: "d1145a8b-98ae-44e0-ab63-2c9c8371caff",
};
3 changes: 3 additions & 0 deletions demo/vue-app-new/src/store/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export const formDataStore = reactive<FormData>({
logoLight: "",
logoDark: "",
},
nftCheckoutPlugin: {
enable: false,
},
useAccountAbstractionProvider: false,
useAAWithExternalWallet: true,
});
7 changes: 6 additions & 1 deletion demo/vue-app-new/src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
"logoLight": "Logo Light",
"logoDark": "Logo Dark"
},
"nftCheckoutPlugin": {
"title": "NFT Checkout Plugin"
},
"accountAbstractionProvider": {
"title": "Account Abstraction Provider",
"smartAccountType": "Smart Account Type",
Expand Down Expand Up @@ -71,7 +74,9 @@
"btnShowCheckout": "Show Checkout",
"btnShowWalletConnectScanner": "Show WalletConnect Scanner",
"btnSignTypedData_v4": "Sign Typed Data v4",
"btnSignPersonalMsg": "Sign Personal Message"
"btnSignPersonalMsg": "Sign Personal Message",
"btnShowFreeMintNFTCheckout": "Show Free Mint NFT",
"btnShowPaidMintNFTCheckout": "Show Paid Mint NFT"
}
}
}
Loading