Skip to content

Commit

Permalink
♻️ Refactoring Chains config (#227)
Browse files Browse the repository at this point in the history
* added new chains config

* refactoring plugin connectWallet

* refactoring swaichNetwork

* replaced getChainInfo by getChainById

* updated chains configs

* refactoring networks store

* delete connectWalletV2

* moved getChainById to store

* moved chainId to networks store

* updated beam chains config

* deleted unused files

---------

Co-authored-by: Andrey <[email protected]>
  • Loading branch information
Andrey-Onipchenko and Onipchenko-Andrey authored Oct 16, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 4a61ba5 commit be97128
Showing 41 changed files with 358 additions and 715 deletions.
16 changes: 4 additions & 12 deletions src/components/app/AppHeader.vue
Original file line number Diff line number Diff line change
@@ -188,7 +188,7 @@
<NetworkPopup
:isOpen="isOpenNetworkPopup"
@closePopup="closeNetworkPopup"
:networksArr="popupNetworksArr"
:networksArr="networksArr"
:activeChain="chainId"
/>

@@ -223,18 +223,10 @@ export default {
networksArr: "getAvailableNetworks",
}),
popupNetworksArr() {
return this.networksArr.map((chain) => {
if (chain?.title) return chain;
chain.title = chain.name;
return chain;
});
},
networcIcon() {
if (!this.chainId) return "";
if (this.popupNetworksArr.length && this.chainId) {
const chain = this.popupNetworksArr.find((chain) => {
if (this.networksArr.length && this.chainId) {
const chain = this.networksArr.find((chain) => {
if (chain.chainId === this.chainId) return chain;
});
@@ -245,7 +237,7 @@ export default {
},
isUnsupportedChain() {
const chain = this.popupNetworksArr.find((chain) => {
const chain = this.networksArr.find((chain) => {
if (chain.chainId === this.chainId) return chain;
});
11 changes: 7 additions & 4 deletions src/components/beam/successPopup/SendFromBlock.vue
Original file line number Diff line number Diff line change
@@ -64,9 +64,9 @@
</template>

<script>
import { mapGetters } from "vuex";
import filters from "@/filters/index.js";
import { useImage } from "@/helpers/useImage";
import { getChainInfo } from "@/helpers/chain/getChainInfo.ts";
import ExplorerLink from "@/components/beam/successPopup/ExplorerLink.vue";
export default {
props: {
@@ -77,11 +77,14 @@ export default {
},
computed: {
...mapGetters({ getChainById: "getChainById" }),
fromScanUrl() {
if (!this.config.tx?.hash) return "";
return `${getChainInfo(this.config.originChain.chainId).scanUrl}${
this.config.tx.hash
}`;
return `${
this.getChainById(this.config.originChain.chainId).blockExplorers
.etherscan.url
}/tx/${this.config.tx.hash}`;
},
sendFromCheck() {
8 changes: 6 additions & 2 deletions src/components/beam/successPopup/SendToBlock.vue
Original file line number Diff line number Diff line change
@@ -46,9 +46,9 @@
</template>

<script>
import { mapGetters } from "vuex";
import filters from "@/filters/index.js";
import { useImage } from "@/helpers/useImage";
import { getChainInfo } from "@/helpers/chain/getChainInfo.ts";
import ExplorerLink from "@/components/beam/successPopup/ExplorerLink.vue";
export default {
props: {
@@ -59,6 +59,8 @@ export default {
},
computed: {
...mapGetters({ getChainById: "getChainById" }),
sendToCheck() {
if (this.dstScanUrl) return useImage("assets/images/beam/complete.png");
return useImage("assets/images/beam/check.png");
@@ -73,7 +75,9 @@ export default {
dstScanUrl() {
const { txInfo, dstChain } = this.config;
if (!txInfo || txInfo?.status === "INFLIGHT") return "";
return `${getChainInfo(dstChain.chainId).scanUrl}${txInfo.dstTxHash}`;
return `${
this.getChainById(dstChain.chainId).blockExplorers.etherscan.url
}/tx/${txInfo.dstTxHash}`;
},
destinationTokenUsd() {
11 changes: 5 additions & 6 deletions src/components/borrow/BalanceBlock.vue
Original file line number Diff line number Diff line change
@@ -60,12 +60,11 @@
</template>

<script>
import { mapGetters } from "vuex";
import { utils } from "ethers";
import { mapGetters } from "vuex";
import filters from "@/filters/index.js";
import { useImage } from "@/helpers/useImage";
import { getChainInfo } from "@/helpers/chain/getChainInfo.ts";
import { defineAsyncComponent } from "vue";
import { useImage } from "@/helpers/useImage";
import { ONE_ETHER } from "@/constants/global";
export default {
props: {
@@ -82,16 +81,16 @@ export default {
},
computed: {
...mapGetters({ chainId: "getChainId" }),
...mapGetters({ chainId: "getChainId", getChainById: "getChainById" }),
nativeTokenInfo() {
const { acceptUseDefaultBalance } = this.cauldron.config.cauldronSettings;
if (!acceptUseDefaultBalance) return null;
const { nativeTokenBalance } = this.cauldron.userTokensInfo;
const { symbol, icon } = getChainInfo(this.chainId);
const { symbol, baseTokenIcon } = this.getChainById(this.chainId);
const balance = utils.formatUnits(nativeTokenBalance);
return { name: symbol, icon, balance };
return { name: symbol, icon: baseTokenIcon, balance };
},
mimInfo() {
3 changes: 0 additions & 3 deletions src/components/markets/CauldronItem.test.ts
Original file line number Diff line number Diff line change
@@ -47,9 +47,6 @@ const store = new Vuex.Store({
state: {
chainIcon: useImage("assets/images/networks/arbitrum-icon.svg"),
},
getters: {
getChainIcon: (state) => (chainId: number) => state.chainIcon,
},
},
},
});
10 changes: 7 additions & 3 deletions src/components/markets/CauldronItem.vue
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
<div class="cauldron-info">
<div class="chain-info">
<p class="chain-title">Chain</p>
<BaseTokenIcon :icon="getChainIcon(chainId)" size="26px" />
<BaseTokenIcon :icon="chainIcon" size="26px" />
</div>

<div class="collateral-info">
@@ -41,9 +41,9 @@
</template>

<script>
import filters from "@/filters/index.js";
import { utils } from "ethers";
import { mapGetters } from "vuex";
import filters from "@/filters/index.js";
import BaseTokenIcon from "@/components/base/BaseTokenIcon.vue";
export default {
@@ -54,7 +54,11 @@ export default {
},
computed: {
...mapGetters({ chainId: "getChainId", getChainIcon: "getChainIcon" }),
...mapGetters({ chainId: "getChainId", getChainById: "getChainById" }),
chainIcon() {
return this.getChainById(this.chainId).icon;
},
goToCauldron() {
const name = this.isDeprecatedCauldron ? "RepayId" : "BorrowId";
33 changes: 4 additions & 29 deletions src/components/markets/FarmItem.vue
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
<div class="stats-wrap">
<div>
<p class="chain-title">CHAIN</p>
<img class="chain-icon" :src="getChainIcon" alt="Chain icon" />
<img class="chain-icon" :src="chainIcon" alt="Chain icon" />
</div>

<div class="farm-info">
@@ -35,7 +35,6 @@
import { mapGetters } from "vuex";
import filters from "@/filters/index.js";
import BaseTokenIcon from "@/components/base/BaseTokenIcon.vue";
import { useImage } from "@/helpers/useImage";
export default {
props: {
@@ -45,7 +44,7 @@ export default {
},
computed: {
...mapGetters({ chainId: "getChainId" }),
...mapGetters({ chainId: "getChainId", getChainById: "getChainById" }),
goToPage() {
return { name: "Farm", params: { id: this.farm.id } };
@@ -61,32 +60,8 @@ export default {
];
},
getChainIcon() {
if (this.chainId === 56) {
return useImage("assets/images/networks/BNB.svg");
}
if (this.chainId === 250) {
return useImage("assets/images/networks/fantom-icon.svg");
}
if (this.chainId === 43114) {
return useImage("assets/images/networks/avalanche-icon.png");
}
if (this.chainId === 137) {
return useImage("assets/images/networks/polygon-icon.svg");
}
if (this.chainId === 42161) {
return useImage("assets/images/networks/Arbitrum.svg");
}
if (this.chainId === 10) {
return useImage("assets/images/networks/optimism-icon.svg");
}
return useImage("assets/images/networks/ethereum-icon.svg");
chainIcon() {
return this.getChainById(this.chainId).icon;
},
},
4 changes: 2 additions & 2 deletions src/components/popups/NetworkPopup.vue
Original file line number Diff line number Diff line change
@@ -17,15 +17,15 @@
@click="switchHandler(network.chainId)"
>
<img class="network-image" :src="network.icon" alt="network" />
<span>{{ network.title }}</span>
<span>{{ network.symbol }}</span>
</button>
</div>
</div>
</div>
</template>

<script>
import switchNetwork from "@/helpers/switchNetwork";
import { switchNetwork } from "@/helpers/chains/switchNetwork";
export default {
props: {
6 changes: 3 additions & 3 deletions src/components/ui/NetworksList.vue
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
v-for="network in activeNetworks"
:key="network.chainId"
:selected="network.chainId === chainId"
:name="network.name"
:name="network.symbol"
:icon="network.icon"
:disabled="loading"
@click="changeNetwork(network.chainId)"
@@ -36,7 +36,7 @@
<script>
import { mapGetters } from "vuex";
import NetworkChip from "@/components/ui/NetworkChip.vue";
import switchNetwork from "@/helpers/switchNetwork";
import { switchNetwork } from "@/helpers/chains/switchNetwork";
export default {
name: "NetworksList",
@@ -59,7 +59,7 @@ export default {
try {
await switchNetwork(chainId);
} catch (error) {
console.log(error)
console.log("Switch Network Error", error);
} finally {
this.loading = false;
}
4 changes: 2 additions & 2 deletions src/components/ui/checkboxes/UseCheckbox.vue
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@
<script>
import { mapGetters } from "vuex";
import { useImage } from "@/helpers/useImage";
import { getChainInfo } from "@/helpers/chain/getChainInfo.ts";
export default {
props: {
config: {
@@ -31,6 +30,7 @@ export default {
computed: {
...mapGetters({
chainId: "getChainId",
getChainById: "getChainById",
}),
isVisibility() {
@@ -48,7 +48,7 @@ export default {
tokenSymbol() {
if (this.config?.cauldronSettings?.acceptUseDefaultBalance)
return getChainInfo(this.chainId).symbol;
return this.getChainById(this.chainId).symbol;
return this.config.collateralInfo.name;
},
},
3 changes: 3 additions & 0 deletions src/constants/chains.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const MAINNET_RPC_URLS: string[] = [
"https://mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161",
];
4 changes: 4 additions & 0 deletions src/constants/tokensAddress.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
import type { Address } from "viem";

export const MAINNET_SPELL_ADDRESS: string =
"0x090185f2135308BaD17527004364eBcC2D37e5F6";
export const SANCTIONS_LIST_ADDRESS: Address =
"0x40c57923924b5c5c5455c48d93317139addac8fb";
17 changes: 9 additions & 8 deletions src/helpers/beam/createBeamConfig.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BigNumber, Contract, providers, utils } from "ethers";
import mimConfigs from "@/utils/contracts/mimToken";
import chainConfig from "@/utils/beam/chainConfig";
import beamConfigs from "@/utils/beam/beamConfigs";
import { markRaw } from "vue";
import beamConfigs from "@/utils/beam/beamConfigs";
import mimConfigs from "@/utils/contracts/mimToken";
import { chains, chainsList } from "@/helpers/chains";
import { BigNumber, Contract, providers, utils } from "ethers";
import type { BeamConfig, UserInfo } from "@/helpers/beam/types";

const emptyState = {
@@ -47,22 +47,23 @@ export const createBeamConfig = async (
const beamConfig = beamConfigs.find((item) => item.chainId === chainId);

const fromChains = beamConfigs.map((configItem) => {
const { chainId } = configItem;
return {
chainId: configItem.chainId,
title: configItem.chainName,
icon: configItem.chainIcon,
icon: chainsList[chainId as keyof typeof chainsList].networkIcon,
defaultValue: configItem.defaultValue,
};
});

const chainsInfo = chainConfig.filter((chain) => chain.chainId !== chainId);
const chainsInfo = chains.filter((chain) => chain.chainId !== chainId);

const toChains = chainsInfo.map((chainItem) => {
return {
chainId: chainItem.chainId,
lzChainId: chainItem.lzChainId,
title: chainItem.name,
icon: chainItem.icon,
title: chainItem.symbol,
icon: chainItem.networkIcon,
};
});

Loading

1 comment on commit be97128

@vercel
Copy link

@vercel vercel bot commented on be97128 Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.