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 5 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
39 changes: 1 addition & 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,14 +730,14 @@ export default {
overview(networkId: $networkId, address: $address) {
totalRewards
liquidStake
totalStake
accountInformation {
accountNumber
sequence
}
}
}
`,
fetchPolicy: "cache-and-network",
Copy link
Collaborator

Choose a reason for hiding this comment

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

very cool. can we set this globablly or does it have to be set per component?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we can, but may want to not do it for things like networks. but we could make it the default and set the fetch policy for networks to cache

variables() {
/* istanbul ignore next */
return {
Expand All @@ -763,11 +762,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 +787,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
2 changes: 2 additions & 0 deletions src/ActionModal/components/DelegationModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ export default {
}
}
`,
fetchPolicy: "cache-and-network",
skip() {
/* istanbul ignore next */
return !this.address
Expand Down Expand Up @@ -427,6 +428,7 @@ export default {
result({ data }) {
/* istanbul ignore next */
if (data.userTransactionAdded.success) {
this.$apollo.queries.balance.refetch()
this.$apollo.queries.delegations.refetch()
}
}
Expand Down
25 changes: 25 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 @@ -270,6 +274,7 @@ export default {
}
}
`,
fetchPolicy: "cache-and-network",
skip() {
return !this.userAddress
},
Expand All @@ -280,6 +285,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
23 changes: 23 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 @@ -306,6 +307,7 @@ export default {
}
}
`,
fetchPolicy: "cache-and-network",
skip() {
/* istanbul ignore next */
return !this.address
Expand Down Expand Up @@ -363,6 +365,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
22 changes: 3 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 @@ -105,6 +103,7 @@ export default {
}
}
`,
fetchPolicy: "cache-and-network",
variables() {
/* istanbul ignore next */
return {
Expand Down Expand Up @@ -143,22 +142,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 +159,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
5 changes: 3 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 All @@ -58,6 +57,7 @@ export default {
/* istanbul ignore next */
return DelegationsForDelegator(this.network)
},
fetchPolicy: "cache-and-network",
variables() {
/* istanbul ignore next */
return {
Expand All @@ -82,8 +82,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
22 changes: 4 additions & 18 deletions src/components/staking/PageValidator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ import moment from "moment"
import { mapGetters, mapState } from "vuex"
import { atoms, shortDecimals, fullDecimals, percent } from "scripts/num"
import { noBlanks, fromNow } from "src/filters"
import refetchNetworkOnly from "scripts/refetch-network-only"
import TmBtn from "common/TmBtn"
import DelegationModal from "src/ActionModal/components/DelegationModal"
import UndelegationModal from "src/ActionModal/components/UndelegationModal"
Expand Down Expand Up @@ -257,21 +256,8 @@ export default {
onUndelegation() {
this.$refs.undelegationModal.open()
},
clearDelegationCache() {
this.$store.commit("invalidateCache", [
`overview`,
`delegations`,
`transactions`
]) // TODO use more finegrained query string (network and address)
},
clearUndelegationCache() {
this.$store.commit("invalidateCache", [
`overview`,
`delegations`,
`undelegations`,
`transactions`
]) // TODO use more finegrained query string (network and address)
},
clearDelegationCache() {},
faboweb marked this conversation as resolved.
Show resolved Hide resolved
clearUndelegationCache() {},
isBlankField(field, alternateFilter) {
return field ? alternateFilter(field) : noBlanks(field)
}
Expand Down Expand Up @@ -387,7 +373,7 @@ export default {
},
result() {
/* istanbul ignore next */
refetchNetworkOnly(this.$apollo.queries.rewards)
this.$apollo.queries.rewards.refetch()
}
},
userTransactionAdded: {
Expand All @@ -406,7 +392,7 @@ export default {
result({ data }) {
/* istanbul ignore next */
if (data.userTransactionAdded.success) {
refetchNetworkOnly(this.$apollo.queries.delegation)
this.$apollo.queries.delegation.refetch()
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/components/staking/PageValidators.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export default {
}
}
`,
fetchPolicy: "cache-and-network",
skip() {
return !this.address
},
Expand Down
Loading