From 3787fab918e40f216658552b13abe36b17c2bfb5 Mon Sep 17 00:00:00 2001 From: Tempe Techie <95053628+tempe-techie@users.noreply.github.com> Date: Thu, 11 Apr 2024 09:51:55 +0200 Subject: [PATCH] better check if user is connected and if network is correct --- components/names/NameMintWidget.vue | 24 ++++++++++---- components/navbars/NavbarMobile.vue | 30 +++++++++++++++-- .../send-tokens/SendTokensComponent.vue | 13 +++----- components/swap/SimpleSwap.vue | 32 ++++++++----------- pages/keys.vue | 22 ++++++++++--- pages/nft/collection.vue | 23 +++++++++---- pages/nft/create.vue | 32 ++++++++++++++++--- 7 files changed, 124 insertions(+), 52 deletions(-) diff --git a/components/names/NameMintWidget.vue b/components/names/NameMintWidget.vue index 093a8af1..d51c32d3 100644 --- a/components/names/NameMintWidget.vue +++ b/components/names/NameMintWidget.vue @@ -29,16 +29,16 @@

- -
- - + + + @@ -49,6 +49,7 @@ import { ethers } from 'ethers'; import { useToast } from "vue-toastification/dist/index.mjs"; import WaitingToast from "~/components/WaitingToast"; import ConnectWalletButton from "~/components/ConnectWalletButton"; +import SwitchChainButton from '~/components//SwitchChainButton.vue'; import { useUserStore } from '~/store/user'; import { getDomainName } from '~/utils/domainUtils'; import { fetchReferrer, fetchUsername, storeUsername } from '~/utils/storageUtils'; @@ -74,6 +75,7 @@ export default { components: { ConnectWalletButton, + SwitchChainButton, WaitingToast }, @@ -198,7 +200,15 @@ export default { } else { return this.price5char; } - } + }, + + isSupportedChain() { + if (this.chainId === this.$config.supportedChainId) { + return true; + } else { + return false; + } + }, }, methods: { @@ -367,11 +377,11 @@ export default { }, setup() { - const { address, balance, isActivated, signer } = useEthers(); + const { address, balance, chainId, isActivated, signer } = useEthers(); const toast = useToast(); const userStore = useUserStore(); - return { address, balance, isActivated, signer, toast, userStore }; + return { address, balance, chainId, isActivated, signer, toast, userStore }; } } \ No newline at end of file diff --git a/components/navbars/NavbarMobile.vue b/components/navbars/NavbarMobile.vue index afbe10ab..a0bcf6b4 100644 --- a/components/navbars/NavbarMobile.vue +++ b/components/navbars/NavbarMobile.vue @@ -15,16 +15,41 @@ - + + +
+
+ + +
+
\ No newline at end of file diff --git a/components/send-tokens/SendTokensComponent.vue b/components/send-tokens/SendTokensComponent.vue index 4156cb65..b99dc1d8 100644 --- a/components/send-tokens/SendTokensComponent.vue +++ b/components/send-tokens/SendTokensComponent.vue @@ -98,14 +98,7 @@ - + @@ -120,6 +113,7 @@ import { getTokenBalance } from '~/utils/balanceUtils'; import { hasTextBlankCharacters } from '~/utils/textUtils'; import WaitingToast from "~/components/WaitingToast"; import ConnectWalletButton from '~/components/ConnectWalletButton.vue'; +import SwitchChainButton from '~/components/SwitchChainButton.vue'; import Erc20Abi from "~/assets/abi/Erc20Abi.json"; export default { @@ -141,7 +135,8 @@ export default { }, components: { - ConnectWalletButton + ConnectWalletButton, + SwitchChainButton }, mounted() { diff --git a/components/swap/SimpleSwap.vue b/components/swap/SimpleSwap.vue index 003d05c5..b03fb4b7 100644 --- a/components/swap/SimpleSwap.vue +++ b/components/swap/SimpleSwap.vue @@ -92,27 +92,19 @@ ({{ siteStore.getSlippage }}% slippage). - - -
- -
-
+
- + + + +
-
+
+
-
+
-
+
- + (Price may still change after pressing the button, so make sure to check the {{ $config.tokenSymbol }} amount in wallet.) @@ -201,6 +202,7 @@ import { useEthers, shortenAddress } from 'vue-dapp'; import { useToast } from "vue-toastification/dist/index.mjs"; import ChatFeed from "~/components/chat/ChatFeed.vue"; import ConnectWalletButton from "~/components/ConnectWalletButton.vue"; +import SwitchChainButton from '~/components/SwitchChainButton.vue'; import WaitingToast from "~/components/WaitingToast"; import AddImageToCollectionModal from "~/components/nft/collection/AddImageToCollectionModal"; import ChangeCollectionPreviewModal from "~/components/nft/collection/ChangeCollectionPreviewModal"; @@ -242,6 +244,7 @@ export default { ChatFeed, ConnectWalletButton, RemoveImageFromCollectionModal, + SwitchChainButton, WaitingToast }, @@ -282,7 +285,15 @@ export default { } return false; - } + }, + + isSupportedChain() { + if (this.chainId === this.$config.supportedChainId) { + return true; + } else { + return false; + } + }, }, methods: { diff --git a/pages/nft/create.vue b/pages/nft/create.vue index 90d7c579..f9bb8fd6 100644 --- a/pages/nft/create.vue +++ b/pages/nft/create.vue @@ -134,7 +134,7 @@ - + +
@@ -173,6 +174,7 @@ import { ethers } from 'ethers'; import { useEthers } from 'vue-dapp'; import { useToast } from "vue-toastification/dist/index.mjs"; import ConnectWalletButton from "~/components/ConnectWalletButton.vue"; +import SwitchChainButton from '~/components/SwitchChainButton.vue'; import WaitingToast from "~/components/WaitingToast"; import FileUploadModal from "~/components/storage/FileUploadModal.vue"; import { useUserStore } from '~/store/user'; @@ -202,6 +204,7 @@ export default { components: { ConnectWalletButton, FileUploadModal, + SwitchChainButton, WaitingToast }, @@ -245,6 +248,14 @@ export default { fieldsValid() { return this.cName && this.cSymbol && this.cImage && this.cDescription && this.nftName && this.ratio; }, + + isSupportedChain() { + if (this.chainId === this.$config.supportedChainId) { + return true; + } else { + return false; + } + }, }, methods: { @@ -338,7 +349,20 @@ export default { } } catch (e) { console.error(e); - this.toast(e.message, {type: "error"}); + + try { + let extractMessage = e.message.split("reason=")[1]; + extractMessage = extractMessage.split(", method=")[0]; + extractMessage = extractMessage.replace(/"/g, ""); + extractMessage = extractMessage.replace('execution reverted:', "Error:"); + + console.log(extractMessage); + + this.toast(extractMessage, {type: "error"}); + } catch (e) { + this.toast("Transaction has failed.", {type: "error"}); + } + this.waitingCreate = false; } }