Skip to content

Commit

Permalink
add distribution as widget, style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita-Polyakov committed Mar 5, 2024
1 parent 93b5d37 commit 0954fb9
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 38 deletions.
17 changes: 5 additions & 12 deletions src/components/pages/Swap/Distribution.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<el-popover :visible-arrow="false" placement="right-end" popper-class="swap-distribution-popper" trigger="click">
<base-widget :title="t('swap.route')">
<ul class="distribution">
<li v-for="{ input, output, amount, sources } in swapPaths" :key="input.address" class="distribution-step">
<div class="distribution-asset">
Expand Down Expand Up @@ -30,10 +30,7 @@
</div>
</li>
</ul>
<template #reference>
<slot />
</template>
</el-popover>
</base-widget>
</template>

<script lang="ts">
Expand All @@ -42,6 +39,7 @@ import { FPNumber } from '@sora-substrate/util';
import { components, mixins } from '@soramitsu/soraneo-wallet-web';
import { Component, Mixins } from 'vue-property-decorator';
import TranslationMixin from '@/components/mixins/TranslationMixin';
import { Components } from '@/consts';
import { lazyComponent } from '@/router';
import { getter, state } from '@/store/decorators';
Expand Down Expand Up @@ -76,10 +74,11 @@ const MARKETS = {
components: {
TokenLogo: components.TokenLogo,
FormattedAmount: components.FormattedAmount,
BaseWidget: lazyComponent(Components.BaseWidget),
ValueStatusWrapper: lazyComponent(Components.ValueStatusWrapper),
},
})
export default class SwapDistribution extends Mixins(mixins.FormattedAmountMixin) {
export default class SwapDistribution extends Mixins(mixins.FormattedAmountMixin, TranslationMixin) {
@state.swap.distribution private distribution!: Distribution[][];
@getter.assets.assetDataByAddress private getAsset!: (addr?: string) => Nullable<AccountAsset>;
Expand Down Expand Up @@ -127,12 +126,6 @@ export default class SwapDistribution extends Mixins(mixins.FormattedAmountMixin
}
</script>

<style lang="scss">
.swap-distribution-popper {
@include popper-content;
}
</style>

<style lang="scss" scoped>
$path-color: var(--s-color-base-content-tertiary);
Expand Down
26 changes: 17 additions & 9 deletions src/components/pages/Swap/Form/Widget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,13 @@ export default class SwapFormWidget extends Mixins(
@mutation.settings.setChartsEnabled private setChartsEnabled!: (value: boolean) => void;
@mutation.swap.setFromValue private setFromValue!: (value: string) => void;
@mutation.swap.setToValue private setToValue!: (value: string) => void;
@mutation.swap.setAmountWithoutImpact private setAmountWithoutImpact!: (amount: CodecString) => void;
@mutation.swap.setAmountWithoutImpact private setAmountWithoutImpact!: (amount?: CodecString) => void;
@mutation.swap.setExchangeB private setExchangeB!: (isExchangeB: boolean) => void;
@mutation.swap.setLiquidityProviderFee private setLiquidityProviderFee!: (value: CodecString) => void;
@mutation.swap.setRewards private setRewards!: (rewards: Array<LPRewardsInfo>) => void;
@mutation.swap.setRoute private setRoute!: (route: Array<string>) => void;
@mutation.swap.setDistribution private setDistribution!: (distribution: Distribution[][]) => void;
@mutation.swap.selectDexId private selectDexId!: (dexId: DexId) => void;
@mutation.swap.setLiquidityProviderFee private setLiquidityProviderFee!: (value?: CodecString) => void;
@mutation.swap.setRewards private setRewards!: (rewards?: Array<LPRewardsInfo>) => void;
@mutation.swap.setRoute private setRoute!: (route?: Array<string>) => void;
@mutation.swap.setDistribution private setDistribution!: (distribution?: Distribution[][]) => void;
@mutation.swap.selectDexId private selectDexId!: (dexId?: DexId) => void;
@mutation.swap.setSubscriptionPayload private setSubscriptionPayload!: (payload?: SwapQuoteData) => void;
@action.swap.setTokenFromAddress private setTokenFromAddress!: (address?: string) => Promise<void>;
Expand Down Expand Up @@ -413,7 +413,17 @@ export default class SwapFormWidget extends Mixins(
private runRecountSwapValues(): void {
const value = this.isExchangeB ? this.toValue : this.fromValue;
if (!this.areTokensSelected || asZeroValue(value) || !this.swapQuote) return;
if (!this.areTokensSelected || asZeroValue(value) || !this.swapQuote) {
this.setAmountWithoutImpact();
this.setLiquidityProviderFee();
this.setRewards();
this.setRoute();
this.setDistribution();
this.selectDexId();
return;
}
const setOppositeValue = this.isExchangeB ? this.setFromValue : this.setToValue;
const resetOppositeValue = this.isExchangeB ? this.resetFieldFrom : this.resetFieldTo;
const oppositeToken = (this.isExchangeB ? this.tokenFrom : this.tokenTo) as AccountAsset;
Expand Down Expand Up @@ -577,8 +587,6 @@ export default class SwapFormWidget extends Mixins(

<style lang="scss" scoped>
.swap-widget {
max-width: $inner-window-width;
@include buttons;
@include full-width-button('action-button');
@include vertical-divider('el-button--switch-tokens', $inner-spacing-medium);
Expand Down
6 changes: 0 additions & 6 deletions src/components/pages/Swap/TransactionDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
</info-line>
<info-line :label="t('swap.route')">
<div class="swap-route">
<swap-distribution>
<s-icon class="el-tooltip" name="info-16" size="14px" />
</swap-distribution>

<div class="swap-route-paths s-flex">
<div v-for="(token, index) in swapRoute" class="swap-route-value" :key="token">
<span>{{ token }}</span>
Expand Down Expand Up @@ -81,7 +77,6 @@ type RewardValue = {
components: {
ValueStatusWrapper: lazyComponent(Components.ValueStatusWrapper),
TransactionDetails: lazyComponent(Components.TransactionDetails),
SwapDistribution: lazyComponent(Components.SwapDistribution),
FormattedAmount: components.FormattedAmount,
InfoLine: components.InfoLine,
},
Expand Down Expand Up @@ -186,7 +181,6 @@ export default class SwapTransactionDetails extends Mixins(mixins.FormattedAmoun
align-items: center;
justify-content: space-between;
gap: $inner-spacing-mini;
width: 100%;
&-value {
font-weight: 600;
Expand Down
2 changes: 1 addition & 1 deletion src/components/shared/Chart/ChartSkeleton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ $skeleton-label-width: 34px;
min-height: 293px;
@include tablet {
min-height: 336px;
min-height: 317px;
}
&-price {
Expand Down
11 changes: 8 additions & 3 deletions src/components/shared/TransactionDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,20 @@ export default class TransactionDetails extends Mixins(TranslationMixin) {

<style lang="scss">
.transaction-details-wrapper {
margin-bottom: -24px;
.el-collapse-item__header {
display: flex;
text-transform: uppercase;
font-weight: 400;
}
.el-collapse-item__content {
padding-bottom: 0;
}
.el-collapse-item__wrap {
margin-top: $inner-spacing-medium;
}
.el-collapse.neumorphic .el-icon-arrow-right {
all: initial;
* {
Expand All @@ -55,7 +61,6 @@ export default class TransactionDetails extends Mixins(TranslationMixin) {
line-height: 13px;
height: 14px;
font-size: 13px;
margin-bottom: 15px;
.el-icon-arrow-right {
position: relative;
Expand Down
1 change: 1 addition & 0 deletions src/components/shared/Widget/Base.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ $left: $inner-spacing-medium;
.base-widget {
display: flex;
flex-flow: column nowrap;
align-items: normal;
&-block {
display: flex;
Expand Down
14 changes: 8 additions & 6 deletions src/store/swap/mutations.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { DexId } from '@sora-substrate/util/build/dex/consts';
import { defineMutations } from 'direct-vuex';
import omit from 'lodash/fp/omit';

import { ZeroStringValue } from '@/consts';
import { settingsStorage } from '@/utils/storage';

import { initialState } from './state';
Expand Down Expand Up @@ -43,22 +45,22 @@ const mutations = defineMutations<SwapState>()({
setToValue(state, value: string): void {
state.toValue = value;
},
setAmountWithoutImpact(state, amount: CodecString): void {
setAmountWithoutImpact(state, amount: CodecString = ZeroStringValue): void {
state.amountWithoutImpact = amount;
},
setExchangeB(state, value: boolean): void {
state.isExchangeB = value;
},
setLiquidityProviderFee(state, value: CodecString): void {
setLiquidityProviderFee(state, value: CodecString = ZeroStringValue): void {
state.liquidityProviderFee = value;
},
setRewards(state, rewards: Array<LPRewardsInfo>): void {
setRewards(state, rewards: Array<LPRewardsInfo> = []): void {
state.rewards = Object.freeze([...rewards]);
},
setRoute(state, route: string[]): void {
setRoute(state, route: string[] = []): void {
state.route = Object.freeze([...route]);
},
setDistribution(state, distribution: Distribution[][]): void {
setDistribution(state, distribution: Distribution[][] = []): void {
state.distribution = Object.freeze([...distribution]);
},
setSubscriptionPayload(state, payload?: SwapQuoteData): void {
Expand All @@ -70,7 +72,7 @@ const mutations = defineMutations<SwapState>()({
setLiquiditySource(state, liquiditySource): void {
state.liquiditySources = [liquiditySource];
},
selectDexId(state, dexId: number) {
selectDexId(state, dexId: number = DexId.XOR) {
state.selectedDexId = dexId;
},
setAllowLossPopup(state, flag: boolean) {
Expand Down
1 change: 1 addition & 0 deletions src/styles/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ $button-custom-shadow: -1px -1px 5px rgba(0, 0, 0, 0.05), 1px 1px 5px rgba(0, 0,
line-height: var(--s-line-height-medium);

&--footer {
align-items: flex-start;
margin-top: $inner-spacing-tiny;
margin-bottom: 0;
min-height: $inner-spacing-mini * 2.625; // 21px
Expand Down
17 changes: 16 additions & 1 deletion src/views/Swap.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<template>
<div class="swap-container">
<swap-form-widget :parent-loading="parentLoading" />
<div class="column column--small">
<swap-form-widget :parent-loading="parentLoading" class="swap-form" />
<swap-distribution-widget />
</div>
<div class="column">
<swap-chart-widget :parent-loading="parentLoading" v-if="chartsEnabled" class="swap-chart" />
<swap-transactions-widget :parent-loading="parentLoading" />
Expand All @@ -26,6 +29,7 @@ import type { AccountAsset } from '@sora-substrate/util/build/assets/types';
SwapFormWidget: lazyComponent(Components.SwapFormWidget),
SwapChartWidget: lazyComponent(Components.SwapChartWidget),
SwapTransactionsWidget: lazyComponent(Components.SwapTransactionsWidget),
SwapDistributionWidget: lazyComponent(Components.SwapDistribution),
},
})
export default class Swap extends Mixins(mixins.LoadingMixin, TranslationMixin, SelectedTokenRouteMixin) {
Expand Down Expand Up @@ -81,10 +85,21 @@ export default class Swap extends Mixins(mixins.LoadingMixin, TranslationMixin,
justify-content: center;
align-items: flex-start;
gap: $inner-spacing-medium;
.swap-chart,
.swap-form {
@include desktop {
min-height: 517px;
}
}
}
.column {
display: flex;
gap: $inner-spacing-medium;
flex-flow: column nowrap;
&--small {
max-width: $inner-window-width;
}
}
</style>

0 comments on commit 0954fb9

Please sign in to comment.