From a6310dd3f0f4612cb1e52262704789db3e483d43 Mon Sep 17 00:00:00 2001 From: Fabian Date: Fri, 10 Jan 2020 13:56:03 -0400 Subject: [PATCH] Fabo/fetch policy (#3390) * set fetch policies correctly * fixed tests * changelog * coverage * remove cache invalidation handlers from delegation modals * switch to default fetch-policy to cache-and-network * linted * always requery data on incomming tx on delegation modal * reload balance on open in delegation modal * fix data undefined * fix delegation modal test * refetch delegations in undelegation modal * coverage * fix test Co-authored-by: Ana G. <40721795+Bitcoinera@users.noreply.github.com> --- changes/fabo_fetch-policy | 1 + src/ActionModal/components/ActionModal.vue | 38 ------------------- .../components/DelegationModal.vue | 15 ++++---- .../components/ModalWithdrawRewards.vue | 1 + src/ActionModal/components/SendModal.vue | 24 ++++++++++++ .../components/UndelegationModal.vue | 24 ++++++++++++ src/components/common/TmBalance.vue | 21 +--------- src/components/governance/PageProposal.vue | 18 +++------ src/components/governance/PageProposals.vue | 4 +- src/components/network/PageNetworks.vue | 1 + .../staking/DelegationsOverview.vue | 4 +- src/components/staking/PageValidator.vue | 33 +++------------- src/components/staking/TableValidators.vue | 4 +- src/components/staking/Undelegations.vue | 3 +- src/gql/apollo.js | 8 +++- src/scripts/refetch-network-only.js | 10 ----- src/vuex/modules/connection.js | 3 +- src/vuex/modules/session.js | 15 +------- .../components/DelegationModal.spec.js | 5 ++- .../ActionModal/components/SendModal.spec.js | 9 ++++- .../components/UndelegationModal.spec.js | 3 +- .../governance/PageProposal.spec.js | 9 +---- 22 files changed, 101 insertions(+), 152 deletions(-) create mode 100644 changes/fabo_fetch-policy delete mode 100644 src/scripts/refetch-network-only.js diff --git a/changes/fabo_fetch-policy b/changes/fabo_fetch-policy new file mode 100644 index 0000000000..686b231776 --- /dev/null +++ b/changes/fabo_fetch-policy @@ -0,0 +1 @@ +[Fixed] [#3390](https://github.com/cosmos/lunie/pull/3390) Fix ActionModal data being out of date if a live update of data happened @faboweb \ No newline at end of file diff --git a/src/ActionModal/components/ActionModal.vue b/src/ActionModal/components/ActionModal.vue index 55dd65d5d3..cdf44a7cf7 100644 --- a/src/ActionModal/components/ActionModal.vue +++ b/src/ActionModal/components/ActionModal.vue @@ -481,7 +481,6 @@ export default { userAddress: this.session.address, rewards: this.rewards, totalRewards: this.overview.totalRewards, - delegations: this.delegations, bondDenom: this.network.stakingDenom, isExtensionAccount: this.isExtensionAccount, account: this.overview.accountInformation @@ -735,7 +734,6 @@ export default { overview(networkId: $networkId, address: $address) { totalRewards liquidStake - totalStake accountInformation { accountNumber sequence @@ -767,11 +765,8 @@ export default { query NetworkActionModal($networkId: String!) { network(id: $networkId) { id - testnet stakingDenom chain_id - rpc_url - api_url action_send action_claim_rewards action_delegate @@ -795,39 +790,6 @@ export default { return data.network } }, - delegations: { - query: gql` - query DelegationsActionModal( - $networkId: String! - $delegatorAddress: String! - ) { - delegations( - networkId: $networkId - delegatorAddress: $delegatorAddress - ) { - amount - validator { - operatorAddress - } - } - } - `, - skip() { - /* istanbul ignore next */ - return !this.session.address - }, - variables() { - /* istanbul ignore next */ - return { - networkId: this.networkId, - delegatorAddress: this.session.address - } - }, - update(data) { - /* istanbul ignore next */ - return data.delegations - } - }, $subscribe: { userTransactionAdded: { variables() { diff --git a/src/ActionModal/components/DelegationModal.vue b/src/ActionModal/components/DelegationModal.vue index 68181799e6..dea82f7a47 100644 --- a/src/ActionModal/components/DelegationModal.vue +++ b/src/ActionModal/components/DelegationModal.vue @@ -269,13 +269,11 @@ export default { return this.fromSelectedIndex !== `0` } }, - mounted() { - this.$apollo.queries.balance.refetch() - this.$apollo.queries.delegations.refetch() - }, methods: { open() { this.$refs.actionModal.open() + this.$apollo.queries.balance.refetch() + this.$apollo.queries.delegations.refetch() }, validateForm() { this.$v.$touch() @@ -398,6 +396,7 @@ export default { } } `, + fetchPolicy: "cache-first", variables() { /* istanbul ignore next */ return { @@ -424,11 +423,11 @@ export default { return !this.address }, query: UserTransactionAdded, - result({ data }) { + result() { /* istanbul ignore next */ - if (data.userTransactionAdded.success) { - this.$apollo.queries.delegations.refetch() - } + this.$apollo.queries.balance.refetch() + /* istanbul ignore next */ + this.$apollo.queries.delegations.refetch() } } } diff --git a/src/ActionModal/components/ModalWithdrawRewards.vue b/src/ActionModal/components/ModalWithdrawRewards.vue index 415977ecec..6a1be96f12 100644 --- a/src/ActionModal/components/ModalWithdrawRewards.vue +++ b/src/ActionModal/components/ModalWithdrawRewards.vue @@ -118,6 +118,7 @@ export default { } } `, + fetchPolicy: "cache-first", variables() { return { networkId: this.network diff --git a/src/ActionModal/components/SendModal.vue b/src/ActionModal/components/SendModal.vue index 8019ca101a..d66e73f304 100644 --- a/src/ActionModal/components/SendModal.vue +++ b/src/ActionModal/components/SendModal.vue @@ -134,6 +134,7 @@ import ActionModal from "./ActionModal" import transaction from "../utils/transactionTypes" import { toMicroDenom } from "src/scripts/common" import config from "src/../config" +import { UserTransactionAdded } from "src/gql" const defaultMemo = "(Sent via Lunie)" @@ -189,6 +190,9 @@ export default { } } }, + mounted() { + this.$apollo.queries.balance.refetch() + }, methods: { open() { this.$refs.actionModal.open() @@ -280,6 +284,26 @@ export default { denom: this.denom } } + }, + $subscribe: { + userTransactionAdded: { + variables() { + /* istanbul ignore next */ + return { + networkId: this.network, + address: this.userAddress + } + }, + skip() { + /* istanbul ignore next */ + return !this.userAddress + }, + query: UserTransactionAdded, + result() { + /* istanbul ignore next */ + this.$apollo.queries.balance.refetch() + } + } } } } diff --git a/src/ActionModal/components/UndelegationModal.vue b/src/ActionModal/components/UndelegationModal.vue index 7812ece1c6..d82c74fd07 100644 --- a/src/ActionModal/components/UndelegationModal.vue +++ b/src/ActionModal/components/UndelegationModal.vue @@ -124,6 +124,7 @@ import TmFormMsg from "src/components/common/TmFormMsg" import transaction from "../utils/transactionTypes" import { toMicroDenom } from "src/scripts/common" import { formatBech32, validatorEntry } from "src/filters" +import { UserTransactionAdded } from "src/gql" export default { name: `undelegation-modal`, @@ -266,6 +267,7 @@ export default { methods: { open() { this.$refs.actionModal.open() + this.$apollo.queries.delegations.refetch() }, validateForm() { this.$v.$touch() @@ -331,6 +333,7 @@ export default { } } `, + fetchPolicy: "cache-first", variables() { /* istanbul ignore next */ return { @@ -363,6 +366,27 @@ export default { /* istanbul ignore next */ return data.validators } + }, + + $subscribe: { + userTransactionAdded: { + variables() { + /* istanbul ignore next */ + return { + networkId: this.network, + address: this.userAddress + } + }, + skip() { + /* istanbul ignore next */ + return !this.userAddress + }, + query: UserTransactionAdded, + result() { + /* istanbul ignore next */ + this.$apollo.queries.delegations.refetch() + } + } } } } diff --git a/src/components/common/TmBalance.vue b/src/components/common/TmBalance.vue index 9e67ea944e..57000d20e3 100644 --- a/src/components/common/TmBalance.vue +++ b/src/components/common/TmBalance.vue @@ -53,12 +53,10 @@