Skip to content

Commit

Permalink
Add namespace & types for swap (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefashkaa authored Mar 15, 2021
1 parent 93cc076 commit 843057c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 36 deletions.
21 changes: 12 additions & 9 deletions src/components/ConfirmSwap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import { Component, Mixins, Prop } from 'vue-property-decorator'
import { Getter } from 'vuex-class'
import { api } from '@soramitsu/soraneo-wallet-web'
import { CodecString } from '@sora-substrate/util'
import { CodecString, AccountAsset } from '@sora-substrate/util'
import TransactionMixin from '@/components/mixins/TransactionMixin'
import DialogMixin from '@/components/mixins/DialogMixin'
Expand All @@ -50,6 +50,8 @@ import DialogBase from '@/components/DialogBase.vue'
import { lazyComponent } from '@/router'
import { Components } from '@/consts'
const namespace = 'swap'
@Component({
components: {
DialogBase,
Expand All @@ -58,13 +60,14 @@ import { Components } from '@/consts'
}
})
export default class ConfirmSwap extends Mixins(TransactionMixin, DialogMixin, NumberFormatterMixin) {
@Getter tokenFrom!: any
@Getter tokenTo!: any
@Getter fromValue!: string
@Getter minMaxReceived!: CodecString
@Getter toValue!: string
@Getter('tokenFrom', { namespace }) tokenFrom!: AccountAsset
@Getter('tokenTo', { namespace }) tokenTo!: AccountAsset
@Getter('fromValue', { namespace }) fromValue!: string
@Getter('toValue', { namespace }) toValue!: string
@Getter('minMaxReceived', { namespace }) minMaxReceived!: CodecString
@Getter('isExchangeB', { namespace }) isExchangeB!: boolean
@Getter slippageTolerance!: number
@Getter isExchangeB!: boolean
@Prop({ default: false, type: Boolean }) readonly isInsufficientBalance!: boolean
Expand Down Expand Up @@ -92,8 +95,8 @@ export default class ConfirmSwap extends Mixins(TransactionMixin, DialogMixin, N
async () => await api.swap(
this.tokenFrom.address,
this.tokenTo.address,
this.fromValue.toString(),
this.toValue.toString(),
this.fromValue,
this.toValue,
this.slippageTolerance,
this.isExchangeB
)
Expand Down
55 changes: 28 additions & 27 deletions src/components/Swap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ import { isWalletConnected, isXorAccountAsset, isMaxButtonAvailable, getMaxValue
import router, { lazyComponent } from '@/router'
import { Components, PageNames } from '@/consts'
const namespace = 'swap'
@Component({
components: {
SwapInfo: lazyComponent(Components.SwapInfo),
Expand All @@ -125,32 +127,31 @@ import { Components, PageNames } from '@/consts'
}
})
export default class Swap extends Mixins(TranslationMixin, LoadingMixin, NumberFormatterMixin) {
@Getter tokenXOR!: any
@Getter tokenFrom!: any
@Getter tokenTo!: any
@Getter fromValue!: string
@Getter toValue!: string
@Getter isExchangeB!: boolean
@Getter('tokenXOR', { namespace }) tokenXOR!: AccountAsset
@Getter('tokenFrom', { namespace }) tokenFrom!: AccountAsset
@Getter('tokenTo', { namespace }) tokenTo!: AccountAsset
@Getter('fromValue', { namespace }) fromValue!: string
@Getter('toValue', { namespace }) toValue!: string
@Getter('isExchangeB', { namespace }) isExchangeB!: boolean
@Getter('networkFee', { namespace }) networkFee!: CodecString
@Getter('liquidityProviderFee', { namespace }) liquidityProviderFee!: CodecString
@Action('getTokenXOR', { namespace }) getTokenXOR!: () => Promise<void>
@Action('setTokenFrom', { namespace }) setTokenFrom!: (options: any) => Promise<void>
@Action('setTokenTo', { namespace }) setTokenTo!: (options: any) => Promise<void>
@Action('setFromValue', { namespace }) setFromValue!: (value: string) => Promise<void>
@Action('setToValue', { namespace }) setToValue!: (value: string) => Promise<void>
@Action('setTokenFromPrice', { namespace }) setTokenFromPrice!: (isTokenFromPrice: boolean) => Promise<void>
@Action('setMinMaxReceived', { namespace }) setMinMaxReceived!: (value: CodecString) => Promise<void>
@Action('setExchangeB', { namespace }) setExchangeB!: (isExchangeB: boolean) => Promise<void>
@Action('setLiquidityProviderFee', { namespace }) setLiquidityProviderFee!: (value: CodecString) => Promise<void>
@Action('setNetworkFee', { namespace }) setNetworkFee!: (value: CodecString) => Promise<void>
@Action('getPrices', { namespace: 'prices' }) getPrices!: (options: any) => Promise<void>
@Action('resetPrices', { namespace: 'prices' }) resetPrices!: () => Promise<void>
@Getter slippageTolerance!: number
@Getter networkFee!: CodecString
@Getter liquidityProviderFee!: CodecString
@Action getTokenXOR
@Action setTokenFrom
@Action setTokenTo
@Action setFromValue
@Action setToValue
@Action setTokenFromPrice
@Action setMinMaxReceived
@Action setExchangeB
@Action setLiquidityProviderFee
@Action setNetworkFee
@Action('getPrices', { namespace: 'prices' }) getPrices
@Action('resetPrices', { namespace: 'prices' }) resetPrices
// Wallet store
@Getter accountAssets!: Array<AccountAsset>
@Getter accountAssets!: Array<AccountAsset> // Wallet store
@Watch('slippageTolerance')
private handleSlippageToleranceChange (): void {
Expand Down Expand Up @@ -203,7 +204,7 @@ export default class Swap extends Mixins(TranslationMixin, LoadingMixin, NumberF
let fpBalance = this.getFPNumberFromCodec(this.tokenFrom.balance, this.tokenFrom.decimals)
const fpAmount = this.getFPNumber(this.fromValue, this.tokenFrom.decimals)
if (FPNumber.lt(fpBalance, fpAmount)) {
this.insufficientBalanceTokenSymbol = this.tokenFrom.symbol
this.insufficientBalanceTokenSymbol = this.tokenFrom.symbol as string
return true
}
const fpFee = this.getFPNumberFromCodec(this.networkFee, this.tokenFrom.decimals)
Expand Down Expand Up @@ -335,7 +336,7 @@ export default class Swap extends Mixins(TranslationMixin, LoadingMixin, NumberF
}
} catch (error) {
resetOppositeValue()
if (!this.isInsufficientAmountError(token.symbol, error.message)) {
if (!this.isInsufficientAmountError(token.symbol as string, error.message)) {
throw error
}
} finally {
Expand Down
1 change: 1 addition & 0 deletions src/store/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ const actions = {
}

export default {
namespaced: true,
state,
getters,
mutations,
Expand Down

0 comments on commit 843057c

Please sign in to comment.