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 asset icons (desktop mode) #25

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,50 @@ Build artifacts will be located at `dist` dir.

`Dockerfile` with `nginx.conf` are also provided. Based on [Deployment > Docker (nginx)](https://cli.vuejs.org/guide/deployment.html#docker-nginx).

## Development

### Setting up the `.env` file

You need a file with environment variables to configure Vite for the frontend to properly request either mock data or interact with the backend.

To enable the mocks, write:

```
VITE_FAKE_API_ENABLED=TRUE
```

To interact with the backend, assuming you'll add an API proxy as described below, write:

```
VITE_API_URL=http://localhost:5173/api-proxy
VITE_FAKE_API_ENABLED=FALSE
```

### Connecting to a BCE backend

One may want to see to see how the backend responds in the real time,
but pointing the API endpoint directly in the `VITE_API_URL` property of an `.env` file
would lead to a lot of errors like this one:

Access to fetch at 'http://localhost:port_A/...' from origin 'http://localhost:port_B' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Vite can be configured to proxy the responses.

So, we first return to the `.env` file and configure `VITE_API_URL` property as `http://localhost:5173/api-proxy`, if our `dev` shows the port as 5173.

Then we go to the Vite configuration in `vite.config.js` and add a new part in our `defineConfig` section,
where our `target` points to the host and the port of our BCE backend instance.

```js
server: {
proxy: {
'/api-proxy': {
target: 'http://127.0.0.1:4000',
changeOrigin: true,
secure: false,
ws: false,
rewrite: (path) => '/api/v1' + path.replace(/api-proxy\//, ''),
},
},
},
```
1 change: 1 addition & 0 deletions src/app/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ hr {

.cell {
padding: 0 size(2);
align-self: center;
}

.nowrap {
Expand Down
69 changes: 69 additions & 0 deletions src/entities/asset/AssetIcon.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<template>
<div class="asset">
<div class="asset__icon">
<XOR v-if="nameLower=='xor'" />
<VAL v-else-if="nameLower=='val'" />
<ETH v-else-if="nameLower=='eth'" />
<IrohaIcon v-else-if="nameLower=='iroha'" />
<Soshiba v-else-if="nameLower=='soshiba'" />
<Pswap v-else-if="nameLower=='pswap'" />
<NaIcon v-else />
Comment on lines +4 to +10
Copy link
Contributor

Choose a reason for hiding this comment

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

Written in JS, it could be less verbose:

const ICONS = {
  xor: XOR,
  // ...
}

const Icon = computed(() => ICONS[nameLower.value] ?? NaIcon)
<template>
  <component :is="Icon" />
</template>

</div>
</div>
</template>

<script setup lang="ts">
import { toRefs } from 'vue';

import XOR from '~icons/assets/XOR.svg';
import VAL from '~icons/assets/VAL.svg';
import ETH from '~icons/assets/ETH.svg';
import IrohaIcon from '~icons/assets/iroha_icon.svg';
import Soshiba from '~icons/assets/soshiba.svg';
import Pswap from '~icons/assets/pswap.svg';
import NaIcon from '~icons/assets/na.svg';
Comment on lines +18 to +24
Copy link
Contributor

Choose a reason for hiding this comment

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

It might make sense to import these icons lazily, as dynamic imports. Also you can leverage globs to reduce boilerplate.


const props = defineProps({
name: {
type: String,
default: '',
},
});

const { name } = toRefs(props);

let nameLower = '';

const init = async () => {
nameLower = name.value.toLowerCase();
};

init();
Comment on lines +33 to +41
Copy link
Contributor

Choose a reason for hiding this comment

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

That is not how we write Vue applications )

That's how:

import { computed } from 'vue'

const nameLower = computed(() => props.name.toLowerCase())

Please read the Computed Properties section (with enabled "Composition" toggle).

</script>

<style lang="scss">
@import 'styles';

.asset {
position: relative;
display: grid;
grid-gap: size(1);
align-items: center;
grid-auto-flow: column;
grid-auto-columns: auto;
Comment on lines +49 to +53
Copy link
Contributor

Choose a reason for hiding this comment

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

.asset div has the only one element inside. grid-auto-flow, grid-auto-columns and grip-gap are useless.


&__icon {
width: size(4);
height: size(4);
border-radius: 50%;
Copy link
Contributor

Choose a reason for hiding this comment

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

border-radius: 50% might produce an oval shape if width is not equal to height. Consider using an absolute value (e.g. 99px) for the best result.

display: flex;
align-items: center;
justify-content: center;

svg {
width: size(4);
height: size(4);
}
}
}
</style>
9 changes: 8 additions & 1 deletion src/pages/AssetsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
>
<template #header>
<div class="assets-list-page__row">
<span class="h-sm cell">{{ $t('icon') }}</span>
<span class="h-sm cell">{{ $t('name') }}</span>
<span class="h-sm cell">{{ $t('domain') }}</span>
<span class="h-sm cell">{{ $t('total') }}</span>
Expand All @@ -20,6 +21,10 @@

<template #row="{ item }: { item: Asset }">
<div class="assets-list-page__row">
<div class="cell row-text">
<AssetIcon :name="item.definition_id.split('#')[0]" />
</div>

<BaseLink :to="`/assets/${item.definition_id}`" class="cell">
{{ item.definition_id.split('#')[0] }}
</BaseLink>
Expand Down Expand Up @@ -74,6 +79,8 @@ import BaseLink from '~base/BaseLink.vue';
import { useTable } from '~shared/lib/table';
import { http } from '~shared/api';

import AssetIcon from '~entities/asset/AssetIcon.vue';

const table = useTable(http.fetchAssets);
table.fetch();
</script>
Expand All @@ -85,7 +92,7 @@ table.fetch();
&__row {
width: 100%;
display: grid;
grid-template-columns: 2fr 2fr 1fr;
grid-template-columns: 0.25fr 2fr 2fr 1fr;
justify-content: start;
}

Expand Down
3 changes: 2 additions & 1 deletion src/shared/lib/localization/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,6 @@
"mostValue": "Most Value",
"wasm": "WebAssembly",
"instruction": "Instruction"
}
},
"icon": "Icon"
}
1 change: 1 addition & 0 deletions src/shared/ui/icons/assets/ETH.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/shared/ui/icons/assets/VAL.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/shared/ui/icons/assets/XOR.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/shared/ui/icons/assets/iroha_icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/shared/ui/icons/assets/na.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/shared/ui/icons/assets/pswap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading