-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.vue
43 lines (38 loc) · 1.14 KB
/
app.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<template>
<div>
<button v-text="connectionButtonTitle" @click="handleClickConnectionButton" />
<div v-text="walletAddress" />
</div>
</template>
<script lang="ts" setup>
import { LikeCoinEVMWalletConnector } from "@likecoin/evm-wallet-connector";
const walletAddress = ref<string>("");
const connector = ref<LikeCoinEVMWalletConnector | null>(null);
const connectionButtonTitle = computed(() =>
walletAddress.value ? "Disconnect" : "Connect"
);
onMounted(() => {
const { magicLinkAPIKey, rpcURL, chainId } = useRuntimeConfig().public;
connector.value = new LikeCoinEVMWalletConnector({
magicLinkAPIKey,
rpcURL,
chainId: Number(chainId),
onSelectConnectProvider: (providerId: string) => {
console.log("Selected", providerId);
},
onConnect: (connection: { walletAddress: string, providerId: string }) => {
walletAddress.value = connection.walletAddress;
},
onDisconnect: () => {
walletAddress.value = "";
},
});
})
function handleClickConnectionButton() {
if (walletAddress.value) {
connector.value?.disconnect();
} else {
connector.value?.showConnectPortal();
}
}
</script>