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

Feature add third #206

Merged
merged 3 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions components/common/input/TransactionWithdraw.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:loading="loading"
:tokens="tokens"
:balances="balances"
:title="from==='withdraw'? 'Choose chain and token':''"
>
<template #body-bottom v-if="$slots['token-dropdown-bottom']">
<slot name="token-dropdown-bottom" />
Expand Down Expand Up @@ -155,6 +156,10 @@ const props = defineProps({
type: String,
default: "Amount",
},
from: {
type: String,
default: "",
},
tokens: {
type: Array as PropType<Token[]>,
default: () => [],
Expand Down
127 changes: 121 additions & 6 deletions components/token/TokenSelectModal.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<template>
<CommonModal v-model:opened="isModalOpened" class="token-select-modal" :title="title" @after-leave="search = ''">
<CommonModal v-model:opened="isModalOpened" class="token-select-modal" :class="{ 'token-modal': title === 'Choose chain and token' }" :title="title" @after-leave="search = ''">
<div v-if="title === 'Choose chain and token'" class="mb-4">
<div class="flex gap-2 flex-wrap">
<div v-for="(group, groupIndex) in arr" :key="groupIndex" class="chainBox cursor-pointer" :class="{'active': selectChain === group.key}"
@click="buttonClicked(zkSyncNetwork.find(item => item.key === group.key)!);">
<img :src="group.iconUrl" :alt="group.label"/>
</div>
</div>
<p v-if="!arr.length" class="mt-block-padding-1/2 text-center">No chains found</p>
</div>
<Combobox v-model="selectedToken">
<!-- TODO: Refactor this to use ComboboxInput as main component but look like CommonInputSearch -->
<CommonInputSearch
Expand All @@ -12,7 +21,7 @@
<MagnifyingGlassIcon aria-hidden="true" />
</template>
</CommonInputSearch>
<div class="-mx-block-padding-1/2 h-full overflow-auto px-block-padding-1/2">
<div class="-mx-block-padding-1/2 md:h-[18rem] h-[15rem] overflow-auto px-block-padding-1/2">
<template v-if="loading">
<div class="-mx-block-padding-1/2">
<TokenBalanceLoader v-for="index in 2" variant="light" :key="index" />
Expand Down Expand Up @@ -46,7 +55,7 @@
size="sm"
variant="light"
:key="item.address"
@click="selectedToken = item"
@click="changeToken(item)"
/>
</div>
</div>
Expand All @@ -68,7 +77,7 @@
</template>

<script lang="ts" setup>
import { computed, ref } from "vue";
import { computed, ref, watch } from "vue";

import { Combobox } from "@headlessui/vue";
import { MagnifyingGlassIcon } from "@heroicons/vue/24/outline";
Expand All @@ -85,7 +94,27 @@ import { useSearchtokenStore } from "@/store/searchToken";
import { useZkSyncEthereumBalanceStore } from "@/store/zksync/ethereumBalance";
import { groupBalancesByAmount } from "@/utils/mappers";
import { ETH_ADDRESS, fetchErc20, L2_ETH_TOKEN_ADDRESS } from "~/zksync-web3-nova/src/utils";
import useNetworks from "@/composables/useNetworks";
import type { ZkSyncNetwork } from "@/data/networks";
import { useZkSyncWalletStore } from "@/store/zksync/wallet";
import { useZkSyncProviderStore } from "@/store/zksync/provider";
import { useRoute } from "#app";
const route = useRoute();
const providerStore = useZkSyncProviderStore();
const { zkSyncNetworks } = useNetworks();

const walletStore = useZkSyncWalletStore();
const { balance, balanceInProgress, balanceError } = storeToRefs(walletStore);
const zkSyncNetwork = zkSyncNetworks.filter((e) => !e.hidden)
let arr : any[] = [];
zkSyncNetwork.map((i)=> {
const obj = {
iconUrl: i.logoUrl,
key: i.key,
label: i.l1Network?.name,
};
arr.push(obj);
});
const props = defineProps({
title: {
type: String,
Expand Down Expand Up @@ -123,6 +152,19 @@ const { selectedNetwork } = storeToRefs(useNetworkStore());
const zkSyncEthereumBalance = useZkSyncEthereumBalanceStore();

const search = ref("");
const searchList = ref<any[]>([]);
watch(
() => search.value,
(value) => {
if (chainList.value.length >0) {
searchList.value = filterTokens(
chainList.value
) as TokenAmount[]
balanceGroups = groupBalancesByAmount(searchList)
}
},
);
const selectChain = ref(selectedNetwork.value.key)
const showLoading = ref(false);
const hasBalances = computed(() => props.balances.length > 0);
const onboardStore = useOnboardStore();
Expand Down Expand Up @@ -160,7 +202,49 @@ const filterTokens = (tokens: Token[]) => {
}
return newTokens;
};

const changeToken = (item:any) => {
console.log(item)
selectedToken.value = item
if (selectChain.value === selectedNetwork.value.key) {
return;
}
const url = new URL(route.fullPath, window.location.origin);
url.searchParams.set("network", selectChain.value);
url.searchParams.set("tokenAddress", item.address);
window.location.href = url.toString();
}
const isNetworkSelected = (network: ZkSyncNetwork) => selectChain.value === network.key;
const chainLists = ref<any[]>([]);
const chainList = ref<any[]>([]);
const buttonClicked = async (network: ZkSyncNetwork) => {
if (isNetworkSelected(network)) {
return;
}
selectChain.value = network.key;
chainLists.value = balance.value.filter((e) => {
if (isSupportedMergeToken(e.address, network.key)) {
return true;
}
if (!e.l1Address) {
return false;
}
if (e.l1Address === ETH_ADDRESS) {
return true;
}
if (e.networkKey === network.key) {
return true;
}
return false;
});
chainList.value = filterTokens(
chainLists.value.filter(
(e) =>
network.isEthGasToken ||
(e.address !== ETH_ADDRESS && e.address.toLowerCase() !== L2_ETH_TOKEN_ADDRESS)
)
) as TokenAmount[]
balanceGroups = groupBalancesByAmount(chainList)
};
const displayedTokens = computed(() =>
filterTokens(
props.tokens.filter(
Expand All @@ -180,7 +264,7 @@ const displayedBalances = computed(
)
) as TokenAmount[]
);
const balanceGroups = groupBalancesByAmount(displayedBalances);
let balanceGroups = groupBalancesByAmount(displayedBalances);
const selectedTokenAddress = computed({
get: () => props.tokenAddress,
set: (value) => emit("update:tokenAddress", value),
Expand Down Expand Up @@ -225,4 +309,35 @@ const closeModal = () => {
@apply pt-0;
}
}
.token-modal {
.modal-card {
@apply block h-full grid-rows-[max-content_max-content_1fr];
}
.category:first-child .group-category-label {
@apply pt-0;
}
}
.chainBox{
display: flex;
width: 75.7px;
height: 64px;
padding: 12px 18px 12px 18px;
justify-content: center;
align-items: center;
border-radius: 8px;
background: #3D424D;
img{
border-radius: 50%;
width: 40px;
}
}
.chainBox:hover{
border-radius: 8px;
background: rgba(23, 85, 244, 0.25);
}
.active{
border-radius: 8px;
background: rgba(23, 85, 244, 0.25);
border: 2px solid #1755F4;
}
</style>
1 change: 1 addition & 0 deletions views/transactions/Deposit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
v-model:error="amountError"
v-model:token-address="amountInputTokenAddress"
label="From"
:from="'deposit'"
:tokens="availableTokens"
:balances="availableBalances"
:max-amount="maxAmount"
Expand Down
4 changes: 2 additions & 2 deletions views/transactions/Withdraw.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
v-model:error="amountError"
v-model:token-address="amountInputTokenAddress"
:label="type === 'withdrawal' ? 'From' : undefined"
:from="'withdraw'"
:tokens="availableTokens"
:balances="availableBalances"
:max-amount="maxAmount"
Expand Down Expand Up @@ -584,7 +585,6 @@ const props = defineProps({
const { selectedNetwork } = storeToRefs(useNetworkStore());
const route = useRoute();
const router = useRouter();

const onboardStore = useOnboardStore();
const walletStore = useZkSyncWalletStore();
const tokensStore = useZkSyncTokensStore();
Expand Down Expand Up @@ -671,7 +671,7 @@ const tokenWithHighestBalancePrice = computed(() => {
});
const defaultToken = computed(() => availableTokens.value?.[0] ?? undefined);
const selectedTokenAddress = ref<string | undefined>(
routeTokenAddress.value ?? tokenWithHighestBalancePrice.value?.address ?? defaultToken.value?.address
route.query.tokenAddress ?? routeTokenAddress.value ?? tokenWithHighestBalancePrice.value?.address ?? defaultToken.value?.address
);
const selectedToken = computed<Token | undefined>(() => {
if (!tokens.value) {
Expand Down
Loading