2022-08-25 22:39:02 +00:00
|
|
|
<template>
|
|
|
|
<ion-app>
|
2022-10-07 17:07:59 +00:00
|
|
|
<ion-router-outlet />
|
2022-08-25 22:39:02 +00:00
|
|
|
</ion-app>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2022-10-07 17:07:59 +00:00
|
|
|
import { IonApp, IonRouterOutlet } from "@ionic/vue";
|
2024-04-12 16:39:26 +00:00
|
|
|
import { defineComponent, onBeforeMount, onMounted } from "vue";
|
2022-10-15 20:20:33 +00:00
|
|
|
import { useRoute, useRouter } from "vue-router";
|
2022-10-30 23:34:21 +00:00
|
|
|
import { getSettings } from "@/utils/platform";
|
2024-01-24 00:41:31 +00:00
|
|
|
import { getSelectedAddress } from "@/utils/wallet";
|
|
|
|
import type { RequestArguments } from "@/extension/types";
|
2022-08-25 22:39:02 +00:00
|
|
|
|
|
|
|
export default defineComponent({
|
2022-10-07 17:07:59 +00:00
|
|
|
name: "App",
|
2022-08-25 22:39:02 +00:00
|
|
|
components: {
|
2022-10-07 17:07:59 +00:00
|
|
|
IonApp,
|
|
|
|
IonRouterOutlet,
|
2022-08-25 22:39:02 +00:00
|
|
|
},
|
2022-10-30 23:34:21 +00:00
|
|
|
setup() {
|
|
|
|
const route = useRoute();
|
|
|
|
const router = useRouter();
|
|
|
|
const { param, rid } = route.query;
|
2022-10-07 17:07:59 +00:00
|
|
|
|
2024-01-24 00:41:31 +00:00
|
|
|
const pageListener = (
|
|
|
|
message: RequestArguments,
|
|
|
|
sender: any,
|
|
|
|
sendResponse: (a: any) => any
|
|
|
|
) => {
|
|
|
|
if (chrome.runtime.lastError) {
|
|
|
|
console.info("Error receiving message:", chrome.runtime.lastError);
|
|
|
|
}
|
2024-07-09 14:02:25 +00:00
|
|
|
if (message?.type === "CLWALLET_PAGE_MSG") {
|
|
|
|
console.info("page listener:", message);
|
2024-01-24 00:41:31 +00:00
|
|
|
|
2024-07-09 14:02:25 +00:00
|
|
|
(async () => {
|
|
|
|
if (!message?.method) {
|
|
|
|
sendResponse({
|
|
|
|
code: 500,
|
|
|
|
message: "Invalid request method",
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// ETH API
|
|
|
|
switch (message.method) {
|
|
|
|
case "paste": {
|
|
|
|
const currentAddress = (await getSelectedAddress()) as string[];
|
|
|
|
if (currentAddress.length > 0) {
|
|
|
|
document.execCommand("insertText", false, currentAddress[0]);
|
|
|
|
}
|
|
|
|
sendResponse(true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
sendResponse({
|
|
|
|
error: true,
|
|
|
|
message:
|
|
|
|
"ClearWallet: Invalid PAGE request method " + (message?.method ?? ""),
|
|
|
|
});
|
|
|
|
break;
|
2024-01-24 00:41:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-07-09 14:02:25 +00:00
|
|
|
})();
|
|
|
|
}
|
2024-01-24 00:41:31 +00:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2024-04-12 16:39:26 +00:00
|
|
|
if (chrome?.runtime?.onMessage) {
|
|
|
|
chrome.runtime.onMessage.addListener(pageListener);
|
|
|
|
console.info("page listener set");
|
|
|
|
}
|
|
|
|
|
2022-10-30 23:34:21 +00:00
|
|
|
onBeforeMount(() => {
|
|
|
|
getSettings().then((settings) => {
|
|
|
|
if (settings.theme !== "system") {
|
|
|
|
document.body.classList.remove(settings.theme === "dark" ? "light" : "dark");
|
|
|
|
document.body.classList.add(settings.theme);
|
|
|
|
}
|
|
|
|
});
|
2024-01-24 00:41:31 +00:00
|
|
|
});
|
|
|
|
|
2024-04-12 16:39:26 +00:00
|
|
|
// onUnmounted(() => {
|
|
|
|
// if (chrome?.runtime?.onMessage) {
|
|
|
|
// chrome.runtime.onMessage.removeListener(pageListener);
|
|
|
|
// console.info("page listener removed");
|
|
|
|
// }
|
|
|
|
// });
|
2022-10-30 23:34:21 +00:00
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
switch (route?.query?.route ?? "") {
|
|
|
|
case "sign-msg": {
|
|
|
|
router.push({
|
|
|
|
path: `/sign-msg/${rid}/${param}`,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "sign-tx": {
|
|
|
|
router.push({
|
|
|
|
path: `/sign-tx/${rid}/${param}`,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "switch-network": {
|
|
|
|
router.push({
|
|
|
|
path: `/switch-network/${rid}/${param}`,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "request-network": {
|
|
|
|
router.push({
|
|
|
|
path: `/request-network/${rid}/${param}`,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "wallet-error": {
|
|
|
|
router.push({
|
|
|
|
path: `/wallet-error/${rid}/${param}`,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
router.push({ path: "/" });
|
|
|
|
}
|
|
|
|
}
|
2022-10-13 20:48:07 +00:00
|
|
|
});
|
2022-10-30 23:34:21 +00:00
|
|
|
},
|
2022-08-25 22:39:02 +00:00
|
|
|
});
|
|
|
|
</script>
|