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

Remove liquidity: reactive updates #476

Merged
merged 6 commits into from
Sep 29, 2021
Merged
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
18 changes: 10 additions & 8 deletions src/components/ConfirmRemoveLiquidity.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@

<script lang="ts">
import { Component, Mixins } from 'vue-property-decorator'
import { Getter } from 'vuex-class'
import { Getter, State } from 'vuex-class'
import { components, mixins } from '@soramitsu/soraneo-wallet-web'
import type { Asset } from '@sora-substrate/util'

import TranslationMixin from '@/components/mixins/TranslationMixin'
import DialogMixin from '@/components/mixins/DialogMixin'
Expand All @@ -69,15 +70,16 @@ const namespace = 'removeLiquidity'
}
})
export default class ConfirmRemoveLiquidity extends Mixins(mixins.NumberFormatterMixin, TranslationMixin, DialogMixin, LoadingMixin) {
@Getter('firstToken', { namespace }) firstToken!: any
@Getter('secondToken', { namespace }) secondToken!: any
@Getter('liquidityAmount', { namespace }) liquidityAmount!: string
@Getter('firstTokenAmount', { namespace }) firstTokenAmount!: string
@Getter('secondTokenAmount', { namespace }) secondTokenAmount!: string
@State(state => state[namespace].liquidityAmount) liquidityAmount!: string
@State(state => state[namespace].firstTokenAmount) firstTokenAmount!: string
@State(state => state[namespace].secondTokenAmount) secondTokenAmount!: string

@Getter('firstToken', { namespace }) firstToken!: Asset
@Getter('secondToken', { namespace }) secondToken!: Asset
@Getter('shareOfPool', { namespace }) shareOfPool!: string

@Getter('price', { namespace: 'prices' }) price!: string | number
@Getter('priceReversed', { namespace: 'prices' }) priceReversed!: string | number
@Getter('price', { namespace: 'prices' }) price!: string
@Getter('priceReversed', { namespace: 'prices' }) priceReversed!: string

@Getter slippageTolerance!: string

Expand Down
15 changes: 8 additions & 7 deletions src/store/addLiquidity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fromPairs from 'lodash/fp/fromPairs'
import flow from 'lodash/fp/flow'
import concat from 'lodash/fp/concat'
import { api } from '@soramitsu/soraneo-wallet-web'
import { KnownAssets, FPNumber, CodecString } from '@sora-substrate/util'
import { KnownAssets, FPNumber, CodecString, AccountBalance } from '@sora-substrate/util'

import { ZeroStringValue } from '@/consts'
import { TokenBalanceSubscriptions } from '@/utils/subscriptions'
Expand Down Expand Up @@ -35,7 +35,7 @@ interface AddLiquidityState {
secondTokenAddress: string;
firstTokenValue: string;
secondTokenValue: string;
secondTokenBalance: any;
secondTokenBalance: Nullable<AccountBalance>;
reserve: Nullable<Array<CodecString>>;
minted: CodecString;
totalSupply: CodecString;
Expand All @@ -51,8 +51,8 @@ function initialState (): AddLiquidityState {
secondTokenValue: '',
secondTokenBalance: null,
reserve: null,
minted: '',
totalSupply: '',
minted: ZeroStringValue,
totalSupply: ZeroStringValue,
focusedField: null,
isAvailable: false
}
Expand Down Expand Up @@ -150,7 +150,7 @@ const mutations = {
state.minted = minted
state.totalSupply = pts
},
[types.ESTIMATE_MINTED_FAILURE] (state, error) {
[types.ESTIMATE_MINTED_FAILURE] (state: AddLiquidityState) {
state.minted = ZeroStringValue
state.totalSupply = ZeroStringValue
},
Expand Down Expand Up @@ -233,7 +233,8 @@ const actions = {
)
commit(types.ESTIMATE_MINTED_SUCCESS, { minted, pts })
} catch (error) {
commit(types.ESTIMATE_MINTED_FAILURE, error)
console.error(error)
commit(types.ESTIMATE_MINTED_FAILURE)
}
}
},
Expand Down Expand Up @@ -299,7 +300,7 @@ const actions = {
}
},

async setDataFromLiquidity ({ dispatch }, { firstAddress, secondAddress }) {
async setDataFromLiquidity ({ dispatch }, { firstAddress, secondAddress }: { firstAddress: string; secondAddress: string }) {
const findAssetAddress = address => {
const asset = KnownAssets.get(address) ?? api.accountAssets.find(a => a.address === address)
return asset?.address ?? ''
Expand Down
Loading