Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fabo/fetch policy #3390

Merged
merged 16 commits into from
Jan 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/fabo_fetch-policy
Original file line number Diff line number Diff line change
@@ -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
38 changes: 0 additions & 38 deletions src/ActionModal/components/ActionModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,6 @@ export default {
userAddress: this.session.address,
rewards: this.rewards,
totalRewards: this.overview.totalRewards,
delegations: this.delegations,
Copy link
Collaborator

@jbibla jbibla Jan 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how come this is no longer needed? don't we use this for undelegation counts and redelegations?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find any use of delegations in the context. 5 withdraws are calculated based on the rewards.

bondDenom: this.network.stakingDenom,
isExtensionAccount: this.isExtensionAccount,
account: this.overview.accountInformation
Expand Down Expand Up @@ -731,7 +730,6 @@ export default {
overview(networkId: $networkId, address: $address) {
totalRewards
liquidStake
totalStake
accountInformation {
accountNumber
sequence
Expand Down Expand Up @@ -763,11 +761,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
Expand All @@ -791,39 +786,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() {
Expand Down
15 changes: 7 additions & 8 deletions src/ActionModal/components/DelegationModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -398,6 +396,7 @@ export default {
}
}
`,
fetchPolicy: "cache-first",
variables() {
/* istanbul ignore next */
return {
Expand All @@ -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()
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/ActionModal/components/ModalWithdrawRewards.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export default {
}
}
`,
fetchPolicy: "cache-first",
variables() {
return {
networkId: this.network
Expand Down
24 changes: 24 additions & 0 deletions src/ActionModal/components/SendModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down Expand Up @@ -189,6 +190,9 @@ export default {
}
}
},
mounted() {
this.$apollo.queries.balance.refetch()
},
methods: {
open() {
this.$refs.actionModal.open()
Expand Down Expand Up @@ -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()
}
}
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions src/ActionModal/components/UndelegationModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down Expand Up @@ -266,6 +267,7 @@ export default {
methods: {
open() {
this.$refs.actionModal.open()
this.$apollo.queries.delegations.refetch()
},
validateForm() {
this.$v.$touch()
Expand Down Expand Up @@ -331,6 +333,7 @@ export default {
}
}
`,
fetchPolicy: "cache-first",
variables() {
/* istanbul ignore next */
return {
Expand Down Expand Up @@ -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()
}
}
}
}
}
Expand Down
21 changes: 2 additions & 19 deletions src/components/common/TmBalance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,10 @@
</template>
<script>
import { shortDecimals } from "scripts/num"
import refetchNetworkOnly from "scripts/refetch-network-only"
import { noBlanks } from "src/filters"
import TmBtn from "common/TmBtn"
import SendModal from "src/ActionModal/components/SendModal"
import ModalWithdrawRewards from "src/ActionModal/components/ModalWithdrawRewards"
import { UserTransactionAdded } from "src/gql"
import { mapGetters } from "vuex"
import gql from "graphql-tag"
export default {
Expand Down Expand Up @@ -143,22 +141,6 @@ export default {
}
},
$subscribe: {
userTransactionAdded: {
variables() {
return {
networkId: this.network,
address: this.address
}
},
skip() {
return !this.address
},
query: UserTransactionAdded,
result() {
// query if successful or not as even an unsuccessful tx costs fees
refetchNetworkOnly(this.$apollo.queries.overview)
}
},
blockAdded: {
variables() {
return {
Expand All @@ -176,7 +158,8 @@ export default {
`
},
result() {
refetchNetworkOnly(this.$apollo.queries.overview)
/* istanbul ignore next */
this.$apollo.queries.overview.refetch()
}
}
}
Expand Down
18 changes: 5 additions & 13 deletions src/components/governance/PageProposal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ import { ProposalItem, GovernanceParameters, Vote } from "src/gql"
import BigNumber from "bignumber.js"
import Bech32 from "common/Bech32"
import gql from "graphql-tag"
import refetchNetworkOnly from "scripts/refetch-network-only"
export default {
name: `page-proposal`,
Expand Down Expand Up @@ -270,20 +269,13 @@ export default {
this.$refs.modalVote.open()
},
afterVote() {
this.$apollo.queries.vote.refetch({
proposalId: this.proposal.id,
address: this.address
})
this.$store.commit("invalidateCache", [`overview`, `transactions`])
this.$apollo.queries.vote.refetch()
},
onDeposit() {
this.$refs.modalDeposit.open()
},
afterDeposit() {
this.$apollo.queries.proposal.refetch({
id: this.proposal.id
})
this.$store.commit("invalidateCache", [`overview`, `transactions`])
this.$apollo.queries.proposal.refetch()
},
getProposalIndex(num) {
let proposalsObj = this.proposals
Expand Down Expand Up @@ -424,9 +416,9 @@ export default {
this.proposal.status !== "Rejected" &&
this.loaded
) {
refetchNetworkOnly(this.$apollo.queries.proposal)
refetchNetworkOnly(this.$apollo.queries.parameters)
refetchNetworkOnly(this.$apollo.queries.vote)
this.$apollo.queries.proposal.refetch()
this.$apollo.queries.parameters.refetch()
this.$apollo.queries.vote.refetch()
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/components/governance/PageProposals.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import TmDataMsg from "common/TmDataMsg"
import { mapGetters } from "vuex"
import { GovernanceParameters } from "src/gql"
import gql from "graphql-tag"
import refetchNetworkOnly from "scripts/refetch-network-only"
export default {
name: `page-proposals`,
Expand All @@ -71,7 +70,6 @@ export default {
},
afterPropose() {
this.$apollo.queries.proposals.refetch()
this.$store.commit("invalidateCache", [`overview`, `transactions`])
}
},
apollo: {
Expand Down Expand Up @@ -133,7 +131,7 @@ export default {
},
result() {
/* istanbul ignore next */
refetchNetworkOnly(this.$apollo.queries.proposals)
this.$apollo.queries.proposals.refetch()
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/components/network/PageNetworks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default {
apollo: {
networks: {
query: Networks,
fetchPolicy: "cache-first",
update: NetworksResult
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/staking/DelegationsOverview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import { mapGetters } from "vuex"
import TmDataMsg from "common/TmDataMsg"
import TableValidators from "staking/TableValidators"
import { DelegationsForDelegator, UserTransactionAdded } from "src/gql"
import refetchNetworkOnly from "scripts/refetch-network-only"
export default {
name: `delegations-overview`,
Expand Down Expand Up @@ -82,8 +81,9 @@ export default {
},
query: UserTransactionAdded,
result({ data }) {
/* istanbul ignore next */
if (data.userTransactionAdded.success) {
refetchNetworkOnly(this.$apollo.queries.delegations)
this.$apollo.queries.delegations.refetch()
}
}
}
Expand Down
Loading