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

PSS-74 Swap Interface Integration #26

Merged
merged 28 commits into from
Dec 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ee86887
Hid swap info for not connected wallet.
alexnatalia Dec 15, 2020
45a64a0
Updated SelectToken search by name, added check for translation exist…
alexnatalia Dec 15, 2020
23fd15c
Merge branch 'develop' into feature/pss-74-swap-interface-integration
alexnatalia Dec 15, 2020
7c587ad
Added Swap Integration Draft.
alexnatalia Dec 16, 2020
abf5daf
Refactored formatNumber calls, updated Swap integration calls.
alexnatalia Dec 16, 2020
fcf2552
Hid swap info under buttons for zero amount. Added TODOs.
alexnatalia Dec 18, 2020
5bcfc13
Merge branch 'develop' into feature/pss-74-swap-interface-integration
alexnatalia Dec 18, 2020
3d907dc
Fixed Header Menu colors.
alexnatalia Dec 19, 2020
125b796
Updated Swap Integration.
alexnatalia Dec 21, 2020
52eb6f4
Removed reversed flag from getSwapResult and getMinMaxReceived calls,…
alexnatalia Dec 21, 2020
9521341
Updated tooltips.
alexnatalia Dec 21, 2020
4b57c71
Updated About page text and Main menu links order.
alexnatalia Dec 21, 2020
0eeab8c
Updated Price and Price reverced values in price area.
alexnatalia Dec 22, 2020
9e8e61a
Updated Default token setting.
alexnatalia Dec 22, 2020
46c7038
Updated Wallet version.
alexnatalia Dec 22, 2020
0034ecd
Updated Swap Integration math.
alexnatalia Dec 22, 2020
4f22502
Hid Transaction Deadline area for Settings.
alexnatalia Dec 22, 2020
91f9413
Added validation for Settings.
alexnatalia Dec 22, 2020
5c5f6d9
Added validation for Settings.
alexnatalia Dec 22, 2020
58e64e1
Added validation for Insufficient Amount error from server.
alexnatalia Dec 22, 2020
474f83c
Set default token for connected mode.
alexnatalia Dec 23, 2020
cfe46f4
Removed unneeded tooltip from Settings dialog.
alexnatalia Dec 23, 2020
a6595e7
Fixed Card title color for About page.
alexnatalia Dec 23, 2020
938ceca
Added loading while not conencted, changed store to not strict mode, …
alexnatalia Dec 23, 2020
6ebc615
Fixed focused behaviour for Swap input fields.
alexnatalia Dec 23, 2020
fb1809d
Fix wallet connection & select token behavior
stefashkaa Dec 23, 2020
2287f4b
Fixed Min Received format.
alexnatalia Dec 23, 2020
f6f58ca
Merge branch 'feature/pss-74-swap-interface-integration' of https://g…
alexnatalia Dec 23, 2020
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"dependencies": {
"@soramitsu/soramitsu-js-ui": "^0.6.7",
"@soramitsu/soraneo-wallet-web": "^0.2.7",
"@soramitsu/soraneo-wallet-web": "^0.2.9",
"axios": "^0.19.2",
"bignumber.js": "^9.0.1",
"core-js": "^3.6.4",
Expand Down
8 changes: 5 additions & 3 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@
{{ t(`mainMenu.${item}`) }}
</s-menu-item>
</s-menu>
<s-button class="polkaswap-logo" type="link" @click="goTo(PageNames.About)" />
<s-button class="polkaswap-logo" type="link" @click="goTo(PageNames.Exchange)" />
<div class="buttons">
<s-button class="wallet" type="action" icon="wallet" rounded :disabled="loading" @click="goTo(PageNames.Wallet)" />
<s-button type="action" icon="settings" rounded @click="openSettingsDialog" />
<!-- TODO: The button is hidden because we don't have a Search page right now -->
<!-- <s-button type="action" icon="search" rounded /> -->
</div>
</header>
<div class="app-content"><router-view /></div>
<div class="app-content">
<!-- TODO 4 alexnatalia: We should have this loader only for appropriate pages. Play with it a bit more -->
<router-view v-loading="loading" />
</div>
<settings :visible.sync="showSettings" />
</div>
</template>
Expand Down Expand Up @@ -235,7 +238,6 @@ $menu-height: 65px;
font-size: var(--s-heading4-font-size);
letter-spacing: $s-letter-spacing-small;
font-feature-settings: $s-font-feature-settings-title;
&,
&.is-active:hover {
color: var(--s-color-theme-accent-hover) !important;
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/ConfirmRemoveLiquidity.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ export default class ConfirmSwap extends Mixins(TranslationMixin, DialogMixin) {
formatNumber = formatNumber

get formattedFromValue (): string {
return formatNumber(this.firstTokenAmount, 4)
return formatNumber(this.firstTokenAmount)
}

get formattedToValue (): string {
return formatNumber(this.secondTokenAmount, 4)
return formatNumber(this.secondTokenAmount)
}

get formattedLiquidityValue (): string {
return formatNumber(this.liquidityAmount, 4)
return formatNumber(this.liquidityAmount)
}

handleConfirmRemoveLiquidity (): void {
Expand Down
5 changes: 3 additions & 2 deletions src/components/ConfirmSwap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import DialogBase from '@/components/DialogBase.vue'
import { formatNumber } from '@/utils'
import { lazyComponent } from '@/router'
import { Components } from '@/consts'
import { dexApi } from '@soramitsu/soraneo-wallet-web'

@Component({
components: {
Expand All @@ -56,11 +57,11 @@ export default class ConfirmSwap extends Mixins(TranslationMixin, DialogMixin) {
@Getter toValue!: number

get formattedFromValue (): string {
return formatNumber(this.fromValue, 4)
return formatNumber(this.fromValue)
}

get formattedToValue (): string {
return formatNumber(this.toValue, 4)
return formatNumber(this.toValue)
}

handleConfirmSwap (): void {
Expand Down
5 changes: 3 additions & 2 deletions src/components/Pool.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<template>
<div class="el-form--pool">
<!-- TODO: Add appropriate tooltip -->
<generic-header class="header--pool" :has-button-back="false" :title="t('pool.yourLiquidity')" :tooltip="t('pool.loremIpsum')" />
<generic-header class="header--pool" :has-button-back="false" :title="t('pool.yourLiquidity')" :tooltip="t('pool.description')" />
<p v-if="!connected" class="pool-info-container">
{{ t('pool.connectToWallet') }}
</p>
<p v-else-if="!liquidities || !liquidities.length" class="pool-info-container">
{{ t('pool.liquidityNotFound') }}
</p>
<!-- TODO 4 alexnatalia: Whole pool area should be clickable -->
<s-collapse v-else class="pool-list" :borders="true">
<s-collapse-item v-for="liquidity of liquidities" :key="liquidity.id" :name="liquidity.id" class="pool-info-container">
<template #title>
Expand Down Expand Up @@ -83,7 +84,7 @@ export default class Pool extends Mixins(TranslationMixin) {

get pairValue (): string {
// TODO: Play with Pair value
return formatNumber(10.00000171, 4)
return formatNumber(10.00000171)
}

handleAddLiquidity (): void {
Expand Down
34 changes: 18 additions & 16 deletions src/components/SelectToken.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,8 @@
<s-col>
<s-row flex justify="start" align="middle">
<token-logo :token="token" />
<div>
<div v-if="checkAsset(token.symbol)" class="token-item__name">
{{ t(`assetNames.${token.symbol}`) }} ({{ token.symbol }})
</div>
<div v-else class="token-item__name">
{{ token.symbol }}
</div>
<div class="token-item__name">
{{ getTokenName(token.symbol) }}
</div>
</s-row>
</s-col>
Expand All @@ -40,17 +35,16 @@
</template>

<script lang="ts">
import { Component, Mixins, Prop, Watch } from 'vue-property-decorator'
import { Component, Mixins, Prop } from 'vue-property-decorator'
import { Action, Getter } from 'vuex-class'
import { KnownAssets, KnownSymbols } from '@sora-substrate/util'

import TranslationMixin from '@/components/mixins/TranslationMixin'
import DialogMixin from '@/components/mixins/DialogMixin'
import LoadingMixin from '@/components/mixins/LoadingMixin'
import DialogBase from '@/components/DialogBase.vue'
import { Token } from '@/types'
import { LogoSize, Components } from '@/consts'
import { lazyComponent } from '@/router'
import LoadingMixin from './mixins/LoadingMixin'

const namespace = 'assets'

Expand All @@ -64,21 +58,26 @@ export default class SelectToken extends Mixins(TranslationMixin, DialogMixin, L
query = ''
selectedToken: Token | null = null

@Prop({ default: () => null, type: Object }) readonly asset!: Token

@Getter('assets', { namespace }) assets!: Array<Token>
@Action('getAssets', { namespace }) getAssets

get assetsList (): Array<Token> {
return this.asset ? this.assets.filter(asset => asset.symbol !== this.asset.symbol) : this.assets
}

get filteredTokens (): Array<Token> {
if (this.query) {
const query = this.query.toLowerCase().trim()
return this.assets.filter(t =>
// add recieve token name from i18t
// t.name.toLowerCase().includes(query) ||
return this.assetsList.filter(t =>
this.t(`assetNames.${t.symbol}`).toLowerCase().includes(query) ||
t.symbol.toLowerCase().includes(query) ||
t.address.toLowerCase().includes(query)
)
}

return this.assets
return this.assetsList
}

created (): void {
Expand All @@ -93,8 +92,11 @@ export default class SelectToken extends Mixins(TranslationMixin, DialogMixin, L
this.isVisible = false
}

checkAsset (symbol: string): boolean {
return !!KnownSymbols[symbol]
getTokenName (tokenSymbol: string): string {
if (this.te(`assetNames.${tokenSymbol}`)) {
return `${this.t(`assetNames.${tokenSymbol}`)} (${tokenSymbol})`
}
return tokenSymbol
}
}
</script>
Expand Down
79 changes: 70 additions & 9 deletions src/components/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
>
<div class="settings-content">
<s-divider />
<div class="slippage-tolerance s-flex">
<div :class="slippageToleranceClasses">
<div class="slippage-tolerance-default">
<div class="header">
{{ t('settings.slippageTolerance') }}
Expand All @@ -33,9 +33,11 @@
size="small"
/>
</div>
<div v-if="slippageToleranceValidation" class="slippage-tolerance_validation">{{ t(`settings.slippageToleranceValidation.${slippageToleranceValidation}`) }}</div>
</div>
<s-divider />
<div class="transaction-deadline">
<!-- TODO: We'll play with this field at the next iteration of development -->
<!-- <div class="transaction-deadline">
<div class="header">
{{ t('settings.transactionDeadline') }}
<s-tooltip popper-class="info-tooltip" border-radius="mini" :content="t('settings.transactionDeadlineHint')" theme="light" placement="right-start" animation="none" :show-arrow="false">
Expand All @@ -47,14 +49,9 @@
<s-slider class="value-slider" :value="transactionDeadline" :showTooltip="false" @change="handleSetTransactionDeadline" />
</div>
</div>
<s-divider />
<s-divider /> -->
<div class="node-address">
<div class="header">
{{ t('settings.nodeAddress') }}
<s-tooltip popper-class="info-tooltip" border-radius="mini" :content="t('settings.nodeAddressHint')" theme="light" placement="right-start" animation="none" :show-arrow="false">
<s-icon class="header-hint" name="info" />
</s-tooltip>
</div>
<div class="header">{{ t('settings.nodeAddress') }}</div>
<div class="value">
<div class="value-container">
<span class="value-container_label">{{ t('settings.ip') }}: </span>{{ nodeAddress.ip }}
Expand Down Expand Up @@ -88,6 +85,11 @@ export default class Settings extends Mixins(TranslationMixin, DialogMixin) {
1
]

readonly slippageToleranceExtremeValues = {
min: 0.01,
max: 10
}

@Getter slippageTolerance!: number
@Getter transactionDeadline!: number
@Getter nodeAddress!: { ip: string; port: number }
Expand All @@ -103,6 +105,30 @@ export default class Settings extends Mixins(TranslationMixin, DialogMixin) {
this.setSlippageTolerance({ value })
}

get slippageToleranceClasses (): string {
const defaultClass = 'slippage-tolerance'
const classes = [defaultClass, 's-flex']

if (this.slippageToleranceValidation) {
classes.push(`${defaultClass}--${this.slippageToleranceValidation === 'frontrun' ? 'warning' : this.slippageToleranceValidation}`)
}

return classes.join(' ')
}

get slippageToleranceValidation (): string {
if (+this.model >= this.slippageToleranceExtremeValues.min && +this.model < 0.1) {
return 'warning'
}
if (+this.model >= 5 && +this.model <= this.slippageToleranceExtremeValues.max) {
return 'frontrun'
}
if (+this.model < this.slippageToleranceExtremeValues.min || +this.model > this.slippageToleranceExtremeValues.max) {
return 'error'
}
return ''
}

selectSlippageTolerance ({ name }): void {
this.setSlippageTolerance({ value: name })
}
Expand All @@ -127,6 +153,19 @@ export default class Settings extends Mixins(TranslationMixin, DialogMixin) {
.el-dialog .el-dialog__body {
padding-bottom: $inner-spacing-big;
}
.el-tabs__header {
margin-bottom: 0;
}
.slippage-tolerance--error .el-input__inner {
&,
&:focus {
border-color: var(--s-color-status-error);
}
}
// TODO: remove after UI Lib fix
.s-placeholder {
display: none;
}
}
</style>

Expand Down Expand Up @@ -170,12 +209,34 @@ export default class Settings extends Mixins(TranslationMixin, DialogMixin) {
}
}
.slippage-tolerance {
flex-wrap: wrap;
&-default {
flex: 2;
}
&-custom {
flex: 1;
}
&_validation {
margin-top: $inner-spacing-mini;
width: 100%;
font-size: var(--s-font-size-mini);
line-height: $s-line-height-big;
}
&--warning {
color: var(--s-color-status-warning)
}
&--error {
color: var(--s-color-status-error)
}
+ .s-divider-secondary {
margin-top: $inner-spacing-big;
}
&--warning,
&--error {
+ .s-divider-secondary {
margin-top: $inner-spacing-medium;
}
}
}
@include vertical-divider('el-divider');
</style>
Loading