Skip to content

Commit

Permalink
feat: add lables for bridged and native tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
kiriyaga committed Dec 16, 2024
1 parent 38a05a3 commit f36000f
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 9 deletions.
33 changes: 27 additions & 6 deletions packages/app/src/components/TokenIconLabel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,22 @@
/>
</div>
</AddressLink>
<div class="token-info" v-if="name && symbol">
<div class="token-symbol">
{{ symbol }}
</div>
<div class="token-name">
{{ name }}
<div class="token-info-container">
<div class="token-info" v-if="name && symbol">
<div class="token-symbol">
{{ symbol }}
</div>
<div class="token-name">
{{ name }}
</div>
<div style="display: flex; gap: 0.5rem">
<Badge v-if="bridged" color="primary" class="verified-badge" :tooltip="t('tokensView.table.bridged.tooltip')">
{{ t("tokensView.table.bridged.title") }}
</Badge>
<Badge v-else color="progress" class="verified-badge" :tooltip="t('tokensView.table.native.tooltip')">
{{ t("tokensView.table.native.title") }}
</Badge>
</div>
</div>
</div>
</div>
Expand All @@ -34,6 +44,7 @@ import { useI18n } from "vue-i18n";
import { useImage } from "@vueuse/core";
import AddressLink from "@/components/AddressLink.vue";
import Badge from "@/components/common/Badge.vue";
import type { Hash } from "@/types";
Expand Down Expand Up @@ -66,6 +77,10 @@ const props = defineProps({
type: String,
default: "",
},
bridged: {
type: Boolean,
default: false,
},
});
const imgSource = computed(() => {
Expand Down Expand Up @@ -115,6 +130,12 @@ const { isReady: isImageLoaded } = useImage({ src: imgSource.value });
}
}
}
.token-info-container {
display: flex;
justify-content: center;
align-items: center;
gap: 1rem;
}
.token-info {
.token-symbol {
@apply text-neutral-600;
Expand Down
1 change: 1 addition & 0 deletions packages/app/src/components/token/TokenListTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
:address="item.l2Address"
:name="item.name"
:icon-url="item.iconURL"
:bridged="item.l1Address ? true : false"
/>
</TableBodyColumn>
<TableBodyColumn :data-heading="t('tokensView.table.price')">
Expand Down
10 changes: 9 additions & 1 deletion packages/app/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,15 @@
"table": {
"tokenName": "Token Name",
"price": "Price",
"tokenAddress": "Token Address"
"tokenAddress": "Token Address",
"bridged": {
"title": "Default bridge",
"tooltip": "This token is bridged from L1 to ZKsync Era"
},
"native": {
"title": "L2-native",
"tooltip": "This token is native to ZKsync Era"
}
}
},
"pageError": {
Expand Down
10 changes: 9 additions & 1 deletion packages/app/src/locales/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,15 @@
"table": {
"tokenName": "Назва Токена",
"price": "Ціна",
"tokenAddress": "Адреса Токена"
"tokenAddress": "Адреса Токена",
"bridged": {
"title": "Бридж",
"tooltip": "Цей токен перенесений з L1 до ZKsync Era"
},
"native": {
"title": "L2-нативний",
"tooltip": "Цей токен є нативним для ZKsync Era"
}
}
},
"timeMessages": {
Expand Down
39 changes: 38 additions & 1 deletion packages/app/tests/components/token/TokenListTable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe("TokenListTable:", () => {
en: enUS,
},
});
it("renders properly", async () => {
it("renders properly with bridged token", async () => {
const { getTokenInfo } = useToken();
const wrapper = mount(TokenListTable, {
props: {
Expand Down Expand Up @@ -75,6 +75,43 @@ describe("TokenListTable:", () => {
expect(tr0Arr[0].find(".token-symbol").text()).toBe("ETH");
expect(tr0Arr[0].find(".token-name").text()).toBe("Ether");
expect(tr0Arr[0].find(".token-icon-label img").attributes("src")).toBe("https://icon.com");
expect(tr0Arr[0].find(".verified-badge").text()).toBe("Default bridge");
expect(tr0Arr[1].text()).toBe("$150.00");
expect(tr0Arr[2].text()).toBe("L20xEeeeeEeeeEeE...EEeE");
});

it("renders properly with native token", async () => {
const { getTokenInfo } = useToken();
const wrapper = mount(TokenListTable, {
props: {
tokens: [
{
decimals: 18,
iconURL: "https://icon.com",
l2Address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
name: "Ether",
symbol: "ETH",
} as Token,
],
loading: false,
},
global: {
stubs: {
RouterLink: RouterLinkStub,
},
plugins: [i18n, $testId],
},
});
await getTokenInfo("0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE");
await nextTick();
const trArr = wrapper.findAll("tbody tr");
expect(trArr.length).toBe(1);
const tr0Arr = trArr[0].findAll(".table-body-col");
expect(tr0Arr.length).toBe(3);
expect(tr0Arr[0].find(".token-symbol").text()).toBe("ETH");
expect(tr0Arr[0].find(".token-name").text()).toBe("Ether");
expect(tr0Arr[0].find(".token-icon-label img").attributes("src")).toBe("https://icon.com");
expect(tr0Arr[0].find(".verified-badge").text()).toBe("L2-native");
expect(tr0Arr[1].text()).toBe("$150.00");
expect(tr0Arr[2].text()).toBe("L20xEeeeeEeeeEeE...EEeE");
});
Expand Down

0 comments on commit f36000f

Please sign in to comment.