Skip to content

Commit

Permalink
refactor(store/friends): move friendexists method from hounddog into …
Browse files Browse the repository at this point in the history
…getters
  • Loading branch information
jasonwoodland committed May 20, 2022
1 parent 666e890 commit ba4027e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
15 changes: 10 additions & 5 deletions store/friends/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
FriendsError,
FriendsState,
} from './types'
import FriendGetters from './getters'
import { DataStateType } from '~/store/dataState/types'
import { TextileError } from '~/store/textile/types'
import Crypto from '~/libraries/Crypto/Crypto'
Expand All @@ -28,7 +29,6 @@ import { AccountsError } from '~/store/accounts/types'
import { ActionsArguments } from '~/types/store/store'
import { FriendMetadata } from '~/types/textile/metadata'
import { Friend, FriendRequest, OutgoingRequest } from '~/types/ui/friends'
import Hounddog from '~/utilities/Hounddog'

export default {
async initialize({
Expand Down Expand Up @@ -126,14 +126,19 @@ export default {
* @example
*/
async fetchFriendDetails(
{ commit, state, rootState, dispatch }: ActionsArguments<FriendsState>,
{
commit,
state,
rootState,
dispatch,
getters,
}: ActionsArguments<FriendsState, typeof FriendGetters>,
friendAccount: FriendAccount,
) {
): Promise<void> {
// First grab the users from local db
const $SolanaManager: SolanaManager = Vue.prototype.$SolanaManager
const usersProgram: UsersProgram = new UsersProgram($SolanaManager)
const $Crypto: Crypto = Vue.prototype.$Crypto
const $Hounddog: Hounddog = Vue.prototype.$Hounddog

// Check if the request was originally sent by the current user (outgoing)
// and then accepted, or the other way round
Expand Down Expand Up @@ -164,7 +169,7 @@ export default {
).bytes,
)

const friendExists = $Hounddog.friendExists(state, friendKey)
const friendExists = getters.friendExists(state)(friendKey)

const friend: Omit<Friend, 'publicKey' | 'typingState' | 'lastUpdate'> = {
account: friendAccount,
Expand Down
3 changes: 2 additions & 1 deletion types/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ export interface RootState {

export type RootStore = Store<RootState>

export type ActionsArguments<StateType> = {
export type ActionsArguments<StateType, GettersType> = {
commit: Commit
state: StateType
dispatch: Dispatch
rootState: RootState
getters: GettersType
}

0 comments on commit ba4027e

Please sign in to comment.