diff --git a/pages/auth/register/index.vue b/pages/auth/register/index.vue
index bd934d53d3..02156b7e23 100644
--- a/pages/auth/register/index.vue
+++ b/pages/auth/register/index.vue
@@ -18,6 +18,7 @@ export default Vue.extend({
},
computed: {
...mapGetters('accounts', ['getRegistrationStatus']),
+ ...mapGetters(['allPrerequisitesReady']),
hasToRegister() {
return this.getRegistrationStatus === RegistrationStatus.UNKNOWN
},
@@ -32,23 +33,27 @@ export default Vue.extend({
'user.registration.reg_status.sending_transaction',
)
default:
- return this.$i18n.t('user.registration.reg_status.registered')
+ return this.$i18n.t('user.loading.loading_account')
}
},
isRegistered() {
return this.getRegistrationStatus === RegistrationStatus.REGISTERED
},
},
+ watch: {
+ allPrerequisitesReady(nextValue) {
+ if (!nextValue) return
+ this.$router.replace('/chat/direct')
+ },
+ },
mounted() {},
methods: {
async confirm(userData: UserRegistrationData) {
- await this.$store.dispatch('accounts/registerUser', {
+ this.$store.dispatch('accounts/registerUser', {
name: userData.username,
image: userData.photoHash,
status: userData.status,
})
-
- this.$router.replace('/chat/direct')
},
},
})
diff --git a/pages/auth/unlock/index.vue b/pages/auth/unlock/index.vue
index 78274ccf27..37ff043411 100644
--- a/pages/auth/unlock/index.vue
+++ b/pages/auth/unlock/index.vue
@@ -47,7 +47,6 @@ export default Vue.extend({
ConsoleWarning(this.$config.clientVersion, this.$store.state)
this.$store.commit('accounts/lock')
- this.$store.commit('prerequisites/resetState')
},
methods: {
/**
diff --git a/pages/generic/loading/Loading.html b/pages/generic/loading/Loading.html
deleted file mode 100644
index e14507b567..0000000000
--- a/pages/generic/loading/Loading.html
+++ /dev/null
@@ -1,7 +0,0 @@
-
diff --git a/pages/generic/loading/Loading.less b/pages/generic/loading/Loading.less
deleted file mode 100644
index 6c4d7c4884..0000000000
--- a/pages/generic/loading/Loading.less
+++ /dev/null
@@ -1,24 +0,0 @@
-.container {
- margin: 0 auto;
- display: flex;
- justify-content: center;
-
- .loading-body {
- min-width: 250px;
- align-self: center;
- margin-bottom: 25vh;
-
- .subtitle {
- float: right;
- }
- }
-}
-
-@media only screen and (max-width: @mobile-breakpoint) {
- .container {
- .loading-body {
- margin: 0;
- }
- margin: 0;
- }
-}
diff --git a/pages/generic/loading/index.vue b/pages/generic/loading/index.vue
deleted file mode 100644
index 3f8cd2acd2..0000000000
--- a/pages/generic/loading/index.vue
+++ /dev/null
@@ -1,88 +0,0 @@
-
-
-
-
-
diff --git a/pages/index.vue b/pages/index.vue
index 0b6707318c..7ee90aaee0 100644
--- a/pages/index.vue
+++ b/pages/index.vue
@@ -20,7 +20,7 @@ export default Vue.extend({
},
computed: {
...mapGetters('accounts', ['getEncryptedPhrase', 'getActiveAccount']),
- ...mapGetters('prerequisites', ['allPrerequisitesReady']),
+ ...mapGetters(['allPrerequisitesReady']),
...mapState(['accounts']),
// Helper method for prettier loading messages
loadingStep(): string {
@@ -31,21 +31,9 @@ export default Vue.extend({
},
},
watch: {
- // this.$router.replace('/chat/direct')
allPrerequisitesReady(nextValue) {
- if (nextValue) {
- if (
- this.accounts.lastVisited &&
- this.accounts.lastVisited !== this.$route.path
- ) {
- const matcher = this.$router.match(this.accounts.lastVisited)
- if (matcher.matched.length > 0) {
- this.$router.replace(this.accounts.lastVisited)
- return
- }
- }
- this.$router.replace('/chat/direct')
- }
+ if (!nextValue) return
+ this.eventuallyRedirect()
},
},
mounted() {
@@ -54,9 +42,21 @@ export default Vue.extend({
this.$router.replace('/setup/disclaimer')
return
}
+
this.loadAccount()
},
methods: {
+ eventuallyRedirect() {
+ if (this.accounts.lastVisited === this.$route.path) {
+ this.$router.replace('/chat/direct')
+ return
+ }
+
+ const matcher = this.$router.match(this.accounts.lastVisited)
+ if (matcher.matched.length > 0) {
+ this.$router.replace(this.accounts.lastVisited)
+ }
+ },
/**
* @method loadAccount
* @description Load user account by dispatching the loadAccount action in store/accounts/actions.ts,
diff --git a/plugins/local/classLoader.ts b/plugins/local/classLoader.ts
index 9457719c04..a8b084d0a5 100644
--- a/plugins/local/classLoader.ts
+++ b/plugins/local/classLoader.ts
@@ -33,7 +33,6 @@ declare module 'vue/types/vue' {
$Hounddog: Hounddog
$Logger: Logger
$Alerts: Alerts
- $Bucket: Bucket
$FileSystem: TextileFileSystem
}
}
@@ -52,7 +51,6 @@ declare module '@nuxt/types' {
$Hounddog: Hounddog
$Logger: Logger
$Alerts: Alerts
- $Bucket: Bucket
$FileSystem: TextileFileSystem
}
}
@@ -67,7 +65,6 @@ Vue.prototype.$Config = Config
Vue.prototype.$Hounddog = new Hounddog(Vue.prototype.$store)
Vue.prototype.$Logger = new Logger(Vue.prototype.$Config.debug)
Vue.prototype.$Alerts = new Alerts()
-Vue.prototype.$Bucket = new Bucket()
Vue.prototype.$FileSystem = new TextileFileSystem()
// Add typed store alias to Vue prototype
diff --git a/plugins/thirdparty/persist.ts b/plugins/thirdparty/persist.ts
index 95ccbb43da..92a58900f6 100644
--- a/plugins/thirdparty/persist.ts
+++ b/plugins/thirdparty/persist.ts
@@ -19,8 +19,10 @@ const mutationsBlacklist = [
// State properties path to blacklist saving to store
const commonProperties = [
+ 'webrtc.initialized',
+ 'textile.initialized',
+ 'accounts.initialized',
'friends.all',
- 'prerequisites',
'webrtc.activeStream',
'webrtc.connectedPeer',
'webrtc.incomingCall',
diff --git a/store/accounts/__snapshots__/state.test.ts.snap b/store/accounts/__snapshots__/state.test.ts.snap
index ca3e1573cf..443e117e60 100644
--- a/store/accounts/__snapshots__/state.test.ts.snap
+++ b/store/accounts/__snapshots__/state.test.ts.snap
@@ -6,7 +6,8 @@ Object {
"encryptedPhrase": "",
"error": "",
"gasPrice": "",
- "lastVisited": "",
+ "initialized": false,
+ "lastVisited": "/",
"loading": false,
"locked": true,
"phrase": "",
diff --git a/store/accounts/actions.ts b/store/accounts/actions.ts
index 4d8916d79f..e91d5e65d2 100644
--- a/store/accounts/actions.ts
+++ b/store/accounts/actions.ts
@@ -7,8 +7,8 @@ import {
UserRegistrationPayload,
} from './types'
import Crypto from '~/libraries/Crypto/Crypto'
-import ServerProgram from '~/libraries/Solana/ServerProgram/ServerProgram'
import SolanaManager from '~/libraries/Solana/SolanaManager/SolanaManager'
+import UsersProgram from '~/libraries/Solana/UsersProgram/UsersProgram'
import { ActionsArguments, RootState } from '~/types/store/store'
import TextileManager from '~/libraries/Textile/TextileManager'
@@ -18,10 +18,14 @@ import { FilSystem } from '~/libraries/Files/FilSystem'
export default {
/**
- * @method setPin DocsTODO
- * @description
- * @param pin
+ * @method setPin
+ * @description sets the user pin password and stores its
+ * hash inside the Vuex state
+ * @param pin the choosen pin password
* @example
+ * ```typescript
+ * this.$store.dispatch('accounts/setPin', 'myPassword123')
+ * ```
*/
async setPin({ commit }: ActionsArguments
, pin: string) {
if (pin.length < 5) {
@@ -32,16 +36,19 @@ export default {
const pinHash = await $Crypto.hash(pin)
- // The cleartext version of the pin will not be
- // persisted
+ // The cleartext version of the pin will not be persisted
commit('setPin', pin)
commit('setPinHash', pinHash)
},
/**
- * @method unlock DocsTODO
- * @description
- * @param pin
+ * @method unlock
+ * @description performs all the actions to unlock the app by
+ * decrypting the wallet information
+ * @param pin pin password in use
* @example
+ * ```typescript
+ * this.$store.dispatch('accounts/unlock', 'myPassword123')
+ * ```
*/
async unlock(
{ commit, state }: ActionsArguments,
@@ -73,10 +80,12 @@ export default {
commit('unlock', pin)
},
/**
- * @method generateWallet DocsTODO
- * @description
- * @param
+ * @method generateWallet
+ * @description Generates a new Solana hierarchical wallet
* @example
+ * ```typescript
+ * this.$store.dispatch('accounts/generateWallet')
+ * ```
*/
async generateWallet({ commit, state }: ActionsArguments) {
const { pin } = state
@@ -104,10 +113,14 @@ export default {
commit('setEncryptedPhrase', encryptedPhrase)
},
/**
- * @method setRecoverMnemonic DocsTODO
- * @description
- * @param mnemonic
+ * @method setRecoverMnemonic
+ * @description Encrypts the wallet mnemonic phrase using the user pin
+ * password and stores it inside Vuex store
+ * @param mnemonic the mnemonic phrase to store
* @example
+ * ```typescript
+ * this.$store.dispatch('accounts/setRecoverMnemonic','my seed phrase')
+ * ```
*/
async setRecoverMnemonic(
{ commit, state }: ActionsArguments,
@@ -125,10 +138,13 @@ export default {
await commit('setEncryptedPhrase', encryptedPhrase)
},
/**
- * @method loadAccount DocsTODO
- * @description
- * @param
+ * @method loadAccount
+ * @description Performs all the action needed to retrieve the user account
+ * from Solana
* @example
+ * ```typescript
+ * this.$store.dispatch('accounts/loadAccount')
+ * ```
*/
async loadAccount({
commit,
@@ -145,73 +161,46 @@ export default {
await $SolanaManager.initializeFromMnemonic(mnemonic)
- const userAccount = $SolanaManager.getUserAccount()
+ const payerAccount = $SolanaManager.getActiveAccount()
- if (!userAccount) {
+ if (!payerAccount) {
throw new Error(AccountsError.USER_DERIVATION_FAILED)
}
- commit('setActiveAccount', userAccount?.publicKey.toBase58())
+ commit('setActiveAccount', payerAccount?.publicKey.toBase58())
- const serverProgram: ServerProgram = new ServerProgram($SolanaManager)
+ const usersProgram: UsersProgram = new UsersProgram($SolanaManager)
- const userInfo = await serverProgram.getUser(userAccount.publicKey)
+ const userInfo = await usersProgram.getCurrentUserInfo()
if (userInfo === null) {
throw new Error(AccountsError.USER_NOT_REGISTERED)
}
- // Initialize Encryption Engine
- dispatch('initializeEncryptionEngine', userAccount)
+ dispatch('initializeEncryptionEngine', payerAccount)
commit('setUserDetails', {
username: userInfo.name,
...userInfo,
})
- commit('prerequisites/setAccountsReady', true, { root: true })
-
- // TODO: move this logic into a startup action
- // Initialize textile
- const { pin } = state
- dispatch(
- 'textile/initialize',
- {
- id: userAccount?.publicKey.toBase58(),
- pass: pin,
- wallet: $SolanaManager.getMainSolanaWalletInstance(),
- },
- { root: true },
- )
-
- // initialize bucket and file system
- const $Bucket: Bucket = Vue.prototype.$Bucket
- const fsExport = await $Bucket.init({
- id: userAccount?.publicKey.toBase58(),
- pass: pin!,
- wallet: $SolanaManager.getMainSolanaWalletInstance(),
- name: 'personal-files',
- })
- if (fsExport) {
- const $FileSystem: FilSystem = Vue.prototype.$FileSystem
- $FileSystem.import(fsExport)
- }
-
- // Initialize WebRTC with our ID
- dispatch('webrtc/initialize', userAccount.publicKey.toBase58(), {
- root: true,
- })
-
- // Dispatch an action to fetch friends and friends requests
- dispatch('friends/fetchFriends', {}, { root: true })
- dispatch('friends/fetchFriendRequests', {}, { root: true })
- dispatch('friends/subscribeToFriendsEvents', {}, { root: true })
+ dispatch('startup', payerAccount)
},
/**
- * @method registerUser DocsTODO
- * @description
- * @param userData
+ * @method registerUser
+ * @description Registers a new user on the Solana blockchain
+ * @param userData User information to register
* @example
+ * ```typescript
+ * this.$store.dispatch(
+ * 'accounts/registerUser',
+ * {
+ * name: 'My Name',
+ * image: 'linkToMyImage',
+ * status: 'My amazing status message 🚀'
+ * }
+ * );
+ * ```
*/
async registerUser(
{ commit, state, dispatch }: ActionsArguments,
@@ -235,16 +224,9 @@ export default {
throw new Error(AccountsError.PAYER_NOT_PRESENT)
}
- const userAccount = await $SolanaManager.getUserAccount()
-
- if (!userAccount) {
- commit('setRegistrationStatus', RegistrationStatus.UNKNOWN)
- throw new Error(AccountsError.USER_DERIVATION_FAILED)
- }
-
- const serverProgram: ServerProgram = new ServerProgram($SolanaManager)
+ const usersProgram: UsersProgram = new UsersProgram($SolanaManager)
- const userInfo = await serverProgram.getUser(userAccount.publicKey)
+ const userInfo = await usersProgram.getCurrentUserInfo()
if (userInfo) {
commit('setRegistrationStatus', RegistrationStatus.REGISTERED)
@@ -259,7 +241,7 @@ export default {
await dispatch(
'textile/initialize',
{
- id: userAccount?.publicKey.toBase58(),
+ id: payerAccount?.publicKey.toBase58(),
pass: pin,
wallet: $SolanaManager.getMainSolanaWalletInstance(),
},
@@ -269,32 +251,72 @@ export default {
const imagePath = await uploadPicture(userData.image)
- await serverProgram.createUser(userData.name, imagePath, userData.status)
+ await usersProgram.create(userData.name, imagePath, userData.status)
commit('setRegistrationStatus', RegistrationStatus.REGISTERED)
- commit('setActiveAccount', userAccount.publicKey.toBase58())
+ commit('setActiveAccount', payerAccount.publicKey.toBase58())
+
+ dispatch('initializeEncryptionEngine', payerAccount)
- // Initialize Encryption Engine
- dispatch('initializeEncryptionEngine', userAccount)
commit('setUserDetails', {
username: userData.name,
status: userData.status,
photoHash: imagePath,
- address: userAccount.publicKey.toBase58(),
+ address: payerAccount.publicKey.toBase58(),
})
+
+ dispatch('startup', payerAccount)
},
/**
- * @method initializeEncryptionEngine DocsTODO
- * @description
- * @param userAccount
+ * @method initializeEncryptionEngine
+ * @description Initializes the Crypto class with the current user keypair
+ * @param userAccount keypair of the current user
* @example
+ * ```typescript
+ * this.$store.dispatch('accounts/initializeEncriptionEngin', currentUserAccount)
+ * ```
*/
- async initializeEncryptionEngine(_: RootState, userAccount: Keypair) {
+ async initializeEncryptionEngine(
+ _: ActionsArguments,
+ userAccount: Keypair,
+ ) {
// Initialize crypto engine
const $Crypto: Crypto = Vue.prototype.$Crypto
await $Crypto.init(userAccount)
},
+ async startup(
+ { dispatch, rootState, state }: ActionsArguments,
+ payerAccount: Keypair,
+ ) {
+ const $SolanaManager: SolanaManager = Vue.prototype.$SolanaManager
+
+ const { initialized: textileInitialized } = rootState.textile
+ const { initialized: webrtcInitialized } = rootState.webrtc
+
+ const { pin } = state
+ if (!textileInitialized && pin) {
+ dispatch(
+ 'textile/initialize',
+ {
+ id: payerAccount?.publicKey.toBase58(),
+ pass: pin,
+ wallet: $SolanaManager.getMainSolanaWalletInstance(),
+ },
+ { root: true },
+ )
+ }
+
+ if (!webrtcInitialized) {
+ dispatch('webrtc/initialize', payerAccount.publicKey.toBase58(), {
+ root: true,
+ })
+ }
+
+ dispatch('friends/fetchFriends', {}, { root: true })
+ dispatch('friends/fetchFriendRequests', {}, { root: true })
+ dispatch('friends/subscribeToFriendsEvents', {}, { root: true })
+ },
}
/**
diff --git a/store/accounts/mutations.ts b/store/accounts/mutations.ts
index 77775c8f53..931dd59437 100644
--- a/store/accounts/mutations.ts
+++ b/store/accounts/mutations.ts
@@ -29,6 +29,7 @@ const mutations = {
},
setActiveAccount(state: AccountsState, activeAccountPubkey: string) {
state.active = activeAccountPubkey
+ state.initialized = true
},
setUserDetails(state: AccountsState, details: UserRegistrationData) {
state.details = {
@@ -37,6 +38,7 @@ const mutations = {
profilePicture: details.photoHash,
address: state.active,
state: 'online',
+ lastUpdate: Date.now(),
}
},
updateMailboxId(state: AccountsState, mailboxId: string) {
diff --git a/store/accounts/state.ts b/store/accounts/state.ts
index 1b73dcc82d..720e474f92 100644
--- a/store/accounts/state.ts
+++ b/store/accounts/state.ts
@@ -1,6 +1,7 @@
import { AccountsState, RegistrationStatus } from './types'
const InitialAccountsState = (): AccountsState => ({
+ initialized: false,
storePin: false,
registry: true,
locked: true,
@@ -13,7 +14,7 @@ const InitialAccountsState = (): AccountsState => ({
loading: false,
registered: false,
registrationStatus: RegistrationStatus.UNKNOWN,
- lastVisited: '',
+ lastVisited: '/',
})
export default InitialAccountsState
diff --git a/store/accounts/types.ts b/store/accounts/types.ts
index 72f3db2b5e..ce563588b5 100644
--- a/store/accounts/types.ts
+++ b/store/accounts/types.ts
@@ -9,6 +9,7 @@ export enum RegistrationStatus {
}
export interface AccountsState {
+ initialized: boolean
storePin: boolean
registry: boolean
loading?: boolean
diff --git a/store/friends/actions.ts b/store/friends/actions.ts
index b97784c8b9..badcec9557 100644
--- a/store/friends/actions.ts
+++ b/store/friends/actions.ts
@@ -10,7 +10,6 @@ import {
import Crypto from '~/libraries/Crypto/Crypto'
import SolanaManager from '~/libraries/Solana/SolanaManager/SolanaManager'
import FriendsProgram from '~/libraries/Solana/FriendsProgram/FriendsProgram'
-import ServerProgram from '~/libraries/Solana/ServerProgram/ServerProgram'
import {
FriendAccount,
FriendsEvents,
@@ -24,8 +23,10 @@ import {
OutgoingRequest,
} from '~/types/ui/friends'
import { ActionsArguments } from '~/types/store/store'
-import { RawUser } from '~/types/ui/user'
import TextileManager from '~/libraries/Textile/TextileManager'
+import UsersProgram, {
+ UserInfo,
+} from '~/libraries/Solana/UsersProgram/UsersProgram'
export default {
/**
@@ -39,23 +40,21 @@ export default {
const friendsProgram: FriendsProgram = new FriendsProgram($SolanaManager)
- const serverProgram: ServerProgram = new ServerProgram($SolanaManager)
+ const usersProgram: UsersProgram = new UsersProgram($SolanaManager)
const { incoming, outgoing } =
await friendsProgram.getFriendAccountsByStatus(FriendStatus.PENDING)
const incomingRequests = await Promise.all(
incoming.map(async (account) => {
- const userInfo = await serverProgram.getUser(
- new PublicKey(account.from),
- )
+ const userInfo = await usersProgram.getUserInfo(account.from)
return friendAccountToIncomingRequest(account, userInfo)
}),
)
const outgoingRequests = await Promise.all(
outgoing.map(async (account) => {
- const userInfo = await serverProgram.getUser(new PublicKey(account.to))
+ const userInfo = await usersProgram.getUserInfo(account.to)
return friendAccountToOutgoingRequest(account, userInfo)
}),
)
@@ -109,7 +108,7 @@ export default {
friendAccount: FriendAccount,
) {
const $SolanaManager: SolanaManager = Vue.prototype.$SolanaManager
- const serverProgram: ServerProgram = new ServerProgram($SolanaManager)
+ const usersProgram: UsersProgram = new UsersProgram($SolanaManager)
const $Crypto: Crypto = Vue.prototype.$Crypto
// Check if the request was originally sent by the current user (outgoing)
@@ -128,16 +127,18 @@ export default {
friendKey,
encryptedTextilePubkey,
)
- const rawUser = await serverProgram.getUser(new PublicKey(friendKey))
- if (!rawUser) {
+
+ const userInfo = await usersProgram.getUserInfo(friendKey)
+
+ if (!userInfo) {
throw new Error(FriendsError.FRIEND_INFO_NOT_FOUND)
}
const friend: Omit = {
account: friendAccount,
- name: rawUser.name,
- profilePicture: rawUser.photoHash,
- status: rawUser.status,
+ name: userInfo.name,
+ profilePicture: userInfo.photoHash,
+ status: userInfo.status,
encryptedTextilePubkey,
textilePubkey,
item: {},
@@ -185,9 +186,7 @@ export default {
const friendsProgram: FriendsProgram = new FriendsProgram($SolanaManager)
- const serverProgram: ServerProgram = new ServerProgram($SolanaManager)
-
- const userAccount = $SolanaManager.getActiveAccount()
+ const usersProgram: UsersProgram = new UsersProgram($SolanaManager)
friendsProgram.subscribeToFriendsEvents()
@@ -195,9 +194,7 @@ export default {
FriendsEvents.NEW_REQUEST,
async (account) => {
if (account) {
- const userInfo = await serverProgram.getUser(
- new PublicKey(account.from),
- )
+ const userInfo = await usersProgram.getUserInfo(account.from)
commit(
'addIncomingRequest',
friendAccountToIncomingRequest(account, userInfo),
@@ -255,7 +252,7 @@ export default {
const $SolanaManager: SolanaManager = Vue.prototype.$SolanaManager
const $Crypto: Crypto = Vue.prototype.$Crypto
const $TextileManager: TextileManager = Vue.prototype.$TextileManager
- const serverProgram: ServerProgram = new ServerProgram($SolanaManager)
+ const usersProgram: UsersProgram = new UsersProgram($SolanaManager)
const textilePublicKey = $TextileManager.getIdentityPublicKey()
@@ -269,16 +266,10 @@ export default {
throw new Error(AccountsError.PAYER_NOT_PRESENT)
}
- const userAccount = await $SolanaManager.getUserAccount()
-
- if (!userAccount) {
- throw new Error(AccountsError.USER_DERIVATION_FAILED)
- }
-
const friendsProgram: FriendsProgram = new FriendsProgram($SolanaManager)
const friendAccountKey = await friendsProgram.computeFriendAccountKey(
- userAccount.publicKey,
+ payerAccount.publicKey,
friendToKey,
)
@@ -287,7 +278,7 @@ export default {
const friendAccountMirroredKey =
await friendsProgram.computeFriendAccountKey(
friendToKey,
- userAccount.publicKey,
+ payerAccount.publicKey,
)
let friendAccountMirroredInfo = await friendsProgram.getFriend(
@@ -296,7 +287,7 @@ export default {
if (!friendAccountInfo) {
friendAccountInfo = await friendsProgram.createFriend(
- userAccount.publicKey,
+ payerAccount.publicKey,
friendToKey,
)
}
@@ -304,7 +295,7 @@ export default {
if (!friendAccountMirroredInfo) {
friendAccountMirroredInfo = await friendsProgram.createFriend(
friendToKey,
- userAccount.publicKey,
+ payerAccount.publicKey,
)
}
@@ -334,7 +325,7 @@ export default {
const transactionHash = await friendsProgram.createFriendRequest(
friendAccountKey,
friendAccountMirroredKey,
- userAccount,
+ payerAccount,
friendToKey,
Buffer.from(encryptedTextilePublicKey.padStart(128, '0')),
)
@@ -345,9 +336,7 @@ export default {
)
if (parsedFriendRequest) {
- const userInfo = await serverProgram.getUser(
- new PublicKey(parsedFriendRequest.to),
- )
+ const userInfo = await usersProgram.getUserInfo(parsedFriendRequest.to)
commit(
'addOutgoingRequest',
friendAccountToOutgoingRequest(parsedFriendRequest, userInfo),
@@ -382,12 +371,6 @@ export default {
throw new Error(AccountsError.PAYER_NOT_PRESENT)
}
- const userAccount = await $SolanaManager.getUserAccount()
-
- if (!userAccount) {
- throw new Error(AccountsError.USER_DERIVATION_FAILED)
- }
-
const friendsProgram: FriendsProgram = new FriendsProgram($SolanaManager)
commit('updateIncomingRequest', { ...friendRequest, pending: true })
@@ -396,7 +379,7 @@ export default {
const computedFriendAccountKey =
await friendsProgram.computeFriendAccountKey(
new PublicKey(account.from),
- userAccount.publicKey,
+ payerAccount.publicKey,
)
const friendFromKey = friendRequest.account.from
@@ -413,7 +396,7 @@ export default {
const transactionId = await friendsProgram.acceptFriendRequest(
computedFriendAccountKey,
new PublicKey(account.from),
- userAccount,
+ payerAccount,
Buffer.from(encryptedIdentityPublicKey.padStart(128, '0')),
)
@@ -439,12 +422,6 @@ export default {
throw new Error(AccountsError.PAYER_NOT_PRESENT)
}
- const userAccount = await $SolanaManager.getUserAccount()
-
- if (!userAccount) {
- throw new Error(AccountsError.USER_DERIVATION_FAILED)
- }
-
const friendsProgram: FriendsProgram = new FriendsProgram($SolanaManager)
commit('updateIncomingRequest', { ...friendRequest, pending: true })
@@ -454,13 +431,13 @@ export default {
const computedFriendAccountKey =
await friendsProgram.computeFriendAccountKey(
new PublicKey(account.from),
- userAccount.publicKey,
+ payerAccount.publicKey,
)
const transactionId = await friendsProgram.denyFriendRequest(
computedFriendAccountKey,
new PublicKey(account.from),
- userAccount,
+ payerAccount,
)
if (transactionId) {
@@ -488,12 +465,6 @@ export default {
throw new Error(AccountsError.PAYER_NOT_PRESENT)
}
- const userAccount = await $SolanaManager.getUserAccount()
-
- if (!userAccount) {
- throw new Error(AccountsError.USER_DERIVATION_FAILED)
- }
-
const friendsProgram: FriendsProgram = new FriendsProgram($SolanaManager)
commit('updateOutgoingRequest', { ...friendRequest, pending: true })
@@ -502,13 +473,13 @@ export default {
const computedFriendAccountMirroredKey =
await friendsProgram.computeFriendAccountKey(
- userAccount.publicKey,
+ payerAccount.publicKey,
new PublicKey(account.to),
)
const transactionId = await friendsProgram.removeFriendRequest(
computedFriendAccountMirroredKey,
- userAccount,
+ payerAccount,
new PublicKey(account.to),
)
@@ -537,19 +508,13 @@ export default {
throw new Error(AccountsError.PAYER_NOT_PRESENT)
}
- const userAccount = await $SolanaManager.getUserAccount()
-
- if (!userAccount) {
- throw new Error(AccountsError.USER_DERIVATION_FAILED)
- }
-
const friendsProgram: FriendsProgram = new FriendsProgram($SolanaManager)
const { account } = friend
const transactionId = await friendsProgram.removeFriend(
account,
- userAccount,
+ payerAccount,
)
if (transactionId) {
@@ -566,7 +531,7 @@ export default {
*/
function friendAccountToIncomingRequest(
friendAccount: FriendAccount,
- userInfo: RawUser | null,
+ userInfo: UserInfo | null,
): IncomingRequest {
return {
requestId: friendAccount.accountId,
@@ -585,7 +550,7 @@ function friendAccountToIncomingRequest(
*/
function friendAccountToOutgoingRequest(
friendAccount: FriendAccount,
- userInfo: RawUser | null,
+ userInfo: UserInfo | null,
): OutgoingRequest {
return {
requestId: friendAccount.accountId,
diff --git a/store/getters.ts b/store/getters.ts
new file mode 100644
index 0000000000..a858f0593e
--- /dev/null
+++ b/store/getters.ts
@@ -0,0 +1,13 @@
+import { RootState } from '~/types/store/store'
+
+const getters = {
+ allPrerequisitesReady: (state: RootState): boolean => {
+ return (
+ Boolean(state.accounts.active) &&
+ state.textile.initialized &&
+ state.webrtc.initialized
+ )
+ },
+}
+
+export default getters
diff --git a/store/prerequisites/Readme.md b/store/prerequisites/Readme.md
deleted file mode 100644
index d8d416e61d..0000000000
--- a/store/prerequisites/Readme.md
+++ /dev/null
@@ -1,3 +0,0 @@
-# Prerequisites
-
-These are state values which are required to exist before the application can be considered "loaded".
diff --git a/store/prerequisites/__snapshots__/getters.test.ts.snap b/store/prerequisites/__snapshots__/getters.test.ts.snap
deleted file mode 100644
index 18d5eb449a..0000000000
--- a/store/prerequisites/__snapshots__/getters.test.ts.snap
+++ /dev/null
@@ -1,9 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`getters.default.allPrerequisitesReady 0 1`] = `false`;
-
-exports[`getters.default.allPrerequisitesReady 1 1`] = `false`;
-
-exports[`getters.default.allPrerequisitesReady 2 1`] = `true`;
-
-exports[`getters.default.allPrerequisitesReady 3 1`] = `false`;
diff --git a/store/prerequisites/__snapshots__/mutations.test.ts.snap b/store/prerequisites/__snapshots__/mutations.test.ts.snap
deleted file mode 100644
index 8d328ca82a..0000000000
--- a/store/prerequisites/__snapshots__/mutations.test.ts.snap
+++ /dev/null
@@ -1,41 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`mutations.default.resetState 0 1`] = `undefined`;
-
-exports[`mutations.default.resetState 1 1`] = `undefined`;
-
-exports[`mutations.default.resetState 2 1`] = `undefined`;
-
-exports[`mutations.default.resetState 3 1`] = `undefined`;
-
-exports[`mutations.default.resetState 4 1`] = `undefined`;
-
-exports[`mutations.default.setAccountsReady 0 1`] = `undefined`;
-
-exports[`mutations.default.setAccountsReady 1 1`] = `undefined`;
-
-exports[`mutations.default.setAccountsReady 2 1`] = `undefined`;
-
-exports[`mutations.default.setAccountsReady 3 1`] = `undefined`;
-
-exports[`mutations.default.setAccountsReady 4 1`] = `undefined`;
-
-exports[`mutations.default.setP2PReady 0 1`] = `undefined`;
-
-exports[`mutations.default.setP2PReady 1 1`] = `undefined`;
-
-exports[`mutations.default.setP2PReady 2 1`] = `undefined`;
-
-exports[`mutations.default.setP2PReady 3 1`] = `undefined`;
-
-exports[`mutations.default.setP2PReady 4 1`] = `undefined`;
-
-exports[`mutations.default.setTextileReady 0 1`] = `undefined`;
-
-exports[`mutations.default.setTextileReady 1 1`] = `undefined`;
-
-exports[`mutations.default.setTextileReady 2 1`] = `undefined`;
-
-exports[`mutations.default.setTextileReady 3 1`] = `undefined`;
-
-exports[`mutations.default.setTextileReady 4 1`] = `undefined`;
diff --git a/store/prerequisites/__snapshots__/state.test.ts.snap b/store/prerequisites/__snapshots__/state.test.ts.snap
deleted file mode 100644
index 6a8409e4b2..0000000000
--- a/store/prerequisites/__snapshots__/state.test.ts.snap
+++ /dev/null
@@ -1,9 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`state.default 0 1`] = `
-Object {
- "accountsReady": false,
- "p2pReady": true,
- "textileReady": false,
-}
-`;
diff --git a/store/prerequisites/actions.test.ts b/store/prerequisites/actions.test.ts
deleted file mode 100644
index da7f4dd83e..0000000000
--- a/store/prerequisites/actions.test.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import Vue from 'vue'
-import actions from '~/store/prerequisites/actions'
-import * as Logger from '~/utilities/Logger'
-import { Config } from '~/config'
-
-Vue.prototype.$Config = Config
-
-const DefaultLogger = Logger.default
-Vue.prototype.$Logger = new DefaultLogger(Vue.prototype.$Config.debug)
-
-describe('actions.default.startup', () => {
- test('0', async () => {
- const LoggerPrototype = Vue.prototype.$Logger
-
- const dispatch = jest.fn()
- LoggerPrototype.log = jest.fn()
-
- await actions.startup({ dispatch })
-
- expect(LoggerPrototype.log).toHaveBeenCalled()
- expect(LoggerPrototype.log).toHaveBeenCalledWith('WebRTC', 'Identified')
- })
-})
diff --git a/store/prerequisites/actions.ts b/store/prerequisites/actions.ts
deleted file mode 100644
index 6ec6b40f1c..0000000000
--- a/store/prerequisites/actions.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-import Vue from 'vue'
-import { PrerequisiteState } from './types'
-import { ActionsArguments } from '~/types/store/store'
-
-export default {
- /**
- * @method startup DocsTODO
- * @description
- * @param
- * @example
- */
- async startup({ dispatch }: ActionsArguments) {
- Vue.prototype.$Logger.log('WebRTC', 'Identified')
- },
-}
diff --git a/store/prerequisites/getters.test.ts b/store/prerequisites/getters.test.ts
deleted file mode 100644
index 44f79b1a73..0000000000
--- a/store/prerequisites/getters.test.ts
+++ /dev/null
@@ -1,39 +0,0 @@
-import * as getters from '~/store/prerequisites/getters'
-
-describe('getters.default.allPrerequisitesReady', () => {
- test('0', () => {
- const result: any = getters.default.allPrerequisitesReady({
- accountsReady: true,
- textileReady: false,
- p2pReady: false,
- })
- expect(result).toMatchSnapshot()
- })
-
- test('1', () => {
- const result: any = getters.default.allPrerequisitesReady({
- accountsReady: true,
- textileReady: true,
- p2pReady: false,
- })
- expect(result).toMatchSnapshot()
- })
-
- test('2', () => {
- const result: any = getters.default.allPrerequisitesReady({
- accountsReady: true,
- textileReady: true,
- p2pReady: true,
- })
- expect(result).toMatchSnapshot()
- })
-
- test('3', () => {
- const result: any = getters.default.allPrerequisitesReady({
- accountsReady: true,
- textileReady: false,
- p2pReady: true,
- })
- expect(result).toMatchSnapshot()
- })
-})
diff --git a/store/prerequisites/getters.ts b/store/prerequisites/getters.ts
deleted file mode 100644
index 93b973930e..0000000000
--- a/store/prerequisites/getters.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-import { PrerequisiteState } from './types'
-
-const getters = {
- allPrerequisitesReady: (state: PrerequisiteState): boolean => {
- return Object.values(state).reduce(
- (stateLoaded, prerequisite) => stateLoaded && prerequisite,
- true,
- )
- },
-}
-
-export default getters
diff --git a/store/prerequisites/mutations.test.ts b/store/prerequisites/mutations.test.ts
deleted file mode 100644
index e0e7c40f49..0000000000
--- a/store/prerequisites/mutations.test.ts
+++ /dev/null
@@ -1,174 +0,0 @@
-import * as mutations from '~/store/prerequisites/mutations'
-
-describe('mutations.default.setTextileReady', () => {
- test('0', () => {
- const result: any = mutations.default.setTextileReady(
- { accountsReady: true, textileReady: true, p2pReady: true },
- true,
- )
- expect(result).toMatchSnapshot()
- })
-
- test('1', () => {
- const result: any = mutations.default.setTextileReady(
- { accountsReady: true, textileReady: false, p2pReady: false },
- false,
- )
- expect(result).toMatchSnapshot()
- })
-
- test('2', () => {
- const result: any = mutations.default.setTextileReady(
- { accountsReady: true, textileReady: true, p2pReady: false },
- true,
- )
- expect(result).toMatchSnapshot()
- })
-
- test('3', () => {
- const result: any = mutations.default.setTextileReady(
- { accountsReady: true, textileReady: false, p2pReady: false },
- true,
- )
- expect(result).toMatchSnapshot()
- })
-
- test('4', () => {
- const result: any = mutations.default.setTextileReady(
- { accountsReady: true, textileReady: false, p2pReady: true },
- false,
- )
- expect(result).toMatchSnapshot()
- })
-})
-
-describe('mutations.default.setP2PReady', () => {
- test('0', () => {
- const result: any = mutations.default.setP2PReady(
- { accountsReady: true, textileReady: false, p2pReady: false },
- false,
- )
- expect(result).toMatchSnapshot()
- })
-
- test('1', () => {
- const result: any = mutations.default.setP2PReady(
- { accountsReady: true, textileReady: true, p2pReady: false },
- true,
- )
- expect(result).toMatchSnapshot()
- })
-
- test('2', () => {
- const result: any = mutations.default.setP2PReady(
- { accountsReady: true, textileReady: false, p2pReady: true },
- true,
- )
- expect(result).toMatchSnapshot()
- })
-
- test('3', () => {
- const result: any = mutations.default.setP2PReady(
- { accountsReady: false, textileReady: false, p2pReady: true },
- true,
- )
- expect(result).toMatchSnapshot()
- })
-
- test('4', () => {
- const result: any = mutations.default.setP2PReady(
- { accountsReady: false, textileReady: false, p2pReady: false },
- true,
- )
- expect(result).toMatchSnapshot()
- })
-})
-
-describe('mutations.default.setAccountsReady', () => {
- test('0', () => {
- const result: any = mutations.default.setAccountsReady(
- { accountsReady: true, textileReady: true, p2pReady: true },
- true,
- )
- expect(result).toMatchSnapshot()
- })
-
- test('1', () => {
- const result: any = mutations.default.setAccountsReady(
- { accountsReady: false, textileReady: true, p2pReady: false },
- true,
- )
- expect(result).toMatchSnapshot()
- })
-
- test('2', () => {
- const result: any = mutations.default.setAccountsReady(
- { accountsReady: false, textileReady: false, p2pReady: true },
- false,
- )
- expect(result).toMatchSnapshot()
- })
-
- test('3', () => {
- const result: any = mutations.default.setAccountsReady(
- { accountsReady: false, textileReady: false, p2pReady: false },
- false,
- )
- expect(result).toMatchSnapshot()
- })
-
- test('4', () => {
- const result: any = mutations.default.setAccountsReady(
- { accountsReady: true, textileReady: false, p2pReady: true },
- false,
- )
- expect(result).toMatchSnapshot()
- })
-})
-
-describe('mutations.default.resetState', () => {
- test('0', () => {
- const result: any = mutations.default.resetState({
- accountsReady: false,
- textileReady: true,
- p2pReady: true,
- })
- expect(result).toMatchSnapshot()
- })
-
- test('1', () => {
- const result: any = mutations.default.resetState({
- accountsReady: true,
- textileReady: false,
- p2pReady: true,
- })
- expect(result).toMatchSnapshot()
- })
-
- test('2', () => {
- const result: any = mutations.default.resetState({
- accountsReady: false,
- textileReady: true,
- p2pReady: false,
- })
- expect(result).toMatchSnapshot()
- })
-
- test('3', () => {
- const result: any = mutations.default.resetState({
- accountsReady: true,
- textileReady: true,
- p2pReady: true,
- })
- expect(result).toMatchSnapshot()
- })
-
- test('4', () => {
- const result: any = mutations.default.resetState({
- accountsReady: true,
- textileReady: false,
- p2pReady: false,
- })
- expect(result).toMatchSnapshot()
- })
-})
diff --git a/store/prerequisites/mutations.ts b/store/prerequisites/mutations.ts
deleted file mode 100644
index d32cdb97ff..0000000000
--- a/store/prerequisites/mutations.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-import { PrerequisiteState } from './types'
-import getInitialState from './state'
-
-const mutations = {
- setAccountsReady(state: PrerequisiteState, accountsReady: boolean) {
- state.accountsReady = accountsReady
- },
- setP2PReady(state: PrerequisiteState, p2pReady: boolean) {
- state.p2pReady = p2pReady
- },
- setTextileReady(state: PrerequisiteState, textileReady: boolean) {
- state.textileReady = textileReady
- },
- resetState(state: PrerequisiteState) {
- const initialState = getInitialState()
- state.accountsReady = initialState.accountsReady
- state.p2pReady = initialState.p2pReady
- state.textileReady = initialState.textileReady
- },
-}
-
-export default mutations
diff --git a/store/prerequisites/state.test.ts b/store/prerequisites/state.test.ts
deleted file mode 100644
index f5a771b47d..0000000000
--- a/store/prerequisites/state.test.ts
+++ /dev/null
@@ -1,8 +0,0 @@
-import * as state from '~/store/prerequisites/state'
-
-describe('state.default', () => {
- test('0', () => {
- const result: any = state.default()
- expect(result).toMatchSnapshot()
- })
-})
diff --git a/store/prerequisites/state.ts b/store/prerequisites/state.ts
deleted file mode 100644
index 9762beb185..0000000000
--- a/store/prerequisites/state.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-import { PrerequisiteState } from './types'
-
-const InitialPrerequisitesState = (): PrerequisiteState => ({
- accountsReady: false,
- p2pReady: true,
- textileReady: false,
-})
-
-export default InitialPrerequisitesState
diff --git a/store/prerequisites/types.ts b/store/prerequisites/types.ts
deleted file mode 100644
index e447dc4f2b..0000000000
--- a/store/prerequisites/types.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-export interface PrerequisiteState {
- accountsReady: boolean
- textileReady: boolean
- p2pReady: boolean
-}
diff --git a/store/textile/actions.ts b/store/textile/actions.ts
index 88c7ab9298..6063f7cdda 100644
--- a/store/textile/actions.ts
+++ b/store/textile/actions.ts
@@ -10,6 +10,7 @@ import { MailboxSubscriptionType, Message } from '~/types/textile/mailbox'
import { UploadDropItemType } from '~/types/files/file'
import { db, DexieMessage } from '~/plugins/thirdparty/dexie'
import { GroupChatManager } from '~/libraries/Textile/GroupChatManager'
+import { FilSystem } from '~/libraries/Files/FilSystem'
export default {
/**
@@ -32,8 +33,12 @@ export default {
commit('textileInitialized', true)
commit('accounts/updateTextilePubkey', textilePublicKey, { root: true })
- // Set Textile Ready prerequisite as true
- commit('prerequisites/setTextileReady', true, { root: true })
+ const fsExport = $TextileManager.bucket?.index
+
+ if (fsExport) {
+ const $FileSystem: FilSystem = Vue.prototype.$FileSystem
+ $FileSystem.import(fsExport)
+ }
},
/**
* @description Fetches messages that comes from a specific user
diff --git a/store/ui/actions.test.ts b/store/ui/actions.test.ts
index 683452a31e..6ac3b54385 100644
--- a/store/ui/actions.test.ts
+++ b/store/ui/actions.test.ts
@@ -119,11 +119,6 @@ const initialRootState: any = {
},
},
},
- prerequisites: {
- accountsReady: true,
- textileReady: true,
- p2pReady: true,
- },
settings: {
audioInput: '',
audioOutput: '',
diff --git a/store/ui/mutations.test.ts b/store/ui/mutations.test.ts
index 8111a1e9a9..df375abb4a 100644
--- a/store/ui/mutations.test.ts
+++ b/store/ui/mutations.test.ts
@@ -1,10 +1,10 @@
+import state from '../friends/state'
import * as mutations from '~/store/ui/mutations'
import { RegistrationStatus } from '~/store/accounts/types'
import { DataStateType } from '~/store/dataState/types'
import { CaptureMouseTypes } from '~/store/settings/types'
import { FlairColors, ThemeNames } from '~/store/ui/types'
-import state from '../friends/state'
// So we don't have annoying snapshot fails. (https://stackoverflow.com/questions/42935903/jest-snapshot-testing-how-to-ignore-part-of-the-snapshot-file-in-jest-test-resu)
Date.now = jest.fn(() => 1645617999076)
@@ -2912,11 +2912,6 @@ describe('mutations', () => {
},
},
},
- prerequisites: {
- accountsReady: true,
- textileReady: true,
- p2pReady: true,
- },
settings: {
audioInput: '',
audioOutput: '',
diff --git a/store/webrtc/actions.ts b/store/webrtc/actions.ts
index 753ebc718a..222c557e6c 100644
--- a/store/webrtc/actions.ts
+++ b/store/webrtc/actions.ts
@@ -6,7 +6,6 @@ import Crypto from '~/libraries/Crypto/Crypto'
import { ActionsArguments } from '~/types/store/store'
import WebRTC from '~/libraries/WebRTC/WebRTC'
import Logger from '~/utilities/Logger'
-import { TracksManager } from '~/libraries/WebRTC/TracksManager'
export default {
/**
@@ -29,9 +28,11 @@ export default {
$Logger.log('WebRTC', 'PEER_CONNECT', { peerId })
commit('setConnectedPeer', peerId)
})
+
$WebRTC.on('ERROR', () => {
commit('setConnectedPeer', '')
})
+
commit('setInitialized', true)
},
/**
@@ -46,7 +47,6 @@ export default {
identifier: string,
) {
const $WebRTC: WebRTC = Vue.prototype.$WebRTC
- const $TracksManager: TracksManager = Vue.prototype.$TracksManager
const $Crypto: Crypto = Vue.prototype.$Crypto
if (!$WebRTC.initialized) {
@@ -73,13 +73,6 @@ export default {
)
})
- // peer?.communicationBus.on('RAW_DATA', (message) => {
- // if (message.data.type === 'CALL_DENIED') {
- // peer?.call.hangUp()
- // dispatch('hangUp')
- // }
- // })
-
peer?.call.on('INCOMING_CALL', (data) => {
// if incoming call is activer call return before toggling incoming call
if (state.activeCall === data.peerId) {
diff --git a/types/store/store.ts b/types/store/store.ts
index 767829c6d6..74402b372d 100644
--- a/types/store/store.ts
+++ b/types/store/store.ts
@@ -3,15 +3,15 @@ import { Store, Commit, Dispatch } from 'vuex'
import { AccountsState } from '~/store/accounts/types'
import { DataState } from '~/store/dataState/types'
import { FriendsState } from '~/store/friends/types'
-import { PrerequisiteState } from '~/store/prerequisites/types'
import { TextileState } from '~/store/textile/types'
+import { WebRTCState } from '~/store/webrtc/types'
export interface RootState {
accounts: AccountsState
dataState: DataState
friends: FriendsState
textile: TextileState
- prerequisites: PrerequisiteState
+ webrtc: WebRTCState
}
export type RootStore = Store
diff --git a/types/ui/friends.d.ts b/types/ui/friends.d.ts
index b97dbe69f0..7173de9d74 100644
--- a/types/ui/friends.d.ts
+++ b/types/ui/friends.d.ts
@@ -1,5 +1,6 @@
import { FriendAccount } from '~/libraries/Solana/FriendsProgram/FriendsProgram.types'
-import { RawUser, User } from '~/types/ui/user'
+import { UserInfo } from '~/libraries/Solana/UsersProgram/UsersProgram'
+import { User } from '~/types/ui/user'
export interface EncryptedFriend extends User {
encryptedTextilePubkey: string
@@ -9,7 +10,7 @@ export interface FriendRequest {
requestId: string
account: FriendAccount
pending: boolean
- userInfo: RawUser
+ userInfo: UserInfo | null
}
export interface IncomingRequest extends FriendRequest {
diff --git a/utilities/Hounddog.test.ts b/utilities/Hounddog.test.ts
index f6a1309fa3..0f89e8977a 100644
--- a/utilities/Hounddog.test.ts
+++ b/utilities/Hounddog.test.ts
@@ -119,11 +119,6 @@ describe("Retrieving friend's profile", () => {
},
},
},
- prerequisites: {
- accountsReady: true,
- textileReady: true,
- p2pReady: true,
- },
}
beforeEach(() => {