-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* move to separate module * add enabling flag * Update getters.ts * remove route * Update types.ts
- Loading branch information
1 parent
440426a
commit bdda254
Showing
22 changed files
with
178 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,20 @@ | ||
import { defineModule } from 'direct-vuex'; | ||
|
||
import { localActionContext, localGetterContext } from '@/store'; | ||
import { localActionContext } from '@/store'; | ||
import { Module } from '@/store/consts'; | ||
|
||
import mutations from './mutations'; | ||
import state from './state'; | ||
import getters from './getters'; | ||
import actions from './actions'; | ||
|
||
const prices = defineModule({ | ||
namespaced: true, | ||
state, | ||
getters, | ||
mutations, | ||
actions, | ||
}); | ||
|
||
const pricesGetterContext = (args: [any, any, any, any]) => localGetterContext(args, Module.Prices, prices); | ||
const pricesActionContext = (context: any) => localActionContext(context, Module.Prices, prices); | ||
|
||
export { pricesActionContext, pricesGetterContext }; | ||
export { pricesActionContext }; | ||
export default prices; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { defineActions } from 'direct-vuex'; | ||
import { api } from '@soramitsu/soraneo-wallet-web'; | ||
import { FPNumber } from '@sora-substrate/util'; | ||
|
||
import { getXorPerEuroRatio, waitForAccountPair } from '@/utils'; | ||
import { soraCardActionContext } from './../soraCard'; | ||
|
||
const actions = defineActions({ | ||
calculateXorRestPrice(context, xorPerEuro): void { | ||
const { state, commit } = soraCardActionContext(context); | ||
const { totalXorBalance } = state; | ||
const euroToPay = FPNumber.HUNDRED.add(FPNumber.ONE).sub(totalXorBalance.mul(xorPerEuro)); | ||
const euroToPayInXor = euroToPay.div(xorPerEuro); | ||
|
||
commit.setXorPriceToDeposit(euroToPayInXor); | ||
}, | ||
|
||
async calculateXorBalanceInEuros(context, xorTotalBalance: FPNumber): Promise<void> { | ||
const { commit, dispatch } = soraCardActionContext(context); | ||
try { | ||
const xorPerEuro: string = await getXorPerEuroRatio(); | ||
const xorPerEuroFPN = FPNumber.fromNatural(xorPerEuro); | ||
const euroBalance = xorTotalBalance.mul(xorPerEuroFPN).toNumber(); | ||
commit.setEuroBalance(euroBalance.toString()); | ||
|
||
if (euroBalance < 100) { | ||
dispatch.calculateXorRestPrice(xorPerEuroFPN); | ||
} | ||
} catch {} | ||
}, | ||
|
||
async subscribeToTotalXorBalance(context): Promise<void> { | ||
const { commit, rootGetters, dispatch } = soraCardActionContext(context); | ||
|
||
commit.resetTotalXorBalanceUpdates(); | ||
|
||
if (!rootGetters.wallet.account.isLoggedIn) return; | ||
|
||
await waitForAccountPair(async () => { | ||
const subscription = api.assets.getTotalXorBalanceObservable().subscribe((xorTotalBalance: FPNumber) => { | ||
commit.setTotalXorBalance(xorTotalBalance); | ||
dispatch.calculateXorBalanceInEuros(xorTotalBalance); | ||
}); | ||
|
||
commit.setTotalXorBalanceUpdates(subscription); | ||
}); | ||
}, | ||
|
||
async unsubscribeFromTotalXorBalance(context): Promise<void> { | ||
const { commit } = soraCardActionContext(context); | ||
setTimeout(() => { | ||
commit.resetTotalXorBalanceUpdates(); | ||
}, 1000 * 60 * 5); | ||
}, | ||
}); | ||
|
||
export default actions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { defineModule } from 'direct-vuex'; | ||
|
||
import { localActionContext, localGetterContext } from '@/store'; | ||
import { Module } from '@/store/consts'; | ||
|
||
import mutations from './mutations'; | ||
import state from './state'; | ||
import getters from './getters'; | ||
import actions from './actions'; | ||
|
||
const soraCard = defineModule({ | ||
namespaced: true, | ||
state, | ||
getters, | ||
mutations, | ||
actions, | ||
}); | ||
|
||
const soraCardGetterContext = (args: [any, any, any, any]) => localGetterContext(args, Module.SoraCard, soraCard); | ||
const soraCardActionContext = (context: any) => localActionContext(context, Module.SoraCard, soraCard); | ||
|
||
export { soraCardActionContext, soraCardGetterContext }; | ||
export default soraCard; |
Oops, something went wrong.