Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Dispatch actions on App mount
  • Loading branch information
samajammin committed May 20, 2021
commit 6ff00a4caf61ce16dbcdc31f91da5fe7f3044ad1
17 changes: 4 additions & 13 deletions vue-app/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,11 @@ import { Watch } from 'vue-property-decorator'

import { recipientRegistryType } from '@/api/core'
import { getCurrentRound } from '@/api/round'
import { getRecipientRegistryAddress } from '@/api/projects'
import { getRegistryInfo } from '@/api/recipient-registry-optimistic'

import Cart from '@/components/Cart.vue'
import Profile from '@/components/Profile.vue'

import { LOAD_USER_INFO, LOAD_ROUND_INFO, LOAD_RECIPIENT_REGISTRY_INFO } from '@/store/action-types'
import {
SET_RECIPIENT_REGISTRY_ADDRESS,
SET_RECIPIENT_REGISTRY_INFO,
} from '@/store/mutation-types'
import { LOAD_USER_INFO, LOAD_ROUND_INFO, LOAD_RECIPIENT_REGISTRY_INFO, SELECT_ROUND } from '@/store/action-types'

@Component({
name: 'clr.fund',
Expand Down Expand Up @@ -88,13 +82,10 @@ export default class App extends Vue {
}, 60 * 1000)
}

// TODO commit() approach? Or dispatch() on interval?
async mounted() {
const roundAddress = this.$store.state.currentRoundAddress || await getCurrentRound()
const registryAddress = this.$store.state.recipientRegistryAddress || await getRecipientRegistryAddress(roundAddress)
this.$store.commit(SET_RECIPIENT_REGISTRY_ADDRESS, registryAddress)
const registryInfo = this.$store.state.recipientRegistryInfo || await getRegistryInfo(registryAddress)
this.$store.commit(SET_RECIPIENT_REGISTRY_INFO, registryInfo)
const roundAddress = await getCurrentRound()
await this.$store.dispatch(SELECT_ROUND, roundAddress)
this.$store.dispatch(LOAD_RECIPIENT_REGISTRY_INFO)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not correct because the round address can also come from route parameter in ProjectList component.

See my previous comment on this section of code

Copy link
Contributor

Choose a reason for hiding this comment

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

Construction of the app's state begins with a round address, because almost everything else depends on it.

There are two ways in which this variable can be set:

  1. If user lands on the project list page, the ProjectList component gets round address from route parameters.
  2. If route parameters does not contain round address, or if user lands on some other page, the app gets round address from the FundingRoundFactory contract.

(1) is the reason why the initialization does not currently take place in the App.created(). Doing initialization in App should be possible, but it would require more work.

Your proposed change simply creates a race for dispatching SELECT_ROUND between App and ProjectList components.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the explanation.

  1. If route parameters does not contain round address, or if user lands on some other page, the app gets round address from the FundingRoundFactory contract.

Where does this logic take place? Does it happen on page load / app initialization? I see we dispatch LOAD_ROUND_INFO every 60 seconds in App.vue but for our purposes we need to fetch round info on any initial page load. I'm open to refactoring this to accomplish that without creating a potential clash vs. the route parameters of ProjectList.

}

toggleNavBar() {
Expand Down
4 changes: 3 additions & 1 deletion vue-app/src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import { recipientRegistryType } from '@/api/core'
import { loginUser, logoutUser } from '@/api/gun'
import { getRegistryInfo, RegistryInfo } from '@/api/recipient-registry-optimistic'
Copy link
Contributor

Choose a reason for hiding this comment

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

Other types of registries (such as Kleros adapter) can have registry info too, but of different type.
There should be a wrapper function in api/projects.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I checked out api/projects.ts but I'm only seeing wrapper functions around getting/registering projects. I'm not seeing anything around registry info in api/recipient-registry-kleros but please let me know if I'm missing something you'd like me to add here (or if there's a wrapper function you'd like me to create).

import { getRecipientRegistryAddress } from '@/api/projects'
import { RoundInfo, RoundStatus, getRoundInfo } from '@/api/round'
import { storage } from '@/api/storage'
import { Tally, getTally } from '@/api/tally'
Expand Down Expand Up @@ -183,7 +184,8 @@ const actions = {
}
},
async [LOAD_RECIPIENT_REGISTRY_INFO]({ commit, state }) {
const recipientRegistryAddress = state.recipientRegistryAddress
const recipientRegistryAddress = state.recipientRegistryAddress || await getRecipientRegistryAddress(state.currentRoundAddress)
commit(SET_RECIPIENT_REGISTRY_ADDRESS, recipientRegistryAddress)
if (recipientRegistryAddress === null || recipientRegistryType !== 'optimistic') {
commit(SET_RECIPIENT_REGISTRY_INFO, null)
return
Expand Down