diff --git a/src/store/demeris-api/action-types.ts b/src/store/demeris-api/action-types.ts index 1bfb7ba3d..6a19cc2ae 100644 --- a/src/store/demeris-api/action-types.ts +++ b/src/store/demeris-api/action-types.ts @@ -1,53 +1,4 @@ export enum ActionTypes { - // Wrapper/Grouping actions - GET_ALL_BALANCES = 'GET_ALL_BALANCES', - GET_ALL_STAKING_BALANCES = 'GET_ALL_STAKING_BALANCES', - GET_ALL_UNBONDING_DELEGATIONS = 'GET_ALL_UNBONDING_DELEGATIONS', - - // Emeris Endpoints - GET_BALANCES = 'GET_BALANCES', - GET_POOL_BALANCES = 'GET_POOL_BALANCES', - GET_STAKING_BALANCES = 'GET_STAKING_BALANCES', - GET_UNBONDING_DELEGATIONS = 'GET_UNBONDING_DELEGATIONS', - GET_NUMBERS_CHAIN = 'GET_NUMBERS_CHAIN', - GET_VERIFIED_DENOMS = 'GET_VERIFIED_DENOMS', - GET_CHAIN = 'GET_CHAIN', - GET_CHAIN_APR = 'GET_CHAIN_APR', - GET_CHAIN_STATUS = 'GET_CHAIN_STATUS', - GET_CHAINS = 'GET_CHAINS', - GET_CHAINS_AND_CHAIN_STATUS = 'GET_CHAINS_AND_CHAIN_STATUS', - GET_PRICES = 'GET_PRICES', - GET_TX_STATUS = 'GET_TX_STATUS', - GET_TX_DEST_HASH = 'GET_TX_DEST_HASH', - GET_END_BLOCK_EVENTS = 'GET_END_BLOCK_EVENTS', - GET_VALIDATORS = 'GET_VALIDATORS', - GET_INFLATION = 'GET_INFLATION', - GET_STAKING_REWARDS = 'GET_STAKING_REWARDS', - GET_UNSTAKING_PARAM = 'GET_UNSTAKING_PARAM', - GET_VERIFY_TRACE = 'GET_VERIFY_TRACE', - GET_TOKEN_PRICES = 'GET_TOKEN_PRICES', - TRACE_TX_RESPONSE = 'TRACE_TX_RESPONSE', - GET_TX_FROM_RPC = 'GET_TX_FROM_RPC', - GET_NEW_BLOCK = 'GET_NEW_BLOCK', - - // Coingecko Endpoints - GET_COINGECKO_ID_BY_NAMES = 'GET_COINGECKO_ID_BY_NAMES', - - // Airdrop Endpoints - GET_GIT_AIRDROPS_LIST = 'GET_GIT_AIRDROPS_LIST', - GET_AIRDROPS = 'GET_AIRDROPS', - RESET_AIRDROPS = 'RESET_AIRDROPS', - VALIDATE_POOLS = 'VALIDATE_POOLS', - RESET_TOKEN_PRICES = 'RESET_TOKEN_PRICES', - SIGN_OUT = 'SIGN_OUT', - - // Internal module actions - INIT = 'INIT', - RESET_STATE = 'RESET_STATE', - UNSUBSCRIBE = 'UNSUBSCRIBE', - STORE_UPDATE = 'STORE_UPDATE', -} -export enum GlobalActionTypes { // Wrapper/Grouping actions GET_ALL_BALANCES = 'demerisAPI/GET_ALL_BALANCES', GET_ALL_STAKING_BALANCES = 'demerisAPI/GET_ALL_STAKING_BALANCES', diff --git a/src/store/demeris-api/actions.ts b/src/store/demeris-api/actions.ts index c13da1a9d..f9bd8cdc3 100644 --- a/src/store/demeris-api/actions.ts +++ b/src/store/demeris-api/actions.ts @@ -1,11 +1,9 @@ -import { EncodeObject, Registry } from '@cosmjs/proto-signing'; -import { EmerisAPI, EmerisBase } from '@emeris/types'; +import { EmerisAPI } from '@emeris/types'; import axios, { AxiosResponse } from 'axios'; import { ActionTree } from 'vuex'; import { GlobalGetterTypes, RootState } from '@/store'; import { Pool } from '@/types/actions'; -import { UserData } from '@/types/user'; import { ActionParams, SimpleSubscribable, Subscribable } from '@/types/util'; import { validPools } from '@/utils/actionHandler'; import { getOwnAddress, hashObject } from '@/utils/basic'; @@ -16,12 +14,12 @@ import { RootStoreTyped } from '../'; import { featureRunning } from './../../utils/FeatureManager'; import { APIStore } from '.'; import { ActionTypes } from './action-types'; -import { AirdropActions, AirdropActionsInterface } from './actions/airdrops'; -import { BalanceActions, BalanceActionsInterface } from './actions/balances'; -import { ChainActions, ChainActionsInterface } from './actions/chain'; -import { PriceActions, PriceActionsInterface } from './actions/prices'; -import { StakingActions, StakingActionsInterface } from './actions/staking'; -import { TransactionActions, TransactionActionsInterface } from './actions/transactions'; +import { AirdropActions } from './actions/airdrops'; +import { BalanceActions } from './actions/balances'; +import { ChainActions } from './actions/chain'; +import { PriceActions } from './actions/prices'; +import { StakingActions } from './actions/staking'; +import { TransactionActions } from './actions/transactions'; import { MutationTypes } from './mutation-types'; import { APIState } from './state'; @@ -43,85 +41,23 @@ export type DemerisConfig = { hub_chain?: string; gas_limit?: number; }; -export type DemerisTxParams = { - tx: string; - chain_name: string; - address: string; -}; export type DemerisTxResultParams = { height: number; stepType: string; }; -export type GasFee = { - amount: Array; - gas: string; -}; -export type DemerisSignParams = { - msgs: Array; - chain_name: string; - fee: GasFee; - registry: Registry; - memo?: string; -}; -export type DemerisSessionParams = { - data: UserData; -}; export type TicketResponse = { ticket: string; }; -export type DemerisGetValidatorsParam = { - chain_name: string; -}; -export type DemerisGetInflationParam = { - chain_name: string; -}; -export type DemerisGetRewardsParam = { - chain_name: string; -}; -export type DemerisGetUnstakingParam = { - chain_name: string; -}; -type Namespaced = { - [P in keyof T & string as `${N}/${P}`]: T[P]; -}; -export type Subscription = { - action: K; - payload?: Omit[1], 'subscribe'>; +export type Subscription = { + action: any; + payload?: any; }; -export type Subscriptions = Subscription; - -export interface Actions - extends ChainActionsInterface, - AirdropActionsInterface, - BalanceActionsInterface, - StakingActionsInterface, - PriceActionsInterface, - TransactionActionsInterface { - //Pools Action types - [ActionTypes.VALIDATE_POOLS](context: APIActionContext, pools: Pool[]): Promise; - - //Uncategorized Action types - [ActionTypes.GET_VERIFIED_DENOMS]( - context: APIActionContext, - payload: SimpleSubscribable, - ): Promise; - [ActionTypes.GET_VERIFY_TRACE]( - context: APIActionContext, - payload: Subscribable>, - ): Promise; - [ActionTypes.GET_END_BLOCK_EVENTS](context: APIActionContext, { height }: DemerisTxResultParams): Promise; - [ActionTypes.INIT](context: APIActionContext, config: DemerisConfig): void; - [ActionTypes.RESET_STATE](context: APIActionContext): void; - [ActionTypes.SIGN_OUT](context: APIActionContext, keyHashes: string[]): void; - [ActionTypes.UNSUBSCRIBE](context: APIActionContext, subscription: Subscriptions): void; - [ActionTypes.STORE_UPDATE](context: APIActionContext): void; -} -export type GlobalActions = Namespaced; +export type Subscriptions = Subscription; -export const actions: ActionTree & Actions = { +export const actions: ActionTree = { ...ChainActions, ...AirdropActions, ...BalanceActions, @@ -129,7 +65,7 @@ export const actions: ActionTree & Actions = { ...PriceActions, ...TransactionActions, - async [ActionTypes.VALIDATE_POOLS]({ commit, getters }, pools) { + async [ActionTypes.VALIDATE_POOLS]({ commit, getters }: APIActionContext, pools: Pool[]): Promise { try { const vp = await validPools(pools); commit(MutationTypes.SET_VALID_POOLS, vp); @@ -137,13 +73,16 @@ export const actions: ActionTree & Actions = { console.error(e); throw new EmerisError('Demeris:ValidatePools', 'Could not perform pool validation.'); } - return getters['getAllValidPools']; + return getters[GlobalGetterTypes.API.getAllValidPools]; }, - async [ActionTypes.GET_VERIFIED_DENOMS]({ commit, getters, rootGetters }, { subscribe = false }) { + async [ActionTypes.GET_VERIFIED_DENOMS]( + { commit, getters, rootGetters }: APIActionContext, + { subscribe = false }: SimpleSubscribable, + ): Promise { axios.defaults.headers.get['X-Correlation-Id'] = rootGetters[GlobalGetterTypes.USER.getCorrelationId]; try { const response: AxiosResponse = await axios.get( - getters['getEndpoint'] + '/verified_denoms', + getters[GlobalGetterTypes.API.getEndpoint] + '/verified_denoms', ); commit(MutationTypes.SET_VERIFIED_DENOMS, { value: response.data.verified_denoms }); if (subscribe) { @@ -152,17 +91,20 @@ export const actions: ActionTree & Actions = { } catch (e) { throw new EmerisError('Demeris:GetVerifiedDenoms', 'Could not perform API query.'); } - return getters['getVerifiedDenoms']; + return getters[GlobalGetterTypes.API.getVerifiedDenoms]; }, // Chain-specific endpoint actions - async [ActionTypes.GET_VERIFY_TRACE]({ commit, getters, state, rootGetters }, { subscribe = false, params }) { + async [ActionTypes.GET_VERIFY_TRACE]( + { commit, getters, state, rootGetters }: APIActionContext, + { subscribe = false, params }: Subscribable>, + ): Promise { axios.defaults.headers.get['X-Correlation-Id'] = rootGetters[GlobalGetterTypes.USER.getCorrelationId]; const reqHash = hashObject({ action: ActionTypes.GET_VERIFY_TRACE, payload: { params } }); if (state._InProgess.get(reqHash)) { await state._InProgess.get(reqHash); - return getters['getVerifyTrace'](params); + return getters[GlobalGetterTypes.API.getVerifyTrace](params); } else { let resolver; const promise: Promise = new Promise((resolve, _) => { @@ -171,7 +113,7 @@ export const actions: ActionTree & Actions = { commit(MutationTypes.SET_IN_PROGRESS, { hash: reqHash, promise }); try { const response: AxiosResponse = await axios.get( - getters['getEndpoint'] + '/chain/' + params.chain_name + '/denom/verify_trace/' + params.hash, + `${getters[GlobalGetterTypes.API.getEndpoint]}/chain/${params.chain_name}/denom/verify_trace/${params.hash}`, ); if (response?.data?.verify_trace?.trace) { commit(MutationTypes.SET_VERIFY_TRACE, { params, value: response.data.verify_trace }); @@ -197,14 +139,14 @@ export const actions: ActionTree & Actions = { } resolver(); commit(MutationTypes.DELETE_IN_PROGRESS, reqHash); - return getters['getVerifyTrace'](params); + return getters[GlobalGetterTypes.API.getVerifyTrace](params); } }, - async [ActionTypes.GET_NEW_BLOCK]({ getters }, { chain_name }) { + async [ActionTypes.GET_NEW_BLOCK]({ getters }: APIActionContext, { chain_name }) { return new Promise(async (resolve, reject) => { const timeout = 30000; - const wsUrl = `${getters['getWebSocketEndpoint']}/chain/${chain_name}/rpc/websocket`; + const wsUrl = `${getters[GlobalGetterTypes.API.getWebSocketEndpoint]}/chain/${chain_name}/rpc/websocket`; const wss = new TendermintWS({ server: wsUrl, timeout: 5000, autoReconnect: false }); await wss.connect().catch(reject); @@ -223,7 +165,10 @@ export const actions: ActionTree & Actions = { }); }, - async [ActionTypes.GET_END_BLOCK_EVENTS]({ getters, rootGetters }, { height, stepType }: DemerisTxResultParams) { + async [ActionTypes.GET_END_BLOCK_EVENTS]( + { getters, rootGetters }: APIActionContext, + { height, stepType }: DemerisTxResultParams, + ): Promise { axios.defaults.headers.get['X-Correlation-Id'] = rootGetters[GlobalGetterTypes.USER.getCorrelationId]; function sleep(ms) { return new Promise((resolve) => setTimeout(resolve, ms)); @@ -231,7 +176,7 @@ export const actions: ActionTree & Actions = { try { await sleep(800); // Apparently it takes some time for end block events to be available on the rpc endpoint after the tx is delivered and our tx ticket updates so this is why this was added originally. - const response = await axios.get(`${getters['getEndpoint']}/block_results?height=${height}`); + const response = await axios.get(`${getters[GlobalGetterTypes.API.getEndpoint]}/block_results?height=${height}`); const successData = {}; if (response.data.result?.end_block_events) { @@ -239,7 +184,7 @@ export const actions: ActionTree & Actions = { const checks = getEndBlockChecks({ type: stepType, - requesterAddress: await getOwnAddress({ chain_name: getters['getDexChain'] }), + requesterAddress: await getOwnAddress({ chain_name: getters[GlobalGetterTypes.API.getDexChain] }), }); response.data.result?.end_block_events?.forEach((item) => { @@ -282,7 +227,7 @@ export const actions: ActionTree & Actions = { // Internal module actions [ActionTypes.INIT]( - { commit, dispatch }, + { commit, dispatch }: APIActionContext, { endpoint, gitEndpoint, @@ -291,8 +236,8 @@ export const actions: ActionTree & Actions = { hub_chain = 'cosmos-hub', refreshTime = 5000, gas_limit = 500000, - }, - ) { + }: DemerisConfig, + ): void { console.log('Vuex nodule: demeris initialized!'); commit(MutationTypes.INIT, { wsEndpoint, endpoint, gitEndpoint, rawGitEndpoint, hub_chain, gas_limit }); if (!featureRunning('DEBUG')) { @@ -301,10 +246,10 @@ export const actions: ActionTree & Actions = { }, refreshTime); } }, - [ActionTypes.RESET_STATE]({ commit }) { + [ActionTypes.RESET_STATE]({ commit }: APIActionContext): void { commit(MutationTypes.RESET_STATE); }, - async [ActionTypes.SIGN_OUT]({ commit, state }, keyHashes) { + async [ActionTypes.SIGN_OUT]({ commit, state }: APIActionContext, keyHashes: string[]): Promise { commit(MutationTypes.CLEAR_SUBSCRIPTIONS); // Although on the CLEAR_SUBSCRIPTIONS mutation we remove any subscriptions from the previously signed in account // there is a chance some requests were already in progress and may return after we clear them so we await completion @@ -312,7 +257,7 @@ export const actions: ActionTree & Actions = { await Promise.all(state._InProgess.values()); commit(MutationTypes.SIGN_OUT, keyHashes); }, - [ActionTypes.STORE_UPDATE]({ state, dispatch }) { + [ActionTypes.STORE_UPDATE]({ state, dispatch }: APIActionContext): void { state._Subscriptions.forEach(async (subscription_json) => { const subscription = JSON.parse(subscription_json); try { @@ -322,7 +267,7 @@ export const actions: ActionTree & Actions = { } }); }, - [ActionTypes.UNSUBSCRIBE]({ commit }, subscription) { + [ActionTypes.UNSUBSCRIBE]({ commit }: APIActionContext, subscription: Subscription): void { commit(MutationTypes.UNSUBSCRIBE, subscription); }, }; diff --git a/src/store/demeris-api/actions/airdrops.ts b/src/store/demeris-api/actions/airdrops.ts index 03da2251d..f5e93a787 100644 --- a/src/store/demeris-api/actions/airdrops.ts +++ b/src/store/demeris-api/actions/airdrops.ts @@ -3,7 +3,7 @@ import { EmerisAirdrops } from '@emeris/types'; import axios, { AxiosResponse } from 'axios'; import { ActionTree } from 'vuex'; -import { RootState } from '@/store'; +import { GlobalGetterTypes, RootState } from '@/store'; import { ActionParams, LoadingState, SimpleSubscribable, Subscribable } from '@/types/util'; import { getAirdropEligibility } from '@/utils/airdropEligibility'; import EmerisError from '@/utils/EmerisError'; @@ -18,24 +18,14 @@ export type GitAirdropsListReq = { checkEligibility: boolean; }; -export interface AirdropActionsInterface { - //Airdrops Action types - [ActionTypes.GET_GIT_AIRDROPS_LIST]( - context: APIActionContext, - payload: SimpleSubscribable, - ): Promise; - [ActionTypes.GET_AIRDROPS]( - context: APIActionContext, - payload: Subscribable>, - ): Promise; - [ActionTypes.RESET_AIRDROPS](context: APIActionContext): void; -} - -export const AirdropActions: ActionTree & AirdropActionsInterface = { +export const AirdropActions: ActionTree = { /** * Chain Logic Action types */ - async [ActionTypes.GET_GIT_AIRDROPS_LIST]({ commit }, { subscribe = false }) { + async [ActionTypes.GET_GIT_AIRDROPS_LIST]( + { commit }: APIActionContext, + { subscribe = false }: SimpleSubscribable, + ): Promise { try { delete axios.defaults.headers.get['X-Correlation-Id']; const response: AxiosResponse = await axios.get( @@ -49,7 +39,10 @@ export const AirdropActions: ActionTree & AirdropActionsInt throw new EmerisError('Demeris:gitAirdropsList', 'Could not perform API query.'); } }, - async [ActionTypes.GET_AIRDROPS]({ commit, getters }, { subscribe = false, params }) { + async [ActionTypes.GET_AIRDROPS]( + { commit, getters }: APIActionContext, + { subscribe = false, params }: Subscribable>, + ): Promise { let eligibility = null; commit(MutationTypes.SET_AIRDROPS_STATUS, { value: LoadingState.LOADING, @@ -57,7 +50,9 @@ export const AirdropActions: ActionTree & AirdropActionsInt try { delete axios.defaults.headers.get['X-Correlation-Id']; const response = await axios.get( - `${getters['getRawGitEndpoint']}/EmerisHQ/Emeris-Airdrop/main/airdropList/${params.airdropFileName}`, + `${getters[GlobalGetterTypes.API.getRawGitEndpoint]}/EmerisHQ/Emeris-Airdrop/main/airdropList/${ + params.airdropFileName + }`, ); if (params.checkEligibility) { @@ -85,7 +80,7 @@ export const AirdropActions: ActionTree & AirdropActionsInt throw new EmerisError('Demeris:getAirdrops', 'Could not perform API query.'); } }, - [ActionTypes.RESET_AIRDROPS]({ commit }) { + [ActionTypes.RESET_AIRDROPS]({ commit }: APIActionContext): void { commit(MutationTypes.RESET_AIRDROPS); }, }; diff --git a/src/store/demeris-api/actions/balances.ts b/src/store/demeris-api/actions/balances.ts index f70a29b49..6f3f55dbe 100644 --- a/src/store/demeris-api/actions/balances.ts +++ b/src/store/demeris-api/actions/balances.ts @@ -15,42 +15,22 @@ import { MutationTypes } from '../mutation-types'; import { APIState } from '../state'; import { APIActionContext } from './api-action-context-type'; -export interface BalanceActionsInterface { - //Balances Action types - [ActionTypes.GET_BALANCES]( - context: APIActionContext, - payload: Subscribable>, - ): Promise; - [ActionTypes.GET_POOL_BALANCES]( - context: APIActionContext, - payload: Subscribable>, - ): Promise; - [ActionTypes.GET_STAKING_BALANCES]( - context: APIActionContext, - payload: Subscribable>, - ): Promise; - [ActionTypes.GET_UNBONDING_DELEGATIONS]( - context: APIActionContext, - payload: Subscribable>, - ): Promise; - [ActionTypes.GET_ALL_BALANCES](context: APIActionContext, payload?: Subscribable): Promise; - [ActionTypes.GET_ALL_STAKING_BALANCES](context: APIActionContext): Promise; - [ActionTypes.GET_ALL_UNBONDING_DELEGATIONS](context: APIActionContext): Promise; -} - -export const BalanceActions: ActionTree & BalanceActionsInterface = { +export const BalanceActions: ActionTree = { /** * Balances Logic Action types */ // eslint-disable-next-line @typescript-eslint/no-empty-function - async [ActionTypes.GET_BALANCES]({ commit, dispatch, getters, state, rootGetters }, { subscribe = false, params }) { + async [ActionTypes.GET_BALANCES]( + { commit, dispatch, getters, state, rootGetters }: APIActionContext, + { subscribe = false, params }: Subscribable>, + ): Promise { axios.defaults.headers.get['X-Correlation-Id'] = rootGetters[GlobalGetterTypes.USER.getCorrelationId]; const reqHash = hashObject({ action: ActionTypes.GET_BALANCES, payload: { params } }); if (state._InProgess.get(reqHash)) { await state._InProgess.get(reqHash); - return getters['getBalances'](params); + return getters[GlobalGetterTypes.API.getBalances](params); } else { let resolver; let rejecter; @@ -61,7 +41,7 @@ export const BalanceActions: ActionTree & BalanceActionsInt commit(MutationTypes.SET_IN_PROGRESS, { hash: reqHash, promise }); try { const response: AxiosResponse = await axios.get( - getters['getEndpoint'] + '/account/' + params.address + '/balance', + `${getters[GlobalGetterTypes.API.getEndpoint]}/account/${params.address}/balance`, ); if (response.data.balances) { @@ -70,7 +50,7 @@ export const BalanceActions: ActionTree & BalanceActionsInt if ( // balance.ibc holds resolved ibc denoms so we can show the name of the coin. this functions as a cache. so if it was loaded in the past we don't need to load it again. Object.keys(balance.ibc).length != 0 && - !getters['getVerifyTrace']({ + !getters[GlobalGetterTypes.API.getVerifyTrace]({ chain_name: balance.on_chain, hash: balance.ibc.hash, }) @@ -100,17 +80,20 @@ export const BalanceActions: ActionTree & BalanceActionsInt } commit(MutationTypes.DELETE_IN_PROGRESS, reqHash); resolver(); - return getters['getBalances'](params); + return getters[GlobalGetterTypes.API.getBalances](params); } }, - async [ActionTypes.GET_POOL_BALANCES]({ commit, getters, state, rootGetters }, { subscribe = false, params }) { + async [ActionTypes.GET_POOL_BALANCES]( + { commit, getters, state, rootGetters }: APIActionContext, + { subscribe = false, params }: Subscribable>, + ): Promise { axios.defaults.headers.get['X-Correlation-Id'] = rootGetters[GlobalGetterTypes.USER.getCorrelationId]; const reqHash = hashObject({ action: ActionTypes.GET_POOL_BALANCES, payload: { params } }); if (state._InProgess.get(reqHash)) { await state._InProgess.get(reqHash); - return getters['getBalances'](params); + return getters[GlobalGetterTypes.API.getBalances](params); } else { let resolver; let rejecter; @@ -121,7 +104,7 @@ export const BalanceActions: ActionTree & BalanceActionsInt commit(MutationTypes.SET_IN_PROGRESS, { hash: reqHash, promise }); try { const response: AxiosResponse = await axios.get( - getters['getEndpoint'] + '/account/' + params.address + '/balance', + `${getters[GlobalGetterTypes.API.getEndpoint]}/account/${params.address}/balance`, ); commit(MutationTypes.SET_POOL_BALANCES, { params, value: response.data.balances }); @@ -139,17 +122,20 @@ export const BalanceActions: ActionTree & BalanceActionsInt commit(MutationTypes.DELETE_IN_PROGRESS, reqHash); resolver(); - return getters['getBalances'](params); + return getters[GlobalGetterTypes.API.getBalances](params); } }, - async [ActionTypes.GET_ALL_BALANCES]({ dispatch, getters, rootGetters }, params) { + async [ActionTypes.GET_ALL_BALANCES]( + { dispatch, getters, rootGetters }: APIActionContext, + params?: Subscribable, + ): Promise { try { const keyHashes = rootGetters[GlobalGetterTypes.USER.getKeyhashes]; const balanceLoads = []; const chains = - getters['getChains'] ?? + getters[GlobalGetterTypes.API.getChains] ?? (await dispatch(ActionTypes.GET_CHAINS, { subscribe: featureRunning('USE_NEW_CHAINS_API'), })); @@ -176,9 +162,13 @@ export const BalanceActions: ActionTree & BalanceActionsInt } catch (e) { throw new EmerisError('Demeris:GetAllBalances', 'Could not perform API query.'); } - return getters['getAllBalances']; + return getters[GlobalGetterTypes.API.getAllBalances]; }, - async [ActionTypes.GET_ALL_STAKING_BALANCES]({ dispatch, getters, rootGetters }) { + async [ActionTypes.GET_ALL_STAKING_BALANCES]({ + dispatch, + getters, + rootGetters, + }: APIActionContext): Promise { try { const keyHashes = rootGetters[GlobalGetterTypes.USER.getKeyhashes]; @@ -196,9 +186,13 @@ export const BalanceActions: ActionTree & BalanceActionsInt } catch (e) { throw new EmerisError('Demeris:GetAllStakingBalances', 'Could not perform API query.'); } - return getters['getAllStakingBalances']; + return getters[GlobalGetterTypes.API.getAllStakingBalances]; }, - async [ActionTypes.GET_ALL_UNBONDING_DELEGATIONS]({ dispatch, getters, rootGetters }) { + async [ActionTypes.GET_ALL_UNBONDING_DELEGATIONS]({ + dispatch, + getters, + rootGetters, + }: APIActionContext): Promise { try { const keyHashes = rootGetters[GlobalGetterTypes.USER.getKeyhashes]; for (const keyHash of keyHashes) { @@ -207,16 +201,19 @@ export const BalanceActions: ActionTree & BalanceActionsInt } catch (e) { throw new EmerisError('Demeris:GetAllUnbondingDelegations', 'Could not perform API query.'); } - return getters['getAllUnbondingDelegations']; + return getters[GlobalGetterTypes.API.getAllUnbondingDelegations]; }, - async [ActionTypes.GET_STAKING_BALANCES]({ commit, getters, state, rootGetters }, { subscribe = false, params }) { + async [ActionTypes.GET_STAKING_BALANCES]( + { commit, getters, state, rootGetters }: APIActionContext, + { subscribe = false, params }: Subscribable>, + ): Promise { axios.defaults.headers.get['X-Correlation-Id'] = rootGetters[GlobalGetterTypes.USER.getCorrelationId]; const reqHash = hashObject({ action: ActionTypes.GET_STAKING_BALANCES, payload: { params } }); if (state._InProgess.get(reqHash)) { await state._InProgess.get(reqHash); - return getters['getStakingBalances'](params); + return getters[GlobalGetterTypes.API.getStakingBalances](params); } else { let resolver; let rejecter; @@ -227,7 +224,7 @@ export const BalanceActions: ActionTree & BalanceActionsInt commit(MutationTypes.SET_IN_PROGRESS, { hash: reqHash, promise }); try { const response: AxiosResponse = await axios.get( - getters['getEndpoint'] + '/account/' + params.address + '/stakingbalances', + `${getters[GlobalGetterTypes.API.getEndpoint]}/account/${params.address}/stakingbalances`, ); commit(MutationTypes.SET_STAKING_BALANCES, { params, value: response.data.staking_balances }); if (subscribe) { @@ -244,20 +241,20 @@ export const BalanceActions: ActionTree & BalanceActionsInt commit(MutationTypes.DELETE_IN_PROGRESS, reqHash); resolver(); - return getters['getStakingBalances'](params); + return getters[GlobalGetterTypes.API.getStakingBalances](params); } }, async [ActionTypes.GET_UNBONDING_DELEGATIONS]( - { commit, getters, state, rootGetters }, - { subscribe = false, params }, - ) { + { commit, getters, state, rootGetters }: APIActionContext, + { subscribe = false, params }: Subscribable>, + ): Promise { axios.defaults.headers.get['X-Correlation-Id'] = rootGetters[GlobalGetterTypes.USER.getCorrelationId]; const reqHash = hashObject({ action: ActionTypes.GET_UNBONDING_DELEGATIONS, payload: { params } }); if (state._InProgess.get(reqHash)) { await state._InProgess.get(reqHash); - return getters['getUnbondingDelegations'](params); + return getters[GlobalGetterTypes.API.getUnbondingDelegations](params); } else { let resolver; let rejecter; @@ -268,7 +265,7 @@ export const BalanceActions: ActionTree & BalanceActionsInt commit(MutationTypes.SET_IN_PROGRESS, { hash: reqHash, promise }); try { const response: AxiosResponse = await axios.get( - getters['getEndpoint'] + '/account/' + params.address + '/unbondingdelegations', + getters[GlobalGetterTypes.API.getEndpoint] + '/account/' + params.address + '/unbondingdelegations', ); commit(MutationTypes.SET_UNBONDING_DELEGATIONS, { params, value: response.data.unbonding_delegations }); if (subscribe) { @@ -285,7 +282,7 @@ export const BalanceActions: ActionTree & BalanceActionsInt commit(MutationTypes.DELETE_IN_PROGRESS, reqHash); resolver(); - return getters['getUnbondingDelegations'](params); + return getters[GlobalGetterTypes.API.getUnbondingDelegations](params); } }, }; diff --git a/src/store/demeris-api/actions/chain.ts b/src/store/demeris-api/actions/chain.ts index 3916d6494..81739d081 100644 --- a/src/store/demeris-api/actions/chain.ts +++ b/src/store/demeris-api/actions/chain.ts @@ -14,38 +14,21 @@ import { MutationTypes } from '../mutation-types'; import { APIState } from '../state'; import { APIActionContext } from './api-action-context-type'; -export interface ChainActionsInterface { - //Chain Action Types - [ActionTypes.GET_CHAIN]( - context: APIActionContext, - payload: Subscribable>, - ): Promise; - [ActionTypes.GET_CHAIN_STATUS]( - context: APIActionContext, - payload: Subscribable>, - ): Promise; - [ActionTypes.GET_CHAINS]( - context: APIActionContext, - payload: SimpleSubscribable, - ): Promise>; - [ActionTypes.GET_CHAINS_AND_CHAIN_STATUS]( - context: APIActionContext, - payload: SimpleSubscribable, - ): Promise>; -} - -export const ChainActions: ActionTree & ChainActionsInterface = { +export const ChainActions: ActionTree = { /** * Chain Logic Action types */ - async [ActionTypes.GET_CHAIN]({ commit, getters, state, rootGetters }, { subscribe = false, params }) { + async [ActionTypes.GET_CHAIN]( + { commit, getters, state, rootGetters }: APIActionContext, + { subscribe = false, params }: Subscribable>, + ): Promise { axios.defaults.headers.get['X-Correlation-Id'] = rootGetters[GlobalGetterTypes.USER.getCorrelationId]; const reqHash = hashObject({ action: ActionTypes.GET_CHAIN, payload: { params } }); if (state._InProgess.get(reqHash)) { await state._InProgess.get(reqHash); - return getters['getChain'](params); + return getters[GlobalGetterTypes.API.getChain](params); } else { let resolver; let rejecter; @@ -56,7 +39,7 @@ export const ChainActions: ActionTree & ChainActionsInterfa commit(MutationTypes.SET_IN_PROGRESS, { hash: reqHash, promise }); try { const response: AxiosResponse = await axios.get( - getters['getEndpoint'] + '/chain/' + params.chain_name, + `${getters[GlobalGetterTypes.API.getEndpoint]}/chain/${params.chain_name}`, ); commit(MutationTypes.SET_CHAIN, { params, value: { ...response.data.chain, status: true } }); if (subscribe) { @@ -72,17 +55,20 @@ export const ChainActions: ActionTree & ChainActionsInterfa } resolver(); commit(MutationTypes.DELETE_IN_PROGRESS, reqHash); - return getters['getChain'](params); + return getters[GlobalGetterTypes.API.getChain](params); } }, - async [ActionTypes.GET_CHAIN_STATUS]({ commit, getters, state, rootGetters }, { subscribe = false, params }) { + async [ActionTypes.GET_CHAIN_STATUS]( + { commit, getters, state, rootGetters }: APIActionContext, + { subscribe = false, params }, + ): Promise { axios.defaults.headers.get['X-Correlation-Id'] = rootGetters[GlobalGetterTypes.USER.getCorrelationId]; const reqHash = hashObject({ action: ActionTypes.GET_CHAIN_STATUS, payload: { params } }); if (state._InProgess.get(reqHash)) { await state._InProgess.get(reqHash); - return getters['getChainStatus'](params); + return getters[GlobalGetterTypes.API.getChainStatus](params); } else { let resolver; let rejecter; @@ -93,7 +79,7 @@ export const ChainActions: ActionTree & ChainActionsInterfa commit(MutationTypes.SET_IN_PROGRESS, { hash: reqHash, promise }); try { const response: AxiosResponse = await axios.get( - getters['getEndpoint'] + '/chain/' + params.chain_name + '/status', + `${getters[GlobalGetterTypes.API.getEndpoint]}/chain/${params.chain_name}/status`, ); commit(MutationTypes.SET_CHAIN_STATUS, { params, value: response.data.online }); if (subscribe) { @@ -109,16 +95,19 @@ export const ChainActions: ActionTree & ChainActionsInterfa } resolver(); commit(MutationTypes.DELETE_IN_PROGRESS, reqHash); - return getters['getChainStatus'](params); + return getters[GlobalGetterTypes.API.getChainStatus](params); } }, - async [ActionTypes.GET_CHAINS]({ commit, getters, rootGetters, state }, { subscribe = false }) { + async [ActionTypes.GET_CHAINS]( + { commit, getters, rootGetters, state }: APIActionContext, + { subscribe = false }: SimpleSubscribable, + ): Promise> { axios.defaults.headers.get['X-Correlation-Id'] = rootGetters[GlobalGetterTypes.USER.getCorrelationId]; const reqHash = hashObject({ action: ActionTypes.GET_CHAINS, payload: {} }); if (state._InProgess.get(reqHash)) { await state._InProgess.get(reqHash); - return getters['getChains']; + return getters[GlobalGetterTypes.API.getChains]; } let resolver; const promise: Promise = new Promise((resolve, _) => { @@ -126,7 +115,9 @@ export const ChainActions: ActionTree & ChainActionsInterfa }); try { commit(MutationTypes.SET_IN_PROGRESS, { hash: reqHash, promise }); - const response: AxiosResponse = await axios.get(getters['getEndpoint'] + '/chains'); + const response: AxiosResponse = await axios.get( + `${getters[GlobalGetterTypes.API.getEndpoint]}/chains`, + ); commit(MutationTypes.SET_CHAINS, { value: response.data.chains }); if (subscribe) { commit(MutationTypes.SUBSCRIBE, { action: ActionTypes.GET_CHAINS, payload: {} }); @@ -136,9 +127,12 @@ export const ChainActions: ActionTree & ChainActionsInterfa } resolver(); commit(MutationTypes.DELETE_IN_PROGRESS, reqHash); - return getters['getChains']; + return getters[GlobalGetterTypes.API.getChains]; }, - async [ActionTypes.GET_CHAINS_AND_CHAIN_STATUS]({ dispatch, getters }, { subscribe = false }) { + async [ActionTypes.GET_CHAINS_AND_CHAIN_STATUS]( + { dispatch, getters }: APIActionContext, + { subscribe = false }: SimpleSubscribable, + ): Promise> { if (featureRunning('USE_NEW_CHAINS_API')) { dispatch(ActionTypes.GET_CHAINS, { subscribe: true, @@ -168,6 +162,6 @@ export const ChainActions: ActionTree & ChainActionsInterfa console.error('Could not load chain information: ' + e); }); } - return getters['getChains']; + return getters[GlobalGetterTypes.API.getChains]; }, }; diff --git a/src/store/demeris-api/actions/prices.ts b/src/store/demeris-api/actions/prices.ts index 7149e48b5..c6889ced5 100644 --- a/src/store/demeris-api/actions/prices.ts +++ b/src/store/demeris-api/actions/prices.ts @@ -15,34 +15,21 @@ import { MutationTypes } from '../mutation-types'; import { APIState } from '../state'; import { APIActionContext } from './api-action-context-type'; -export interface PriceActionsInterface { - //Prices Action types - [ActionTypes.GET_PRICES](context: APIActionContext, payload: SimpleSubscribable): Promise; - [ActionTypes.GET_TOKEN_PRICES]( - context: APIActionContext, - payload: Subscribable>, - ): Promise; - [ActionTypes.RESET_TOKEN_PRICES](context: APIActionContext): void; - - //Coingecko Action types - [ActionTypes.GET_COINGECKO_ID_BY_NAMES]( - context: APIActionContext, - payload: Subscribable>, - ): Promise; -} - -export const PriceActions: ActionTree & PriceActionsInterface = { +export const PriceActions: ActionTree = { /** * Staking Logic Action types */ - async [ActionTypes.GET_PRICES]({ commit, getters, rootGetters, state, dispatch }, { subscribe = false }) { + async [ActionTypes.GET_PRICES]( + { commit, getters, rootGetters, state, dispatch }: APIActionContext, + { subscribe = false }: SimpleSubscribable, + ): Promise { axios.defaults.headers.get['X-Correlation-Id'] = rootGetters[GlobalGetterTypes.USER.getCorrelationId]; const reqHash = hashObject({ action: ActionTypes.GET_PRICES, payload: {} }); if (state._InProgess.get(reqHash)) { await state._InProgess.get(reqHash); - return getters['getPrices']; + return getters[GlobalGetterTypes.API.getPrices]; } else { let resolver; let rejecter; @@ -53,14 +40,14 @@ export const PriceActions: ActionTree & PriceActionsInterfa commit(MutationTypes.SET_IN_PROGRESS, { hash: reqHash, promise }); try { const response: AxiosResponse = await axios.get( - getters['getEndpoint'] + '/oracle/prices', + `${getters[GlobalGetterTypes.API.getEndpoint]}/oracle/prices`, ); if (response.data?.data?.Tokens) { commit(MutationTypes.SET_PRICES, { value: response.data.data }); // Set initial prices so pool calculations can find them await Promise.all( - getters['getVerifiedDenoms'].map(async (denom) => { + getters[GlobalGetterTypes.API.getVerifiedDenoms].map(async (denom) => { if (denom.name.startsWith('pool')) { const pools = rootGetters['tendermint.liquidity.v1beta1/getLiquidityPools']().pools; @@ -106,17 +93,22 @@ export const PriceActions: ActionTree & PriceActionsInterfa } commit(MutationTypes.DELETE_IN_PROGRESS, reqHash); resolver(); - return getters['getPrices']; + return getters[GlobalGetterTypes.API.getPrices]; } }, - async [ActionTypes.GET_TOKEN_PRICES]({ commit, getters, rootGetters }, { subscribe = false, params }) { + async [ActionTypes.GET_TOKEN_PRICES]( + { commit, getters, rootGetters }: APIActionContext, + { subscribe = false, params }: Subscribable>, + ): Promise { axios.defaults.headers.get['X-Correlation-Id'] = rootGetters[GlobalGetterTypes.USER.getCorrelationId]; commit(MutationTypes.SET_TOKEN_PRICES_STATUS, { value: params.showSkeleton ? LoadingState.LOADING : LoadingState.LOADED, }); try { const response: AxiosResponse = await axios.get( - getters['getEndpoint'] + `/oracle/chart/${params.token_id}?days=${params.days}&vs_currency=${params.currency}`, + `${getters[GlobalGetterTypes.API.getEndpoint]}/oracle/chart/${params.token_id}?days=${ + params.days + }&vs_currency=${params.currency}`, ); commit(MutationTypes.SET_TOKEN_PRICES, { value: response.data.data.prices }); commit(MutationTypes.SET_TOKEN_PRICES_STATUS, { value: LoadingState.LOADED }); @@ -127,25 +119,28 @@ export const PriceActions: ActionTree & PriceActionsInterfa commit(MutationTypes.SET_TOKEN_PRICES_STATUS, { value: LoadingState.ERROR }); throw new EmerisError('Demeris:getTokenPrices', 'Could not perform API query.'); } - return getters['getTokenPrices']; + return getters[GlobalGetterTypes.API.getTokenPrices]; }, - [ActionTypes.RESET_TOKEN_PRICES]({ commit }) { + [ActionTypes.RESET_TOKEN_PRICES]({ commit }: APIActionContext): void { commit(MutationTypes.SET_TOKEN_PRICES, { value: [] }); }, // Coingecko Actions - async [ActionTypes.GET_COINGECKO_ID_BY_NAMES]({ commit, getters, rootGetters }, { params }) { + async [ActionTypes.GET_COINGECKO_ID_BY_NAMES]( + { commit, getters, rootGetters }: APIActionContext, + { params }: Subscribable>, + ): Promise { axios.defaults.headers.get['X-Correlation-Id'] = rootGetters[GlobalGetterTypes.USER.getCorrelationId]; commit(MutationTypes.SET_COINGECKO_ID_STATUS, { value: LoadingState.LOADING, }); try { const response: AxiosResponse = await axios.get( - getters['getEndpoint'] + `/oracle/geckoid?names=${params.token}`, + `${getters[GlobalGetterTypes.API.getEndpoint]}/oracle/geckoid?names=${params.token}`, ); commit(MutationTypes.SET_COINGECKO_ID, { params: params.token, value: response.data }); commit(MutationTypes.SET_COINGECKO_ID_STATUS, { value: LoadingState.LOADED }); - return getters['getCoinGeckoId']; + return getters[GlobalGetterTypes.API.getCoinGeckoId]; } catch (e) { commit(MutationTypes.SET_COINGECKO_ID_STATUS, { value: LoadingState.ERROR }); console.error('Demeris:getCoinGeckoId: Could not perform API query.'); diff --git a/src/store/demeris-api/actions/staking.ts b/src/store/demeris-api/actions/staking.ts index eac710635..d7d335ee1 100644 --- a/src/store/demeris-api/actions/staking.ts +++ b/src/store/demeris-api/actions/staking.ts @@ -13,39 +13,18 @@ import { MutationTypes } from '../mutation-types'; import { APIState } from '../state'; import { APIActionContext } from './api-action-context-type'; -export interface StakingActionsInterface { - //Staking Action types - [ActionTypes.GET_INFLATION]( - context: APIActionContext, - payload: Subscribable>, - ): Promise; - [ActionTypes.GET_STAKING_REWARDS]( - context: APIActionContext, - payload: Subscribable>, - ): Promise; - [ActionTypes.GET_UNSTAKING_PARAM]( - context: APIActionContext, - payload: Subscribable>, - ): Promise; - [ActionTypes.GET_VALIDATORS]( - context: APIActionContext, - payload: Subscribable>, - ): Promise; - [ActionTypes.GET_CHAIN_APR]( - context: APIActionContext, - payload: Subscribable>, - ): Promise; -} - -export const StakingActions: ActionTree & StakingActionsInterface = { +export const StakingActions: ActionTree = { /** * Staking Logic Action types */ - async [ActionTypes.GET_INFLATION]({ getters, rootGetters }, { subscribe: _subscribe, params: { chain_name } }) { + async [ActionTypes.GET_INFLATION]( + { getters, rootGetters }: APIActionContext, + { subscribe: _subscribe, params: { chain_name } }: Subscribable>, + ): Promise { axios.defaults.headers.get['X-Correlation-Id'] = rootGetters[GlobalGetterTypes.USER.getCorrelationId]; try { const response: AxiosResponse = await axios.get( - getters['getEndpoint'] + '/chain/' + chain_name + '/mint/inflation', + `${getters[GlobalGetterTypes.API.getEndpoint]}/chain/${chain_name}/mint/inflation`, ); return Number(response.data?.inflation); } catch (e) { @@ -53,12 +32,15 @@ export const StakingActions: ActionTree & StakingActionsInt } }, - async [ActionTypes.GET_STAKING_REWARDS]({ getters, rootGetters }, { subscribe: _subscribe, params: { chain_name } }) { + async [ActionTypes.GET_STAKING_REWARDS]( + { getters, rootGetters }: APIActionContext, + { subscribe: _subscribe, params: { chain_name } }: Subscribable>, + ): Promise { axios.defaults.headers.get['X-Correlation-Id'] = rootGetters[GlobalGetterTypes.USER.getCorrelationId]; try { const address = keyHashfromAddress(await getOwnAddress({ chain_name })); const response: AxiosResponse = await axios.get( - getters['getEndpoint'] + '/account/' + address + '/delegatorrewards/' + chain_name, + `${getters[GlobalGetterTypes.API.getEndpoint]}/account/${address}/delegatorrewards/${chain_name}`, ); return response.data; } catch (e) { @@ -67,29 +49,29 @@ export const StakingActions: ActionTree & StakingActionsInt }, async [ActionTypes.GET_UNSTAKING_PARAM]( - { commit, getters }, - { subscribe: _subscribe, params: { chain_name } }, + { commit, getters }: APIActionContext, + { subscribe: _subscribe, params: { chain_name } }: Subscribable>, ): Promise { try { const { data: { params: unstakingParam }, - } = await axios.get(`${getters['getEndpoint']}/chain/${chain_name}/staking/params`); + } = await axios.get(`${getters[GlobalGetterTypes.API.getEndpoint]}/chain/${chain_name}/staking/params`); commit(MutationTypes.SET_UNSTAKING_PARAM, { params: { chain_name }, value: unstakingParam }); - return getters['getUnstakingParam']({ chain_name }); + return getters[GlobalGetterTypes.API.getUnstakingParam]({ chain_name }); } catch { throw new EmerisError('Demeris:getUnstakingParam', 'Could not retrieve staking param.'); } }, async [ActionTypes.GET_CHAIN_APR]( - { commit, getters, state, rootGetters }, - { params }: { params: EmerisAPI.ChainReq }, + { commit, getters, state, rootGetters }: APIActionContext, + { params }: Subscribable>, ): Promise { axios.defaults.headers.get['X-Correlation-Id'] = rootGetters[GlobalGetterTypes.USER.getCorrelationId]; const reqHash = hashObject({ action: ActionTypes.GET_CHAIN_APR, payload: { params } }); if (state._InProgess.get(reqHash)) { await state._InProgess.get(reqHash); - return getters['getChainAPR'](params); + return getters[GlobalGetterTypes.API.getChainAPR](params); } let resolver; const promise: Promise = new Promise((resolve, _) => { @@ -98,7 +80,7 @@ export const StakingActions: ActionTree & StakingActionsInt commit(MutationTypes.SET_IN_PROGRESS, { hash: reqHash, promise }); try { const response: AxiosResponse = await axios.get( - getters['getEndpoint'] + '/chain/' + params.chain_name + '/apr', + `${getters[GlobalGetterTypes.API.getEndpoint]}/chain/${params.chain_name}/apr`, ); commit(MutationTypes.SET_CHAIN_APR, { params, value: response.data.apr ? response.data.apr : '0.00' }); } catch (e) { @@ -106,14 +88,17 @@ export const StakingActions: ActionTree & StakingActionsInt } resolver(); commit(MutationTypes.DELETE_IN_PROGRESS, reqHash); - return getters['getChainAPR'](params); + return getters[GlobalGetterTypes.API.getChainAPR](params); }, - async [ActionTypes.GET_VALIDATORS]({ getters, rootGetters }, { subscribe: _subscribe, params: { chain_name } }) { + async [ActionTypes.GET_VALIDATORS]( + { getters, rootGetters }: APIActionContext, + { subscribe: _subscribe, params: { chain_name } }: Subscribable>, + ): Promise { axios.defaults.headers.get['X-Correlation-Id'] = rootGetters[GlobalGetterTypes.USER.getCorrelationId]; try { const response: AxiosResponse = await axios.get( - getters['getEndpoint'] + '/chain/' + chain_name + '/validators', + `${getters[GlobalGetterTypes.API.getEndpoint]}/chain/${chain_name}/validators`, ); return response.data?.validators; } catch (e) { diff --git a/src/store/demeris-api/actions/transactions.ts b/src/store/demeris-api/actions/transactions.ts index de017f45a..70541bc94 100644 --- a/src/store/demeris-api/actions/transactions.ts +++ b/src/store/demeris-api/actions/transactions.ts @@ -15,29 +15,20 @@ import { MutationTypes } from '../mutation-types'; import { APIState } from '../state'; import { APIActionContext } from './api-action-context-type'; -export interface TransactionActionsInterface { - //Transaction Logic Action types - [ActionTypes.GET_TX_STATUS]( - context: APIActionContext, - payload: Subscribable>, - ): Promise; - [ActionTypes.GET_NUMBERS_CHAIN]( - context: APIActionContext, - payload: Subscribable>, - ): Promise; -} - -export const TransactionActions: ActionTree & TransactionActionsInterface = { +export const TransactionActions: ActionTree = { /** * Gets sequence and account number. Used when making a transaction. * @param {string} chain_name - chain name * @param {string} address - address */ - async [ActionTypes.GET_NUMBERS_CHAIN]({ commit, getters, rootGetters }, { subscribe = false, params }) { + async [ActionTypes.GET_NUMBERS_CHAIN]( + { commit, getters, rootGetters }: APIActionContext, + { subscribe = false, params }: Subscribable>, + ): Promise { axios.defaults.headers.get['X-Correlation-Id'] = rootGetters[GlobalGetterTypes.USER.getCorrelationId]; try { const response: AxiosResponse = await axios.get( - getters['getEndpoint'] + '/chain/' + params.chain_name + '/numbers/' + params.address, + `${getters[GlobalGetterTypes.API.getEndpoint]}/chain/${params.chain_name}/numbers/${params.address}`, ); commit(MutationTypes.SET_NUMBERS_CHAIN, { params, value: response.data.numbers }); if (subscribe) { @@ -46,13 +37,16 @@ export const TransactionActions: ActionTree & TransactionAc } catch (e) { throw new EmerisError('Demeris:GetNumbersChain', 'Could not perform API query.'); } - return getters['getNumbersChain'](params); + return getters[GlobalGetterTypes.API.getNumbersChain](params); }, - async [ActionTypes.GET_TX_STATUS]({ commit, getters, rootGetters }, { subscribe = false, params }) { + async [ActionTypes.GET_TX_STATUS]( + { commit, getters, rootGetters }: APIActionContext, + { subscribe = false, params }: Subscribable>, + ): Promise { axios.defaults.headers.get['X-Correlation-Id'] = rootGetters[GlobalGetterTypes.USER.getCorrelationId]; try { const response: AxiosResponse = await axios.get( - getters['getEndpoint'] + '/tx/ticket/' + params.chain_name + '/' + params.ticket, + `${getters[GlobalGetterTypes.API.getEndpoint]}/tx/ticket/${params.chain_name}/${params.ticket}`, ); commit(MutationTypes.SET_TX_STATUS, { params, value: response.data }); if (subscribe) { @@ -62,13 +56,13 @@ export const TransactionActions: ActionTree & TransactionAc console.error(e); throw new EmerisError('Demeris:GetTXStatus', 'Could not perform API query.'); } - return getters['getTxStatus'](params); + return getters[GlobalGetterTypes.API.getTxStatus](params); }, async [ActionTypes.GET_TX_DEST_HASH]({ getters, rootGetters }, { from_chain, to_chain, txhash }) { axios.defaults.headers.get['X-Correlation-Id'] = rootGetters[GlobalGetterTypes.USER.getCorrelationId]; try { const response: AxiosResponse = await axios.get( - `${getters['getEndpoint']}/tx/${from_chain}/${to_chain}/${txhash}`, + `${getters[GlobalGetterTypes.API.getEndpoint]}/tx/${from_chain}/${to_chain}/${txhash}`, ); const data = response.data; @@ -93,7 +87,7 @@ export const TransactionActions: ActionTree & TransactionAc let timeoutId = undefined; let intervalId = undefined; - const wsUrl = `${getters['getWebSocketEndpoint']}/chain/${chain_name}/rpc/websocket`; + const wsUrl = `${getters[GlobalGetterTypes.API.getWebSocketEndpoint]}/chain/${chain_name}/rpc/websocket`; const wss = new TendermintWS({ server: wsUrl, timeout: 5000, autoReconnect: false }); const txHash64 = Buffer.from(txhash, 'hex').toString('base64'); @@ -196,7 +190,7 @@ export const TransactionActions: ActionTree & TransactionAc }, async [ActionTypes.GET_TX_FROM_RPC]({ getters }, { txhash, chain_name }) { - const rpcUrl = `${getters['getEndpoint']}/chain/${chain_name}/rpc`; + const rpcUrl = `${getters[GlobalGetterTypes.API.getEndpoint]}/chain/${chain_name}/rpc`; if (!rpcUrl) { throw new Error(`${chain_name} RPC endpoint not found`); diff --git a/src/store/demeris-api/getter-types.ts b/src/store/demeris-api/getter-types.ts index 09ebd07ed..8a1550c18 100644 --- a/src/store/demeris-api/getter-types.ts +++ b/src/store/demeris-api/getter-types.ts @@ -1,56 +1,4 @@ export enum GetterTypes { - getBalances = 'getBalances', - getStakingBalances = 'getStakingBalances', - getUnstakingParam = 'getUnstakingParam', - getUnbondingDelegations = 'getUnbondingDelegations', - getNumbers = 'getNumbers', - getNumbersChain = 'getNumbersChain', - getRelayerStatus = 'getRelayerStatus', - getRelayerBalance = 'getRelayerBalance', - getRelayerChainStatus = 'getRelayerChainStatus', - getAllBalances = 'getAllBalances', - getAllStakingBalances = 'getAllStakingBalances', - getAllUnbondingDelegations = 'getAllUnbondingDelegations', - getAllNumbers = 'getAllNumbers', - getFeeAddresses = 'getFeeAddresses', - isVerified = 'isVerified', - getVerifiedDenoms = 'getVerifiedDenoms', - getChains = 'getChains', - getChainAPR = 'getChainAPR', - getExchangeAmountFromATOMPool = 'getExchangeAmountFromATOMPool', - getPrices = 'getPrices', - getPrice = 'getPrice', - getTicker = 'getTicker', - getDisplayChain = 'getDisplayChain', - getChainFromChainId = 'getChainFromChainId', - getDenomPrecision = 'getDenomPrecision', - getEndpoint = 'getEndpoint', - getGitEndpoint = 'getGitEndpoint', - getRawGitEndpoint = 'getRawGitEndpoint', - getWebSocketEndpoint = 'getWebSocketEndpoint', - getAllValidPools = 'getAllValidPools', - getDexChain = 'getDexChain', - getTxStatus = 'getTxStatus', - getVerifyTrace = 'getVerifyTrace', - getFeeTokens = 'getFeeTokens', - getChain = 'getChain', - getSupply = 'getSupply', - getAllVerifiedTraces = 'getAllVerifiedTraces', - getBech32Config = 'getBech32Config', - getPrimaryChannel = 'getPrimaryChannel', - getPrimaryChannels = 'getPrimaryChannels', - getTokenPrices = 'getTokenPrices', - getTokenPricesLoadingStatus = 'getTokenPricesLoadingStatus', - getAirdrops = 'getAirdrops', - getAirdropsStatus = 'getAirdropsStatus', - getSelectedAirdrop = 'getSelectedAirdrop', - getChainStatus = 'getChainStatus', - getChainNameByBaseDenom = 'getChainNameByBaseDenom', - //coingecko - getCoinGeckoId = 'getCoinGeckoId', - getCoinGeckoIdLoadingStatus = 'getCoinGeckoIdLoadingStatus', -} -export enum GlobalGetterTypes { getBalances = 'demerisAPI/getBalances', getStakingBalances = 'demerisAPI/getStakingBalances', getUnstakingParam = 'demerisAPI/getUnstakingParam', @@ -59,7 +7,6 @@ export enum GlobalGetterTypes { getNumbersChain = 'demerisAPI/getNumbersChain', getRelayerStatus = 'demerisAPI/getRelayerStatus', getRelayerBalance = 'demerisAPI/getRelayerBalance', - getRelayerChainStatus = 'demerisAPI/getRelayerChainStatus', getAllBalances = 'demerisAPI/getAllBalances', getAllStakingBalances = 'demerisAPI/getAllStakingBalances', getAllUnbondingDelegations = 'demerisAPI/getAllUnbondingDelegations', diff --git a/src/store/demeris-api/getters.ts b/src/store/demeris-api/getters.ts index 74b515709..b2ccd493b 100644 --- a/src/store/demeris-api/getters.ts +++ b/src/store/demeris-api/getters.ts @@ -5,8 +5,9 @@ import BigNumber from 'bignumber.js'; import { GetterTree } from 'vuex'; import { RootState } from '@/store'; +import { GlobalGetterTypes } from '@/store'; import { Pool } from '@/types/actions'; -import { ChartPrices, LoadingState, Namespaced } from '@/types/util'; +import { ChartPrices, LoadingState } from '@/types/util'; import { keyHashfromAddress, parseCoins } from '@/utils/basic'; import { featureRunning } from '@/utils/FeatureManager'; @@ -14,94 +15,28 @@ import { GlobalGetterTypes as GlobalUserGetterTypes } from '../demeris-user'; import { GetterTypes } from './getter-types'; import { APIState } from './state'; -export type Getters = { - [GetterTypes.getBalances](state: APIState): { (params: EmerisAPI.AddrReq): EmerisAPI.Balances | null }; - [GetterTypes.getStakingBalances](state: APIState): { (params: EmerisAPI.AddrReq): EmerisAPI.StakingBalances | null }; - [GetterTypes.getUnstakingParam](state: APIState): { (params: EmerisAPI.ChainReq): EmerisAPI.StakingParams }; - [GetterTypes.getUnbondingDelegations](state: APIState): { - (params: EmerisAPI.AddrReq): EmerisAPI.UnbondingDelegations | null; - }; - [GetterTypes.getNumbersChain](state: APIState): { (params: EmerisAPI.ChainAddrReq): EmerisAPI.SeqNumber | null }; - [GetterTypes.getChainAPR](state: APIState): { (params: EmerisAPI.ChainReq): string }; - [GetterTypes.getRelayerChainStatus](state: APIState): { (params: EmerisAPI.ChainReq): boolean }; - [GetterTypes.getAllBalances](state: APIState, getters, rootState, rootGetters): EmerisAPI.Balances | null; - [GetterTypes.getAllStakingBalances](state: APIState): EmerisAPI.StakingBalances | null; - [GetterTypes.getAllUnbondingDelegations](state: APIState): EmerisAPI.UnbondingDelegations | null; - [GetterTypes.getVerifiedDenoms](state: APIState): EmerisAPI.VerifiedDenoms | null; - [GetterTypes.getChains](state: APIState): Record; - [GetterTypes.getPrices](state: APIState): EmerisAPI.Prices; - [GetterTypes.getExchangeAmountFromATOMPool](state: APIState, getters): { (base_denom: string): number }; - [GetterTypes.getPrice]( - state: APIState, - getters, - ): { - (params: { denom: string }): number; - }; - [GetterTypes.getTicker]( - state: APIState, - getters, - ): { - (params: { name: string }): string; - }; - [GetterTypes.getChainFromChainId](state: APIState): { - (chain_id: string): string; - }; - [GetterTypes.getDisplayChain](state: APIState): { - (params: { name: string }): string; - }; - [GetterTypes.getDenomPrecision](state: APIState): { - (params: { name: string }): number; - }; - [GetterTypes.getWebSocketEndpoint](state: APIState): string; - [GetterTypes.getAllValidPools](state: APIState): Pool[]; - [GetterTypes.getEndpoint](state: APIState): string; - [GetterTypes.getGitEndpoint](state: APIState): string; - [GetterTypes.getRawGitEndpoint](state: APIState): string; - [GetterTypes.getSupply](state: APIState, getters): { (params): number }; - [GetterTypes.getAllVerifiedTraces](state: APIState): Record; - [GetterTypes.getBech32Config](state: APIState): { (params: EmerisAPI.ChainReq): EmerisBase.Bech32Config | null }; - [GetterTypes.getDexChain](state: APIState): string; - [GetterTypes.getTxStatus](state: APIState): { - (params: EmerisAPI.TicketReq): Promise | null; - }; - [GetterTypes.isVerified](state: APIState): { - (params: { denom: string; chain_name: string }): boolean; - }; - [GetterTypes.getVerifyTrace](state: APIState): { (params: EmerisAPI.VerifyTraceReq): EmerisAPI.VerifyTrace | null }; - [GetterTypes.getFeeTokens](state: APIState): { (params: EmerisAPI.ChainReq): EmerisBase.Denom[] | null }; - [GetterTypes.getChain](state: APIState): { (params: EmerisAPI.ChainReq): EmerisAPI.Chain | null }; - [GetterTypes.getPrimaryChannel](state: APIState): { (params: EmerisAPI.ChainCounterPartyReq): string | null }; - [GetterTypes.getTokenPrices](state: APIState): ChartPrices | null; - [GetterTypes.getAirdrops](state: APIState): EmerisAirdrops.Airdrop[] | null; - [GetterTypes.getAirdropsStatus](state: APIState): LoadingState | null; - [GetterTypes.getSelectedAirdrop](state: APIState): EmerisAirdrops.Airdrop | null; - [GetterTypes.getChainStatus](state: APIState): { (params: EmerisAPI.ChainReq): boolean }; - [GetterTypes.getChainNameByBaseDenom](state: APIState): { (params: EmerisAPI.DenomReq): string }; - - // Coingecko Getters - [GetterTypes.getCoinGeckoId](state: APIState): string | null; -}; - -export type GlobalGetters = Namespaced; - -export const getters: GetterTree & Getters = { - [GetterTypes.getBalances]: (state) => (params) => { - return state.balances[params.address] ?? null; - }, - [GetterTypes.getStakingBalances]: (state) => (params) => { - return state.stakingBalances[params.address] ?? null; - }, - [GetterTypes.getUnstakingParam]: (state) => (params) => { - return state.unstakingParams[params.chain_name] ?? null; - }, - [GetterTypes.getUnbondingDelegations]: (state) => (params) => { - return state.unbondingDelegations[params.address] ?? null; - }, - - [GetterTypes.getRelayerChainStatus]: (_state) => (_params) => { - return true; - }, - [GetterTypes.getAllBalances]: (state: APIState, _getters, _rootState, rootGetters) => { +export const getters: GetterTree = { + [GetterTypes.getBalances]: + (state: APIState) => + (params: EmerisAPI.AddrReq): EmerisAPI.Balances | null => { + return state.balances[params.address] ?? null; + }, + [GetterTypes.getStakingBalances]: + (state: APIState) => + (params: EmerisAPI.AddrReq): EmerisAPI.StakingBalances | null => { + return state.stakingBalances[params.address] ?? null; + }, + [GetterTypes.getUnstakingParam]: + (state: APIState) => + (params: EmerisAPI.ChainReq): EmerisAPI.StakingParams => { + return state.unstakingParams[params.chain_name] ?? null; + }, + [GetterTypes.getUnbondingDelegations]: + (state: APIState) => + (params: EmerisAPI.AddrReq): EmerisAPI.UnbondingDelegations | null => { + return state.unbondingDelegations[params.address] ?? null; + }, + [GetterTypes.getAllBalances]: (state: APIState, _getters, _rootState, rootGetters): EmerisAPI.Balances | null => { if (!rootGetters[GlobalUserGetterTypes.getAccount]) { return null; } @@ -113,43 +48,49 @@ export const getters: GetterTree & Getters = { .filter((balance) => parseCoins(balance.amount)[0].amount != '0'); return balances.length > 0 ? balances : null; }, - [GetterTypes.getAllValidPools]: (state) => { + [GetterTypes.getAllValidPools]: (state: APIState): Pool[] => { return state.validPools; }, - [GetterTypes.getAllStakingBalances]: (state) => { + [GetterTypes.getAllStakingBalances]: (state: APIState): EmerisAPI.StakingBalances | null => { const stakingBalances = Object.values(state.stakingBalances) .filter((balance) => balance !== null) .flat(); return stakingBalances.length > 0 ? stakingBalances : null; }, - [GetterTypes.getAllUnbondingDelegations]: (state) => { + [GetterTypes.getAllUnbondingDelegations]: (state: APIState): EmerisAPI.UnbondingDelegations | null => { const unbondingDelegations = Object.values(state.unbondingDelegations) .filter((balance) => balance !== null) .flat(); return unbondingDelegations.length > 0 ? unbondingDelegations : null; }, - [GetterTypes.getNumbersChain]: (state) => (params) => { - return state.chainnumbers[params.chain_name][params.address] ?? null; - }, - [GetterTypes.getChainAPR]: (state) => (params) => { - return state.chains[params.chain_name].apr; - }, - [GetterTypes.getFeeAddresses]: (state) => { + [GetterTypes.getNumbersChain]: + (state: APIState) => + (params: EmerisAPI.ChainAddrReq): EmerisAPI.SeqNumber | null => { + return state.chainnumbers[params.chain_name][params.address] ?? null; + }, + [GetterTypes.getChainAPR]: + (state: APIState) => + (params: EmerisAPI.ChainReq): string => { + return state.chains[params.chain_name].apr; + }, + [GetterTypes.getFeeAddresses]: (state: APIState) => { const feeAddresses = []; for (const chain of Object.values(state.chains)) { feeAddresses.push({ chain_name: chain.chain_name, demeris_address: chain.demeris_addresses[0] }); } return feeAddresses.length != 0 ? feeAddresses : null; }, - [GetterTypes.isVerified]: (state) => (params) => { - return state.verifiedDenoms.find((x) => x.name == params.denom)?.verified ?? false; - }, - [GetterTypes.getVerifiedDenoms]: (state) => { + [GetterTypes.isVerified]: + (state: APIState) => + (params: { denom: string; chain_name: string }): boolean => { + return state.verifiedDenoms.find((x) => x.name == params.denom)?.verified ?? false; + }, + [GetterTypes.getVerifiedDenoms]: (state: APIState): EmerisAPI.VerifiedDenoms | null => { return state.verifiedDenoms.length != 0 ? state.verifiedDenoms : null; }, [GetterTypes.getTicker]: - (state, getters) => - ({ name }) => { + (state: APIState, getters) => + ({ name }): string => { const ticker = state.verifiedDenoms.find((x) => x.name == name)?.ticker ?? null; if (ticker) { return ticker; @@ -164,132 +105,142 @@ export const getters: GetterTree & Getters = { } } }, - [GetterTypes.getChainFromChainId]: (state) => (chain_id) => { - return Object.values(state.chains).find((x) => x.node_info.chain_id == chain_id).chain_name; - }, - [GetterTypes.getDisplayChain]: - (state) => - ({ name }) => { - return state.chains[name]?.display_name ?? null; + [GetterTypes.getChainFromChainId]: + (state: APIState) => + (chain_id: string): string => { + return Object.values(state.chains).find((x) => x.node_info.chain_id == chain_id).chain_name; }, - [GetterTypes.getDenomPrecision]: - (state) => - ({ name }) => { - return state.verifiedDenoms.find((x) => x.name == name)?.precision ?? null; + [GetterTypes.getDisplayChain]: + (state: APIState) => + (params: { name: string }): string => { + return state.chains[params.name]?.display_name ?? null; }, - [GetterTypes.getChains]: (state) => { + [GetterTypes.getDenomPrecision]: (state) => (params: { name: string }) => { + return state.verifiedDenoms.find((x) => x.name == params.name)?.precision ?? null; + }, + [GetterTypes.getChains]: (state: APIState): Record => { return Object.keys(state.chains).length != 0 ? state.chains : null; }, - [GetterTypes.getPrices]: (state) => { + [GetterTypes.getPrices]: (state: APIState): EmerisAPI.Prices => { return state.prices; }, - [GetterTypes.getExchangeAmountFromATOMPool]: (state, getters) => (base_denom: string) => { - const traces = getters['getAllVerifiedTraces']; - const pools = getters['getAllValidPools']; + [GetterTypes.getExchangeAmountFromATOMPool]: + (state: APIState, getters) => + (base_denom: string): number => { + const traces = getters[GlobalGetterTypes.API.getAllVerifiedTraces]; + const pools = getters[GlobalGetterTypes.API.getAllValidPools]; - let referencePool = null; - let reserveBaseDenoms = []; - if (pools) { - for (const pool of pools) { - reserveBaseDenoms = []; + let referencePool = null; + let reserveBaseDenoms = []; + if (pools) { + for (const pool of pools) { + reserveBaseDenoms = []; - for (const coinDenom of pool.reserve_coin_denoms) { - reserveBaseDenoms.push(traces[coinDenom.split('/')[1]]?.base_denom ?? coinDenom); - } + for (const coinDenom of pool.reserve_coin_denoms) { + reserveBaseDenoms.push(traces[coinDenom.split('/')[1]]?.base_denom ?? coinDenom); + } - if (reserveBaseDenoms.includes('uatom') && reserveBaseDenoms.includes(base_denom)) { - referencePool = pool; - break; + if (reserveBaseDenoms.includes('uatom') && reserveBaseDenoms.includes(base_denom)) { + referencePool = pool; + break; + } } } - } - if (!referencePool) { - return; - } + if (!referencePool) { + return; + } - const reserveBalances = getters['getBalances']({ - address: keyHashfromAddress(referencePool.reserve_account_address), - }); + const reserveBalances = getters[GlobalGetterTypes.API.getBalances]({ + address: keyHashfromAddress(referencePool.reserve_account_address), + }); - if (!reserveBalances) { - return; - } + if (!reserveBalances) { + return; + } - const amounts = reserveBaseDenoms.sort().reduce((acc, baseDenom) => { - const balance = reserveBalances.find((item) => item.base_denom === baseDenom); - return [ - ...acc, - { - ...parseCoins(balance.amount)[0], - base_denom: baseDenom, - precision: getters['getDenomPrecision']({ name: baseDenom }) ?? 6, - }, - ]; - }, []); + const amounts = reserveBaseDenoms.sort().reduce((acc, baseDenom) => { + const balance = reserveBalances.find((item) => item.base_denom === baseDenom); + return [ + ...acc, + { + ...parseCoins(balance.amount)[0], + base_denom: baseDenom, + precision: getters[GlobalGetterTypes.API.getDenomPrecision]({ name: baseDenom }) ?? 6, + }, + ]; + }, []); - const targetIndex = amounts.findIndex((item) => item.base_denom === base_denom); - const counterpartIndex = targetIndex === 0 ? 1 : 0; + const targetIndex = amounts.findIndex((item) => item.base_denom === base_denom); + const counterpartIndex = targetIndex === 0 ? 1 : 0; - const exchangeAmount = new BigNumber(amounts[counterpartIndex].amount) - .dividedBy(amounts[targetIndex].amount) - .toNumber(); + const exchangeAmount = new BigNumber(amounts[counterpartIndex].amount) + .dividedBy(amounts[targetIndex].amount) + .toNumber(); - return exchangeAmount; - }, - [GetterTypes.getPrice]: (state, getters) => (params) => { - const ticker = (getters['getTicker']({ name: params.denom }) + 'USDT').toUpperCase(); - if (state.prices.Tokens.length == 0) { - return; - } - const marketPrice = state.prices.Tokens.find((x) => x.Symbol == ticker)?.Price ?? null; + return exchangeAmount; + }, + [GetterTypes.getPrice]: + (state: APIState, getters) => + (params: { denom: string }): number => { + const ticker = (getters[GlobalGetterTypes.API.getTicker]({ name: params.denom }) + 'USDT').toUpperCase(); + if (state.prices.Tokens.length == 0) { + return; + } + const marketPrice = state.prices.Tokens.find((x) => x.Symbol == ticker)?.Price ?? null; - if (marketPrice) { - return marketPrice; - } + if (marketPrice) { + return marketPrice; + } - const exchangeAmountFromPool = getters['getExchangeAmountFromATOMPool'](params.denom); + const exchangeAmountFromPool = getters[GlobalGetterTypes.API.getExchangeAmountFromATOMPool](params.denom); - if (exchangeAmountFromPool) { - const exchangedDenomPrecision = getters['getDenomPrecision']({ - name: params.denom, - }); - const ATOMPrice = getters['getPrice']({ denom: 'uatom' }); + if (exchangeAmountFromPool) { + const exchangedDenomPrecision = getters[GlobalGetterTypes.API.getDenomPrecision]({ + name: params.denom, + }); + const ATOMPrice = getters[GlobalGetterTypes.API.getPrice]({ denom: 'uatom' }); - return exchangeAmountFromPool * ATOMPrice * 10 ** (exchangedDenomPrecision - 6); - } + return exchangeAmountFromPool * ATOMPrice * 10 ** (exchangedDenomPrecision - 6); + } - return null; - }, - [GetterTypes.getSupply]: (state, getters) => (params) => { - const ticker = (getters['getTicker']({ name: params.denom }) + 'USDT').toUpperCase(); - return state.prices.Tokens.find((x) => x.Symbol == ticker)?.Supply ?? null; - }, - [GetterTypes.getEndpoint]: (state) => { + return null; + }, + [GetterTypes.getSupply]: + (state: APIState, getters) => + (params): number => { + const ticker = (getters[GlobalGetterTypes.API.getTicker]({ name: params.denom }) + 'USDT').toUpperCase(); + return state.prices.Tokens.find((x) => x.Symbol == ticker)?.Supply ?? null; + }, + [GetterTypes.getEndpoint]: (state: APIState): string => { return state.endpoint; }, - [GetterTypes.getGitEndpoint]: (state) => { + [GetterTypes.getGitEndpoint]: (state: APIState): string => { return state.gitEndpoint; }, - [GetterTypes.getRawGitEndpoint]: (state) => { + [GetterTypes.getRawGitEndpoint]: (state: APIState): string => { return state.rawGitEndpoint; }, - [GetterTypes.getWebSocketEndpoint]: (state) => { + [GetterTypes.getWebSocketEndpoint]: (state: APIState): string => { return state.wsEndpoint; }, - [GetterTypes.getDexChain]: (state) => { + [GetterTypes.getDexChain]: (state: APIState): string => { return state.hub_chain; }, - [GetterTypes.getTxStatus]: (state) => (params) => { - return state.transactions.get(JSON.stringify(params))?.promise ?? null; - }, - [GetterTypes.getVerifyTrace]: (state) => (params) => { - if (state.traces[params.chain_name]) { - return state.traces[params.chain_name][params.hash] ?? null; - } else { - return null; - } - }, - [GetterTypes.getAllVerifiedTraces]: (state) => { + [GetterTypes.getTxStatus]: + (state: APIState) => + (params: EmerisAPI.TicketReq): Promise | null => { + return state.transactions.get(JSON.stringify(params))?.promise ?? null; + }, + [GetterTypes.getVerifyTrace]: + (state: APIState) => + (params: EmerisAPI.VerifyTraceReq): EmerisAPI.VerifyTrace | null => { + if (state.traces[params.chain_name]) { + return state.traces[params.chain_name][params.hash] ?? null; + } else { + return null; + } + }, + [GetterTypes.getAllVerifiedTraces]: (state: APIState): Record => { let result = {}; for (const traces of Object.values(state.traces)) { result = { @@ -299,55 +250,67 @@ export const getters: GetterTree & Getters = { } return result; }, - [GetterTypes.getBech32Config]: (state) => (params) => { - return state.chains[params.chain_name]?.node_info.bech32_config ?? null; - }, - [GetterTypes.getFeeTokens]: (state) => (params) => { - return state.chains[params.chain_name]?.denoms?.filter((x) => x.fee_token) ?? []; - }, - [GetterTypes.getChain]: (state) => (params) => { - return state.chains[params.chain_name] ?? null; - }, - [GetterTypes.getPrimaryChannel]: (state) => (params) => { - return state.chains?.[params.chain_name]?.primary_channel[params.destination_chain_name] ?? null; - }, - [GetterTypes.getPrimaryChannels]: (state) => (params) => { + [GetterTypes.getBech32Config]: + (state: APIState) => + (params: EmerisAPI.ChainReq): EmerisBase.Bech32Config | null => { + return state.chains[params.chain_name]?.node_info.bech32_config ?? null; + }, + [GetterTypes.getFeeTokens]: + (state: APIState) => + (params: EmerisAPI.ChainReq): EmerisBase.Denom[] | null => { + return state.chains[params.chain_name]?.denoms?.filter((x) => x.fee_token) ?? []; + }, + [GetterTypes.getChain]: + (state: APIState) => + (params: EmerisAPI.ChainReq): EmerisAPI.Chain | null => { + return state.chains[params.chain_name] ?? null; + }, + [GetterTypes.getPrimaryChannel]: + (state: APIState) => + (params: EmerisAPI.ChainCounterPartyReq): string | null => { + return state.chains?.[params.chain_name]?.primary_channel[params.destination_chain_name] ?? null; + }, + [GetterTypes.getPrimaryChannels]: (state: APIState) => (params) => { const channels = []; for (const channel of Object.values(state.chains[params.chain_name].primary_channel)) { channels.push(channel); } return channels.length != 0 ? channels : null; }, - [GetterTypes.getTokenPrices]: (state) => { + [GetterTypes.getTokenPrices]: (state: APIState): ChartPrices | null => { return state.tokenPrices; }, - [GetterTypes.getAirdrops]: (state) => { + [GetterTypes.getAirdrops]: (state: APIState): EmerisAirdrops.Airdrop[] | null => { return state.airdrops; }, - [GetterTypes.getAirdropsStatus]: (state) => { + [GetterTypes.getAirdropsStatus]: (state: APIState): LoadingState | null => { return state.airdropsStatus; }, - [GetterTypes.getSelectedAirdrop]: (state) => { + [GetterTypes.getSelectedAirdrop]: (state: APIState): EmerisAirdrops.Airdrop | null => { return state.selectedAirdrop; }, - [GetterTypes.getTokenPricesLoadingStatus]: (state) => { + [GetterTypes.getTokenPricesLoadingStatus]: (state: APIState) => { return state.tokenPricesLoadingStatus; }, - [GetterTypes.getChainStatus]: (state) => (params) => { - if (featureRunning('USE_NEW_CHAINS_API')) return state.chains[params.chain_name]?.online; - else return state.chains[params.chain_name]?.status; - }, - [GetterTypes.getChainNameByBaseDenom]: (state) => (params) => { - return Object.values(state.chains)?.find((chain) => { - return chain.denoms?.find((denom) => denom.name === params.denom); - })?.chain_name; - }, + [GetterTypes.getChainStatus]: + (state: APIState) => + (params: EmerisAPI.ChainReq): boolean => { + if (featureRunning('USE_NEW_CHAINS_API')) return state.chains[params.chain_name]?.online; + else return state.chains[params.chain_name]?.status; + }, + [GetterTypes.getChainNameByBaseDenom]: + (state: APIState) => + (params: EmerisAPI.DenomReq): string => { + return Object.values(state.chains)?.find((chain) => { + return chain.denoms?.find((denom) => denom.name === params.denom); + })?.chain_name; + }, // Coingecko Getters - [GetterTypes.getCoinGeckoId]: (state) => { + [GetterTypes.getCoinGeckoId]: (state: APIState): string | null => { return state.coinGeckoId; }, - [GetterTypes.getCoinGeckoIdLoadingStatus]: (state) => { + [GetterTypes.getCoinGeckoIdLoadingStatus]: (state: APIState) => { return state.coinGeckoIdLoadingStatus; }, }; diff --git a/src/store/demeris-api/index.ts b/src/store/demeris-api/index.ts index 90a4e1c30..5afe67a63 100644 --- a/src/store/demeris-api/index.ts +++ b/src/store/demeris-api/index.ts @@ -2,40 +2,28 @@ import { CommitOptions, DispatchOptions, Module, Store as VuexStore } from 'vuex import { RootState } from '@/store'; -import { Actions, actions, GlobalActions } from './actions'; -import { Getters, getters, GlobalGetters } from './getters'; -import { Mutations, mutations } from './mutations'; +import { actions } from './actions'; +import { getters } from './getters'; +import { mutations } from './mutations'; import type { APIState } from './state'; import { getDefaultState } from './state'; export { APIState }; export type APIStore = Omit, 'getters' | 'commit' | 'dispatch'> & { - commit[1]>( - key: K, - payload?: P, - options?: CommitOptions, - ): ReturnType; + commit(key: K, payload?: P, options?: CommitOptions); } & { - dispatch( - key: K, - payload?: Parameters[1], - options?: DispatchOptions, - ): ReturnType; + dispatch(key: any, payload?: any, options?: DispatchOptions): any; } & { getters: { - [K in keyof Getters]: ReturnType; + any: any; }; }; export type NamespacedAPIStore = Omit, 'getters' | 'dispatch'> & { - dispatch( - key: K, - payload?: Parameters[1], - options?: DispatchOptions, - ): ReturnType; + dispatch(key: string, payload?: any, options?: DispatchOptions); } & { getters: { - [K in keyof GlobalGetters]: ReturnType; + any: any; }; }; export const namespace = 'demerisAPI'; @@ -45,10 +33,10 @@ export const module: Module = { mutations, getters, actions, - namespaced: true, + namespaced: false, }; -import { GlobalActionTypes } from './action-types'; -import { GlobalGetterTypes } from './getter-types'; +import { ActionTypes as GlobalActionTypes } from './action-types'; +import { GetterTypes as GlobalGetterTypes } from './getter-types'; export { GlobalActionTypes, GlobalGetterTypes }; diff --git a/src/store/demeris-api/mutations.ts b/src/store/demeris-api/mutations.ts index 351079a11..13aa0c8c9 100644 --- a/src/store/demeris-api/mutations.ts +++ b/src/store/demeris-api/mutations.ts @@ -13,85 +13,49 @@ import { DemerisConfig, Subscriptions } from './actions'; import { MutationTypes } from './mutation-types'; import { APIState, getDefaultState } from './state'; -export type Mutations = { - [MutationTypes.SET_BALANCES](state: S, payload: { params: EmerisAPI.AddrReq; value: EmerisAPI.Balances }): void; - [MutationTypes.SET_POOL_BALANCES](state: S, payload: { params: EmerisAPI.AddrReq; value: EmerisAPI.Balances }): void; - [MutationTypes.SET_STAKING_BALANCES]( - state: S, - payload: { params: EmerisAPI.AddrReq; value: EmerisAPI.StakingBalances }, - ): void; - [MutationTypes.SET_UNSTAKING_PARAM]( - state: S, - payload: { params: EmerisAPI.ChainReq; value: EmerisAPI.StakingParams }, - ): void; - [MutationTypes.SET_UNBONDING_DELEGATIONS]( - state: S, - payload: { params: EmerisAPI.AddrReq; value: EmerisAPI.UnbondingDelegations }, - ): void; - [MutationTypes.SET_NUMBERS_CHAIN]( - state: S, - payload: { params: EmerisAPI.ChainAddrReq; value: EmerisAPI.SeqNumber }, - ): void; - [MutationTypes.SET_VERIFIED_DENOMS](state: S, payload: { value: EmerisAPI.VerifiedDenoms }): void; - [MutationTypes.SET_VALID_POOLS](state: S, payload: Pool[]): void; - [MutationTypes.SET_CHAINS](state: S, payload: { value: EmerisAPI.SupportedChain[] }): void; - [MutationTypes.SET_CHAIN_APR](state: S, payload: { params: EmerisAPI.ChainReq; value: string }): void; - [MutationTypes.SET_PRICES](state: S, payload: { value: EmerisAPI.Prices }): void; - [MutationTypes.SET_TX_STATUS]( - state: S, - payload: { params: EmerisAPI.TicketReq; value: EmerisAPI.TicketResponse }, - ): void; - - [MutationTypes.SET_VERIFY_TRACE]( - state: S, - payload: { params: EmerisAPI.VerifyTraceReq; value: EmerisAPI.VerifyTrace }, - ): void; - [MutationTypes.SET_CHAIN](state: S, payload: { params: EmerisAPI.ChainReq; value: EmerisAPI.Chain }): void; - [MutationTypes.SET_TOKEN_PRICES](state: S, payload: { value: Array<[number, number]> }): void; - [MutationTypes.SET_TOKEN_PRICES_STATUS](state: S, payload: { value: LoadingState }): void; - [MutationTypes.SET_AIRDROPS_STATUS](state: S, payload: { value: LoadingState }): void; - [MutationTypes.SET_CHAIN_STATUS](state: S, payload: { params: EmerisAPI.ChainReq; value: boolean }): void; - [MutationTypes.SET_AIRDROPS](state: S, payload: { value: EmerisAirdrops.Airdrop }): void; - [MutationTypes.RESET_AIRDROPS](state: S): void; - [MutationTypes.INIT](state: S, payload: DemerisConfig): void; - [MutationTypes.SET_IN_PROGRESS](state: S, payload: APIPromise): void; - [MutationTypes.DELETE_IN_PROGRESS](state: S, payload: string): void; - [MutationTypes.RESET_STATE](state: S): void; - [MutationTypes.CLEAR_SUBSCRIPTIONS](state: S): void; - [MutationTypes.SIGN_OUT](state: S, payload: string[]): void; - [MutationTypes.SUBSCRIBE](state: S, subscription: Subscriptions): void; - [MutationTypes.UNSUBSCRIBE](state: S, subsctiption: Subscriptions): void; - - //Coingecko - [MutationTypes.SET_COINGECKO_ID](state: S, payload: { params: string; value: EmerisAPI.TokenIdResponse }): void; - [MutationTypes.SET_COINGECKO_ID_STATUS](state: S, payload: { value: LoadingState }): void; -}; - -export const mutations: MutationTree & Mutations = { - [MutationTypes.SET_BALANCES](state, payload) { +export const mutations: MutationTree = { + [MutationTypes.SET_BALANCES]( + state: APIState, + payload: { params: EmerisAPI.AddrReq; value: EmerisAPI.Balances }, + ): void { if (!isEqual(state.balances[payload.params.address], payload.value)) { state.balances[payload.params.address] = payload.value; } }, - [MutationTypes.SET_POOL_BALANCES](state, payload) { + [MutationTypes.SET_POOL_BALANCES]( + state: APIState, + payload: { params: EmerisAPI.AddrReq; value: EmerisAPI.Balances }, + ): void { if (!isEqual(state.balances[payload.params.address], payload.value)) { state.balances[payload.params.address] = payload.value; } }, - [MutationTypes.SET_STAKING_BALANCES](state, payload) { + [MutationTypes.SET_STAKING_BALANCES]( + state: APIState, + payload: { params: EmerisAPI.AddrReq; value: EmerisAPI.StakingBalances }, + ): void { if (!isEqual(state.stakingBalances[payload.params.address], payload.value)) { state.stakingBalances[payload.params.address] = payload.value; } }, - [MutationTypes.SET_UNSTAKING_PARAM](state, payload) { + [MutationTypes.SET_UNSTAKING_PARAM]( + state: APIState, + payload: { params: EmerisAPI.ChainReq; value: EmerisAPI.StakingParams }, + ): void { state.unstakingParams[payload.params.chain_name] = payload.value; }, - [MutationTypes.SET_UNBONDING_DELEGATIONS](state, payload) { + [MutationTypes.SET_UNBONDING_DELEGATIONS]( + state: APIState, + payload: { params: EmerisAPI.AddrReq; value: EmerisAPI.UnbondingDelegations }, + ): void { if (!isEqual(state.unbondingDelegations[payload.params.address], payload.value)) { state.unbondingDelegations[payload.params.address] = payload.value; } }, - [MutationTypes.SET_NUMBERS_CHAIN](state, payload) { + [MutationTypes.SET_NUMBERS_CHAIN]( + state: APIState, + payload: { params: EmerisAPI.ChainAddrReq; value: EmerisAPI.SeqNumber }, + ): void { if (!state.chainnumbers[payload.params.chain_name]) { state.chainnumbers[payload.params.chain_name] = {}; } @@ -99,17 +63,17 @@ export const mutations: MutationTree & Mutations = { state.chainnumbers[payload.params.chain_name][payload.params.address] = payload.value; } }, - [MutationTypes.SET_VERIFIED_DENOMS](state, payload) { + [MutationTypes.SET_VERIFIED_DENOMS](state: APIState, payload: { value: EmerisAPI.VerifiedDenoms }): void { if (!isEqual(state.verifiedDenoms, payload.value)) { state.verifiedDenoms = payload.value; } }, - [MutationTypes.SET_VALID_POOLS](state: APIState, pools: Pool[]) { + [MutationTypes.SET_VALID_POOLS](state: APIState, pools: Pool[]): void { if (!isEqual(state.validPools, pools)) { state.validPools = pools; } }, - [MutationTypes.SET_CHAINS](state, payload) { + [MutationTypes.SET_CHAINS](state: APIState, payload: { value: EmerisAPI.SupportedChain[] }): void { state.chains = {}; for (const chain of payload.value) { if (!isEqual(state.chains[chain.chain_name], chain)) { @@ -117,21 +81,24 @@ export const mutations: MutationTree & Mutations = { } } }, - [MutationTypes.SET_CHAIN_APR](state, payload) { + [MutationTypes.SET_CHAIN_APR](state: APIState, payload: { params: EmerisAPI.ChainReq; value: string }): void { const { value, params: { chain_name }, } = payload; state.chains[chain_name].apr = value; }, - [MutationTypes.SET_PRICES](state, payload) { + [MutationTypes.SET_PRICES](state: APIState, payload: { value: EmerisAPI.Prices }): void { state.prices.Fiats = payload.value.Fiats; state.prices.Tokens = [ ...state.prices.Tokens.filter((x) => !payload.value.Tokens.map((x) => x.Symbol).includes(x.Symbol)), ...payload.value.Tokens, ]; }, - [MutationTypes.SET_TX_STATUS](state, payload) { + [MutationTypes.SET_TX_STATUS]( + state: APIState, + payload: { params: EmerisAPI.TicketReq; value: EmerisAPI.TicketResponse }, + ): void { const ticket = payload.value; let txPromise = state.transactions.get(JSON.stringify(payload.params)); if (txPromise == null) { @@ -183,7 +150,10 @@ export const mutations: MutationTree & Mutations = { state.transactions.set(JSON.stringify(payload.params), txPromise); } }, - [MutationTypes.SET_VERIFY_TRACE](state, payload) { + [MutationTypes.SET_VERIFY_TRACE]( + state: APIState, + payload: { params: EmerisAPI.VerifyTraceReq; value: EmerisAPI.VerifyTrace }, + ): void { if (state.traces[payload.params.chain_name]) { if (!isEqual(state.traces[payload.params.chain_name][payload.params.hash], payload.value)) { state.traces[payload.params.chain_name][payload.params.hash] = payload.value; @@ -193,7 +163,7 @@ export const mutations: MutationTree & Mutations = { state.traces[payload.params.chain_name][payload.params.hash] = payload.value; } }, - [MutationTypes.SET_CHAIN](state, payload) { + [MutationTypes.SET_CHAIN](state: APIState, payload: { params: EmerisAPI.ChainReq; value: EmerisAPI.Chain }): void { const { status, ...toUpdate } = payload.value; if (state.chains[payload.params.chain_name].status == undefined) { (toUpdate as EmerisAPI.Chain).status = status; @@ -210,13 +180,13 @@ export const mutations: MutationTree & Mutations = { }; } }, - [MutationTypes.SET_IN_PROGRESS](state: APIState, payload: APIPromise) { + [MutationTypes.SET_IN_PROGRESS](state: APIState, payload: APIPromise): void { state._InProgess.set(payload.hash, payload.promise); }, - [MutationTypes.DELETE_IN_PROGRESS](state: APIState, payload: string) { + [MutationTypes.DELETE_IN_PROGRESS](state: APIState, payload: string): void { state._InProgess.delete(payload); }, - [MutationTypes.SET_TOKEN_PRICES](state, payload) { + [MutationTypes.SET_TOKEN_PRICES](state: APIState, payload: { value: Array<[number, number]> }): void { if (payload.value && payload.value.length > 0) { const historicalPrices: ChartPrices = payload.value.map((item) => { return { @@ -230,12 +200,12 @@ export const mutations: MutationTree & Mutations = { state.tokenPrices = []; } }, - [MutationTypes.SET_TOKEN_PRICES_STATUS](state, payload) { + [MutationTypes.SET_TOKEN_PRICES_STATUS](state: APIState, payload: { value: LoadingState }): void { state.tokenPricesLoadingStatus = payload.value; }, //Airdrops Mutations - [MutationTypes.SET_AIRDROPS](state, payload) { + [MutationTypes.SET_AIRDROPS](state: APIState, payload: { value: EmerisAirdrops.Airdrop }): void { const tempAirdrop = payload.value; if (!tempAirdrop.airdropStartDate && !tempAirdrop.airdropEndDate) { @@ -258,37 +228,40 @@ export const mutations: MutationTree & Mutations = { state.airdrops.push(tempAirdrop); }, - [MutationTypes.SET_AIRDROPS_STATUS](state, payload) { + [MutationTypes.SET_AIRDROPS_STATUS](state: APIState, payload: { value: LoadingState }) { state.airdropsStatus = payload.value; }, - [MutationTypes.RESET_AIRDROPS](state) { + [MutationTypes.RESET_AIRDROPS](state: APIState): void { state.airdrops = []; }, //Coingecko Mutations - [MutationTypes.SET_COINGECKO_ID](state, payload) { + [MutationTypes.SET_COINGECKO_ID]( + state: APIState, + payload: { params: string; value: EmerisAPI.TokenIdResponse }, + ): void { state.coinGeckoId = payload.value.data[payload.params]; }, - [MutationTypes.SET_COINGECKO_ID_STATUS](state, payload) { + [MutationTypes.SET_COINGECKO_ID_STATUS](state: APIState, payload: { value: LoadingState }): void { state.coinGeckoIdLoadingStatus = payload.value; }, - [MutationTypes.SET_CHAIN_STATUS](state, payload) { + [MutationTypes.SET_CHAIN_STATUS](state: APIState, payload: { params: EmerisAPI.ChainReq; value: boolean }): void { if (!isEqual(state.chains[payload.params.chain_name].status, payload.value as boolean)) { state.chains[payload.params.chain_name].status = payload.value as boolean; } }, - [MutationTypes.INIT](state: APIState, payload: DemerisConfig) { + [MutationTypes.INIT](state: APIState, payload: DemerisConfig): void { state.endpoint = payload.endpoint; state.gitEndpoint = payload.gitEndpoint; state.rawGitEndpoint = payload.rawGitEndpoint; state.wsEndpoint = payload.wsEndpoint; state.hub_chain = payload.hub_chain; }, - [MutationTypes.RESET_STATE](state: APIState) { + [MutationTypes.RESET_STATE](state: APIState): void { Object.assign(state, getDefaultState()); }, - [MutationTypes.CLEAR_SUBSCRIPTIONS](state: APIState) { + [MutationTypes.CLEAR_SUBSCRIPTIONS](state: APIState): void { for (const sub of state._Subscriptions.values()) { const subObj = JSON.parse(sub); if ( @@ -300,7 +273,7 @@ export const mutations: MutationTree & Mutations = { } } }, - [MutationTypes.SIGN_OUT](state: APIState, payload: string[]) { + [MutationTypes.SIGN_OUT](state: APIState, payload: string[]): void { for (const keyhash of payload ?? []) { delete state.balances[keyhash]; } @@ -309,10 +282,10 @@ export const mutations: MutationTree & Mutations = { state.transactions = new Map(); state._InProgess = new Map(); }, - [MutationTypes.SUBSCRIBE](state: APIState, subscription) { + [MutationTypes.SUBSCRIBE](state: APIState, subscription: Subscriptions): void { state._Subscriptions.add(JSON.stringify(subscription)); }, - [MutationTypes.UNSUBSCRIBE](state: APIState, subscription) { + [MutationTypes.UNSUBSCRIBE](state: APIState, subscription: Subscriptions): void { state._Subscriptions.delete(JSON.stringify(subscription)); }, }; diff --git a/src/utils/actionHandler.ts b/src/utils/actionHandler.ts index 5f4c190d7..f84934cd1 100644 --- a/src/utils/actionHandler.ts +++ b/src/utils/actionHandler.ts @@ -672,7 +672,7 @@ export async function validPools(pools: Actions.Pool[]): Promise export async function chainStatusForSteps(steps: Actions.Step[]) { const typedstore = useStore() as RootStoreTyped; let allClear = true; - let relayerStatus = true; + const relayerStatus = true; const failedChains = []; for (const step of steps) { for (const stepTx of step.transactions) { @@ -704,13 +704,6 @@ export async function chainStatusForSteps(steps: Actions.Step[]) { failedChains.push(dest_chain_name); } } - - if ( - !typedstore.getters[GlobalGetterTypes.API.getRelayerChainStatus]({ chain_name }) || - !typedstore.getters[GlobalGetterTypes.API.getRelayerChainStatus]({ chain_name: dest_chain_name }) - ) { - relayerStatus = false; - } } if (stepTx.type == 'IBCtransferForward') { const chain_name = stepTx.data.chainName;