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

🐞 Connect minor fixes #471

Merged
merged 10 commits into from
Oct 24, 2024
3 changes: 1 addition & 2 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<AppHeader />
<div class="router-wrap" v-if="checkInProcess">
<div class="router-wrap" :style="pageBackground">
<img
class="mim-top-bg"
src="@/assets/images/main-mim-top-bg.png"
Expand Down Expand Up @@ -56,7 +56,6 @@ export default {

computed: {
...mapGetters({
checkInProcess: "getWalletIsConnected",
signer: "getSigner",
}),
},
Expand Down
6 changes: 5 additions & 1 deletion src/components/ui/buttons/ConnectButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<button
class="connect-btn"
:class="{ connected: !!account }"
:disabled="isWalletCheckInProcess"
@click="walletBtnHandler"
>
<div class="account-image-wrap" v-if="walletBtnIcon">
Expand Down Expand Up @@ -30,11 +31,14 @@ export default {
...mapGetters({
chainId: "getChainId",
account: "getAccount",
isWalletCheckInProcess: "getIsWalletCheckInProcess",
ensName: "getEnsName",
}),

walletBtnText() {
if (this.account) {
if (this.isWalletCheckInProcess) {
return "Connecting...";
} else if (this.account) {
if (this.ensName) return this.ensName;
return `${this.account.slice(0, 6)}...${this.account.slice(-6)}`;
} else {
Expand Down
14 changes: 7 additions & 7 deletions src/helpers/cauldron/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getExpectedPostition } from "./getExpectedPosition";
import { expandDecimals } from "../gm/fee/expandDecials";
import { getMaxToBorrow, getMaxCollateralToRemove } from "./utils";
import { PERCENT_PRESITION } from "@/helpers/cauldron/utils";
import { getAccountHelper } from "@/helpers/walletClienHelper";
import type { Address } from "viem";

export const WARNING_TYPES = {
DEPOSIT_ALLOWANCE: 0,
Expand Down Expand Up @@ -58,15 +58,17 @@ export const validateCookByAction = (
cauldron: CauldronInfo,
actionConfig: ActionConfig,
action: "borrow" | "repay",
chainId: number
chainId: number,
account: Address
) => {
const cookType = getCookTypeByAction(actionConfig, action);

const expectedPosition = getExpectedPostition(cauldron, actionConfig, action);

let validationErrors: any = [];

validationErrors = validateConnection(validationErrors);
validationErrors = validateConnection(account, validationErrors);

validationErrors = validateChain(validationErrors, cauldron, chainId);

validationErrors = validatePosition(
Expand Down Expand Up @@ -450,10 +452,8 @@ const validateChain = (
return validationErrors;
};

const validateConnection = (validationErrors: any) => {
const { isConnected } = getAccountHelper();

if (!isConnected) validationErrors.push(WARNING_TYPES.CONNECTION);
const validateConnection = (account: Address, validationErrors: any) => {
if (!account) validationErrors.push(WARNING_TYPES.CONNECTION);

return validationErrors;
};
Expand Down
7 changes: 5 additions & 2 deletions src/helpers/validators/swap/validationActions.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import type { ActionConfig } from "@/helpers/pools/swap/getSwapInfo";
import { validateConnection } from "@/helpers/validators/validateConnection";
import type { Address } from "viem";
const SUPPORTED_CHAINS = [1, 42161, 2222, 81457]; //TODO: Import from config

export const validationActions = (
actionConfig: ActionConfig,
selectedNetwork: number,
chainId: number,
account: Address,
isApproving: boolean
) => {
const { fromToken, toToken, fromInputValue, toInputValue } = actionConfig;

const connectedError = validateConnection();
const connectedError = validateConnection(account);

if (connectedError.btnText) return connectedError;

const chainError = validateChain(selectedNetwork, chainId);
Expand Down Expand Up @@ -59,4 +62,4 @@ const validateChain = (
};

return { btnText: "", isAllowed: true };
};
};
11 changes: 5 additions & 6 deletions src/helpers/validators/validateConnection.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { getAccountHelper } from "@/helpers/walletClienHelper";
import type { Address } from "viem";

export const validateConnection = () => {
const { isConnected } = getAccountHelper();

if (!isConnected)
export const validateConnection = (account: Address) => {
if (!account)
return {
btnText: "Connect Wallet",
isAllowed: true,
method: "connectWallet",
};
return { btnText: false, isAllowed: true };

return { btnText: "", isAllowed: true };
};
9 changes: 3 additions & 6 deletions src/mixins/temp.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export default {
this.cauldron,
this.actionConfig,
this.action,
this.chainId
this.chainId,
this.account
);
},
useNoDeleverageConfirmationPopup() {
Expand Down Expand Up @@ -219,11 +220,7 @@ export default {
this.isOpenGMPopup = true;
this.$emit("clearData");
},
async gmDeleverageHandler(
cookPayload,
cauldronObject,
notificationId
) {
async gmDeleverageHandler(cookPayload, cauldronObject, notificationId) {
const { cauldron } = cauldronObject.contracts;
const cauldronActiveOrder = await cauldron.orders(cookPayload.to);

Expand Down
20 changes: 17 additions & 3 deletions src/plugins/walletConnect/initConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,33 @@ import { getAccount } from "@wagmi/core";
import type { Config } from "@wagmi/core";
import { watchAccount, watchChainId } from "@wagmi/core";
import { getEthersProvider } from "@/helpers/chains/getChainsInfo";
import store from "@/store";

export const initWalletConect = async (wagmiConfig: Config) => {
const account = getAccount(wagmiConfig).address;

if (!account) {
await initWithoutConnect(wagmiConfig);
} else {
await initConnect(wagmiConfig);
}

watchAccount(wagmiConfig, {
onChange({ isConnected, isConnecting }) {
async onChange({ isConnected, isConnecting }) {
store.commit("setIsWalletCheckInProcess", true);

if (!isConnected && !isConnecting) {
initWithoutConnect(wagmiConfig);
await initWithoutConnect(wagmiConfig);
}

if (isConnected && !isConnecting) {
initConnect(wagmiConfig);
await initConnect(wagmiConfig);
}

store.commit("setIsWalletCheckInProcess", false);
},
});
store.commit("setIsWalletCheckInProcess", false);
};

const initConnect = async (wagmiConfig: Config) => {
Expand Down
8 changes: 4 additions & 4 deletions src/store/modules/connectProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
isMetamaskActive: false,
isCoinbase: false,
isWalletConnected: false,
walletCheckInProcess: true,
isWalletCheckInProcess: true,
wagmiConfig: null,
},
mutations: {
Expand Down Expand Up @@ -35,9 +35,8 @@ export default {
setMetamaskActive(state, payload) {
state.isMetamaskActive = payload;
},

SET_WALLET_CHECK_IN_PROCCESS(state, payload) {
state.walletCheckInProcess = payload;
setIsWalletCheckInProcess(state, payload) {
state.isWalletCheckInProcess = payload;
},
},
getters: {
Expand All @@ -47,6 +46,7 @@ export default {
getAccount: (state) => state.account,
getEnsName: (state) => state.ensName,
getWalletIsConnected: (state) => state.isWalletConnected,
getIsWalletCheckInProcess: (state) => state.isWalletCheckInProcess,
getMetamaskActive: (state) => state.isMetamaskActive,
},
};
1 change: 1 addition & 0 deletions src/views/MimSwap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export default {
this.actionConfig,
this.selectedNetwork,
this.chainId,
this.account,
this.isApproving
);
},
Expand Down
29 changes: 21 additions & 8 deletions src/views/MyPositions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@
/>
</div>

<div class="loader-wrap" v-if="positionsIsLoading || showEmptyBlock">
<BaseLoader v-if="positionsIsLoading" large text="Loading Positions" />
<BaseSearchEmpty
v-if="showEmptyBlock && account"
text="There are no Positions"
/>
<ConnectWalletBlock v-if="!account" />
<div
class="loader-wrap"
v-if="showConnectionBlock || showEmptyBlock || showLoader"
>
<ConnectWalletBlock v-if="showConnectionBlock" />
<BaseLoader v-if="showLoader" large text="Loading Positions" />
<BaseSearchEmpty v-if="showEmptyBlock" text="There are no Positions" />
</div>
</div>

Expand Down Expand Up @@ -111,6 +111,7 @@ export default {
computed: {
...mapGetters({
account: "getAccount",
isWalletCheckInProcess: "getIsWalletCheckInProcess",
chainId: "getChainId",
provider: "getProvider",
signer: "getSigner",
Expand All @@ -122,8 +123,18 @@ export default {
return this.selectedChains.length === this.activeChains.length;
},

showConnectionBlock() {
return !this.account;
},

showLoader() {
return (
this.account && (this.positionsIsLoading || this.isWalletCheckInProcess)
);
},

showEmptyBlock() {
return !this.positionsIsLoading && !this.sortedCauldrons.length;
return !this.showConnectionBlock && !this.showLoader;
},

sortedCauldrons() {
Expand Down Expand Up @@ -186,9 +197,11 @@ export default {
this.totalAssets = null;
this.userElixirInfo = null;
} else {
this.positionsIsLoading = true;
await this.getElixirInfo();
this.checkLocalData();
await this.createOpenPositions();
this.positionsIsLoading = false;
}
},

Expand Down
2 changes: 2 additions & 0 deletions src/views/PotionPoints.vue
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ export default {
...mapMutations({ deleteNotification: "notifications/delete" }),

async fetchUserInfo() {
if (!this.account) return;

this.fetching = true;
const publicClient = getPublicClient(ARBITRUM_CHAIN_ID);

Expand Down
Loading