+
From 70ad39597f5fbd1389bf558477900d913df2da53 Mon Sep 17 00:00:00 2001
From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com>
Date: Wed, 1 May 2024 00:00:22 +0400
Subject: [PATCH 80/90] refactor: code improvement
---
apps/ui/src/networks/offchain/api/index.ts | 5 +-
apps/ui/src/stores/bookmarks.ts | 68 +++++++++++-----------
2 files changed, 39 insertions(+), 34 deletions(-)
diff --git a/apps/ui/src/networks/offchain/api/index.ts b/apps/ui/src/networks/offchain/api/index.ts
index a55466cf8..80013a5f7 100644
--- a/apps/ui/src/networks/offchain/api/index.ts
+++ b/apps/ui/src/networks/offchain/api/index.ts
@@ -360,7 +360,10 @@ export function createApi(uri: string, networkId: NetworkID): NetworkApi {
}
});
- return follows;
+ return follows.map(follow => {
+ follow.space.network = networkId;
+ return follow;
+ });
}
};
}
diff --git a/apps/ui/src/stores/bookmarks.ts b/apps/ui/src/stores/bookmarks.ts
index d57868242..c1109025b 100644
--- a/apps/ui/src/stores/bookmarks.ts
+++ b/apps/ui/src/stores/bookmarks.ts
@@ -5,6 +5,10 @@ import { Space } from '@/types';
const offchainNetworkId = offchainNetworks.filter(network => enabledNetworks.includes(network))[0];
+function compositeSpaceId(space: Space) {
+ return `${space.network}:${space.id}`;
+}
+
export const useBookmarksStore = defineStore('bookmarks', () => {
const { web3, authInitiated } = useWeb3();
const spacesStore = useSpacesStore();
@@ -29,7 +33,7 @@ export const useBookmarksStore = defineStore('bookmarks', () => {
);
const bookmarkedSpacesMap = computed(
- () => new Map(spacesData.value.map(space => [`${space.network}:${space.id}`, space]))
+ () => new Map(spacesData.value.map(space => [compositeSpaceId(space), space]))
);
const bookmarkedSpaces = computed({
@@ -41,18 +45,42 @@ export const useBookmarksStore = defineStore('bookmarks', () => {
set(spaces: Space[]) {
starredSpacesIds.value = spaces
.filter(space => space.network !== offchainNetworkId)
- .map(space => `${space.network}:${space.id}`);
+ .map(compositeSpaceId);
- accountsBookmarkedSpacesIds.value[web3.value.account] = spaces.map(
- space => `${space.network}:${space.id}`
- );
+ accountsBookmarkedSpacesIds.value[web3.value.account] = spaces.map(compositeSpaceId);
}
});
+ function syncBookmarkedSpacesIds(spaceIds: string[], type: 'starred' | 'followed') {
+ accountsBookmarkedSpacesIds.value[web3.value.account] = Array.from(
+ new Set(
+ [...bookmarkedSpacesIds.value, ...spaceIds].filter(
+ id =>
+ id.startsWith(`${offchainNetworkId}:`) !== (type === 'followed') ||
+ spaceIds.includes(id)
+ )
+ )
+ );
+ }
+
+ async function fetchSpacesData(ids: string[]) {
+ if (!ids.length) return;
+
+ const spaces = await getSpaces({
+ id_in: ids.filter(id => !spacesMap.has(id))
+ });
+
+ spacesData.value = [
+ ...spacesData.value,
+ ...spaces,
+ ...(ids.map(id => spacesMap.get(id)).filter(Boolean) as Space[])
+ ];
+ }
+
async function loadFollowedSpaces() {
const network = getNetwork(offchainNetworkId);
- const followedIds = (await network.api.loadFollows(web3.value.account)).map(
- follow => `${offchainNetworkId}:${follow.space.id}`
+ const followedIds = (await network.api.loadFollows(web3.value.account)).map(follow =>
+ compositeSpaceId(follow.space)
);
const newIds = followedIds.filter(id => !followedSpacesIds.value.includes(id));
followedSpacesIds.value = followedIds;
@@ -80,32 +108,6 @@ export const useBookmarksStore = defineStore('bookmarks', () => {
});
}
- async function fetchSpacesData(ids: string[]) {
- if (!ids.length) return;
-
- const spaces = await getSpaces({
- id_in: ids.filter(id => !spacesMap.has(id))
- });
-
- spacesData.value = [
- ...spacesData.value,
- ...spaces,
- ...(ids.map(id => spacesMap.get(id)).filter(Boolean) as Space[])
- ];
- }
-
- function syncBookmarkedSpacesIds(spaceIds: string[], type: 'starred' | 'followed') {
- accountsBookmarkedSpacesIds.value[web3.value.account] = Array.from(
- new Set(
- [...bookmarkedSpacesIds.value, ...spaceIds].filter(
- id =>
- id.startsWith(`${offchainNetworkId}:`) !== (type === 'followed') ||
- spaceIds.includes(id)
- )
- )
- );
- }
-
watch(
starredSpacesIds,
async (currentIds, previousIds) => {
From 23c8246008f08bec1feb57768ee8d7fca1d7a27b Mon Sep 17 00:00:00 2001
From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com>
Date: Wed, 1 May 2024 00:43:07 +0400
Subject: [PATCH 81/90] refactor: code DRYing
---
apps/ui/src/components/SpacesListItem.vue | 5 +----
apps/ui/src/stores/bookmarks.ts | 15 ++++++++++++---
apps/ui/src/views/Space/Overview.vue | 4 ++--
3 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/apps/ui/src/components/SpacesListItem.vue b/apps/ui/src/components/SpacesListItem.vue
index ec9d69f7e..d5b094b82 100644
--- a/apps/ui/src/components/SpacesListItem.vue
+++ b/apps/ui/src/components/SpacesListItem.vue
@@ -28,10 +28,7 @@ const spaceIdComposite = `${props.space.network}:${props.space.id}`;
class="hidden group-hover:block absolute top-3 right-3 hover:text-skin-link"
@click.prevent="bookmarksStore.toggleSpaceStar(spaceIdComposite)"
>
-
+
diff --git a/apps/ui/src/stores/bookmarks.ts b/apps/ui/src/stores/bookmarks.ts
index c1109025b..1e0124d7c 100644
--- a/apps/ui/src/stores/bookmarks.ts
+++ b/apps/ui/src/stores/bookmarks.ts
@@ -82,7 +82,7 @@ export const useBookmarksStore = defineStore('bookmarks', () => {
const followedIds = (await network.api.loadFollows(web3.value.account)).map(follow =>
compositeSpaceId(follow.space)
);
- const newIds = followedIds.filter(id => !followedSpacesIds.value.includes(id));
+ const newIds = followedIds.filter(id => !isFollowed(id));
followedSpacesIds.value = followedIds;
syncBookmarkedSpacesIds(followedIds, 'followed');
@@ -90,7 +90,7 @@ export const useBookmarksStore = defineStore('bookmarks', () => {
}
function toggleSpaceStar(id: string) {
- const alreadyStarred = starredSpacesIds.value.includes(id);
+ const alreadyStarred = isStarred(id);
if (alreadyStarred) {
starredSpacesIds.value = starredSpacesIds.value.filter((spaceId: string) => spaceId !== id);
@@ -108,6 +108,14 @@ export const useBookmarksStore = defineStore('bookmarks', () => {
});
}
+ function isStarred(spaceId: string) {
+ return starredSpacesIds.value.includes(spaceId);
+ }
+
+ function isFollowed(spaceId: string) {
+ return followedSpacesIds.value.includes(spaceId);
+ }
+
watch(
starredSpacesIds,
async (currentIds, previousIds) => {
@@ -147,10 +155,11 @@ export const useBookmarksStore = defineStore('bookmarks', () => {
return {
bookmarkedSpaces,
bookmarksLoaded,
- starredSpacesIds,
starredSpacesLoaded,
followedSpacesIds,
followedSpacesLoaded,
+ isStarred,
+ isFollowed,
toggleSpaceStar
};
});
diff --git a/apps/ui/src/views/Space/Overview.vue b/apps/ui/src/views/Space/Overview.vue
index 34c57d01b..abbfe167e 100644
--- a/apps/ui/src/views/Space/Overview.vue
+++ b/apps/ui/src/views/Space/Overview.vue
@@ -27,8 +27,8 @@ onMounted(() => {
const spaceIdComposite = `${props.space.network}:${props.space.id}`;
const isOffchainSpace = offchainNetworks.includes(props.space.network);
-const spaceStarred = computed(() => bookmarksStore.starredSpacesIds.includes(spaceIdComposite));
-const spaceFollowed = computed(() => bookmarksStore.followedSpacesIds.includes(spaceIdComposite));
+const spaceStarred = computed(() => bookmarksStore.isStarred(spaceIdComposite));
+const spaceFollowed = computed(() => bookmarksStore.isFollowed(spaceIdComposite));
const isController = computed(() => compareAddresses(props.space.controller, web3.value.account));
const socials = computed(() =>
From 6e0b892e7630beb0d49c621982ad7ed35c8e7915 Mon Sep 17 00:00:00 2001
From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com>
Date: Wed, 1 May 2024 01:20:34 +0400
Subject: [PATCH 82/90] fix: populate spaces store
---
apps/ui/src/stores/bookmarks.ts | 11 +++++-----
apps/ui/src/stores/spaces.ts | 38 ++++++++++++++++++++++-----------
2 files changed, 31 insertions(+), 18 deletions(-)
diff --git a/apps/ui/src/stores/bookmarks.ts b/apps/ui/src/stores/bookmarks.ts
index 1e0124d7c..3fede06c1 100644
--- a/apps/ui/src/stores/bookmarks.ts
+++ b/apps/ui/src/stores/bookmarks.ts
@@ -12,7 +12,6 @@ function compositeSpaceId(space: Space) {
export const useBookmarksStore = defineStore('bookmarks', () => {
const { web3, authInitiated } = useWeb3();
const spacesStore = useSpacesStore();
- const { spacesMap, getSpaces } = spacesStore;
const { mixpanel } = useMixpanel();
const spacesData = ref([]);
@@ -66,14 +65,14 @@ export const useBookmarksStore = defineStore('bookmarks', () => {
async function fetchSpacesData(ids: string[]) {
if (!ids.length) return;
- const spaces = await getSpaces({
- id_in: ids.filter(id => !spacesMap.has(id))
- });
+ await spacesStore.fetchSpaces(
+ ids.filter(id => !spacesStore.spacesMap.has(id)).map(id => id.split(':')[1]),
+ offchainNetworkId
+ );
spacesData.value = [
...spacesData.value,
- ...spaces,
- ...(ids.map(id => spacesMap.get(id)).filter(Boolean) as Space[])
+ ...(ids.map(id => spacesStore.spacesMap.get(id)).filter(Boolean) as Space[])
];
}
diff --git a/apps/ui/src/stores/spaces.ts b/apps/ui/src/stores/spaces.ts
index 7ce7c4c39..0aad02bae 100644
--- a/apps/ui/src/stores/spaces.ts
+++ b/apps/ui/src/stores/spaces.ts
@@ -5,17 +5,8 @@ import { NetworkID } from '@/types';
export const useSpacesStore = defineStore('spaces', () => {
const metaStore = useMetaStore();
- const {
- loading,
- loaded,
- networksMap,
- spaces,
- spacesMap,
- hasMoreSpaces,
- fetch,
- fetchMore,
- getSpaces
- } = useSpaces();
+ const { loading, loaded, networksMap, spaces, spacesMap, hasMoreSpaces, fetch, fetchMore } =
+ useSpaces();
async function fetchSpace(spaceId: string, networkId: NetworkID) {
await metaStore.fetchBlock(networkId);
@@ -31,6 +22,29 @@ export const useSpacesStore = defineStore('spaces', () => {
};
}
+ async function fetchSpaces(spaceIds: string[], networkId: NetworkID) {
+ await metaStore.fetchBlock(networkId);
+
+ const network = getNetwork(networkId);
+
+ const spaces = await network.api.loadSpaces(
+ {
+ skip: 0,
+ limit: 100
+ },
+ {
+ id_in: spaceIds
+ }
+ );
+
+ if (!spaces.length) return;
+
+ networksMap.value[networkId].spaces = {
+ ...networksMap.value[networkId].spaces,
+ ...Object.fromEntries(spaces.map(space => [space.id, space]))
+ };
+ }
+
return {
loading,
loaded,
@@ -41,6 +55,6 @@ export const useSpacesStore = defineStore('spaces', () => {
fetch,
fetchMore,
fetchSpace,
- getSpaces
+ fetchSpaces
};
});
From f6ca94ba383d29af9e710ba4af18ec04c3b08efa Mon Sep 17 00:00:00 2001
From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com>
Date: Wed, 1 May 2024 01:41:57 +0400
Subject: [PATCH 83/90] fix: fix spaces fetching for multiple network type
---
apps/ui/src/stores/bookmarks.ts | 17 +++++++-------
apps/ui/src/stores/spaces.ts | 41 +++++++++++++++++----------------
2 files changed, 30 insertions(+), 28 deletions(-)
diff --git a/apps/ui/src/stores/bookmarks.ts b/apps/ui/src/stores/bookmarks.ts
index 3fede06c1..f84ecfc08 100644
--- a/apps/ui/src/stores/bookmarks.ts
+++ b/apps/ui/src/stores/bookmarks.ts
@@ -65,10 +65,7 @@ export const useBookmarksStore = defineStore('bookmarks', () => {
async function fetchSpacesData(ids: string[]) {
if (!ids.length) return;
- await spacesStore.fetchSpaces(
- ids.filter(id => !spacesStore.spacesMap.has(id)).map(id => id.split(':')[1]),
- offchainNetworkId
- );
+ await spacesStore.fetchSpaces(ids.filter(id => !spacesStore.spacesMap.has(id)));
spacesData.value = [
...spacesData.value,
@@ -93,12 +90,16 @@ export const useBookmarksStore = defineStore('bookmarks', () => {
if (alreadyStarred) {
starredSpacesIds.value = starredSpacesIds.value.filter((spaceId: string) => spaceId !== id);
- accountsBookmarkedSpacesIds.value[web3.value.account] = accountsBookmarkedSpacesIds.value[
- web3.value.account
- ].filter((spaceId: string) => spaceId !== id);
+
+ if (web3.value.account)
+ accountsBookmarkedSpacesIds.value[web3.value.account] = accountsBookmarkedSpacesIds.value[
+ web3.value.account
+ ].filter((spaceId: string) => spaceId !== id);
} else {
starredSpacesIds.value = [id, ...starredSpacesIds.value];
- accountsBookmarkedSpacesIds.value[web3.value.account] = [id, ...bookmarkedSpacesIds.value];
+
+ if (web3.value.account)
+ accountsBookmarkedSpacesIds.value[web3.value.account] = [id, ...bookmarkedSpacesIds.value];
}
mixpanel.track('Set space favorite', {
diff --git a/apps/ui/src/stores/spaces.ts b/apps/ui/src/stores/spaces.ts
index 0aad02bae..94420d050 100644
--- a/apps/ui/src/stores/spaces.ts
+++ b/apps/ui/src/stores/spaces.ts
@@ -5,8 +5,17 @@ import { NetworkID } from '@/types';
export const useSpacesStore = defineStore('spaces', () => {
const metaStore = useMetaStore();
- const { loading, loaded, networksMap, spaces, spacesMap, hasMoreSpaces, fetch, fetchMore } =
- useSpaces();
+ const {
+ loading,
+ loaded,
+ networksMap,
+ spaces,
+ spacesMap,
+ hasMoreSpaces,
+ fetch,
+ fetchMore,
+ getSpaces
+ } = useSpaces();
async function fetchSpace(spaceId: string, networkId: NetworkID) {
await metaStore.fetchBlock(networkId);
@@ -22,27 +31,19 @@ export const useSpacesStore = defineStore('spaces', () => {
};
}
- async function fetchSpaces(spaceIds: string[], networkId: NetworkID) {
- await metaStore.fetchBlock(networkId);
-
- const network = getNetwork(networkId);
-
- const spaces = await network.api.loadSpaces(
- {
- skip: 0,
- limit: 100
- },
- {
- id_in: spaceIds
- }
- );
+ async function fetchSpaces(spaceIds: string[]) {
+ const spaces = await getSpaces({
+ id_in: spaceIds
+ });
if (!spaces.length) return;
- networksMap.value[networkId].spaces = {
- ...networksMap.value[networkId].spaces,
- ...Object.fromEntries(spaces.map(space => [space.id, space]))
- };
+ for (const space of spaces) {
+ networksMap.value[space.network].spaces = {
+ ...networksMap.value[space.network].spaces,
+ [space.id]: space
+ };
+ }
}
return {
From 6c6c3c3f1746e814a3776cd151d5dc7983f324d6 Mon Sep 17 00:00:00 2001
From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com>
Date: Wed, 1 May 2024 01:46:36 +0400
Subject: [PATCH 84/90] fix: fix variable name
---
apps/ui/src/components/SpacesListItem.vue | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/apps/ui/src/components/SpacesListItem.vue b/apps/ui/src/components/SpacesListItem.vue
index d5b094b82..4bf54b1e3 100644
--- a/apps/ui/src/components/SpacesListItem.vue
+++ b/apps/ui/src/components/SpacesListItem.vue
@@ -6,12 +6,12 @@ const props = defineProps<{ space: Space }>();
const bookmarksStore = useBookmarksStore();
-const spaceIdComposite = `${props.space.network}:${props.space.id}`;
+const compositeSpaceId = `${props.space.network}:${props.space.id}`;
@@ -26,9 +26,9 @@ const spaceIdComposite = `${props.space.network}:${props.space.id}`;
From 108cbd8b12f3df0ba574785307b828fd0903f7db Mon Sep 17 00:00:00 2001
From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com>
Date: Wed, 1 May 2024 02:01:56 +0400
Subject: [PATCH 85/90] chore: code cleaning
---
apps/ui/src/stores/bookmarks.ts | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/apps/ui/src/stores/bookmarks.ts b/apps/ui/src/stores/bookmarks.ts
index f84ecfc08..94cb2eec5 100644
--- a/apps/ui/src/stores/bookmarks.ts
+++ b/apps/ui/src/stores/bookmarks.ts
@@ -10,8 +10,8 @@ function compositeSpaceId(space: Space) {
}
export const useBookmarksStore = defineStore('bookmarks', () => {
- const { web3, authInitiated } = useWeb3();
const spacesStore = useSpacesStore();
+ const { web3, authInitiated } = useWeb3();
const { mixpanel } = useMixpanel();
const spacesData = ref
([]);
@@ -155,7 +155,6 @@ export const useBookmarksStore = defineStore('bookmarks', () => {
return {
bookmarkedSpaces,
bookmarksLoaded,
- starredSpacesLoaded,
followedSpacesIds,
followedSpacesLoaded,
isStarred,
From bdad47357217524b5cf6221a91947631b512b87e Mon Sep 17 00:00:00 2001
From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com>
Date: Wed, 1 May 2024 23:19:47 +0400
Subject: [PATCH 86/90] fix(ux): add missing loading icon while loading follow
list in sidebar
---
apps/ui/src/stores/bookmarks.ts | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/apps/ui/src/stores/bookmarks.ts b/apps/ui/src/stores/bookmarks.ts
index 94cb2eec5..704c5a53f 100644
--- a/apps/ui/src/stores/bookmarks.ts
+++ b/apps/ui/src/stores/bookmarks.ts
@@ -83,6 +83,8 @@ export const useBookmarksStore = defineStore('bookmarks', () => {
syncBookmarkedSpacesIds(followedIds, 'followed');
fetchSpacesData(newIds);
+
+ console.log('fetch end');
}
function toggleSpaceStar(id: string) {
@@ -135,9 +137,14 @@ export const useBookmarksStore = defineStore('bookmarks', () => {
);
watch(
- [() => web3.value.account, () => web3.value.type, () => authInitiated.value],
- async ([web3, type, authInitiated]) => {
- if (!authInitiated) return;
+ [
+ () => web3.value.account,
+ () => web3.value.type,
+ () => web3.value.authLoading,
+ () => authInitiated.value
+ ],
+ async ([web3, type, authLoading, authInitiated]) => {
+ if (!authInitiated || authLoading) return;
if (!web3) {
followedSpacesIds.value = [];
@@ -147,6 +154,7 @@ export const useBookmarksStore = defineStore('bookmarks', () => {
if (type !== 'argentx') await loadFollowedSpaces();
+ console.log('ready');
followedSpacesLoaded.value = true;
},
{ immediate: true }
@@ -155,6 +163,7 @@ export const useBookmarksStore = defineStore('bookmarks', () => {
return {
bookmarkedSpaces,
bookmarksLoaded,
+ starredSpacesLoaded,
followedSpacesIds,
followedSpacesLoaded,
isStarred,
From b3841350840dc99d5752db5dc99d81f15b164442 Mon Sep 17 00:00:00 2001
From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com>
Date: Wed, 1 May 2024 23:20:44 +0400
Subject: [PATCH 87/90] chore: remove debug output
---
apps/ui/src/stores/bookmarks.ts | 3 ---
1 file changed, 3 deletions(-)
diff --git a/apps/ui/src/stores/bookmarks.ts b/apps/ui/src/stores/bookmarks.ts
index 704c5a53f..d86b5b1b1 100644
--- a/apps/ui/src/stores/bookmarks.ts
+++ b/apps/ui/src/stores/bookmarks.ts
@@ -83,8 +83,6 @@ export const useBookmarksStore = defineStore('bookmarks', () => {
syncBookmarkedSpacesIds(followedIds, 'followed');
fetchSpacesData(newIds);
-
- console.log('fetch end');
}
function toggleSpaceStar(id: string) {
@@ -154,7 +152,6 @@ export const useBookmarksStore = defineStore('bookmarks', () => {
if (type !== 'argentx') await loadFollowedSpaces();
- console.log('ready');
followedSpacesLoaded.value = true;
},
{ immediate: true }
From 474d1b72ce4ddcf2c9741e0e449a13f31d9e9c76 Mon Sep 17 00:00:00 2001
From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com>
Date: Mon, 6 May 2024 23:31:23 +0400
Subject: [PATCH 88/90] fix: finish merge conflict
---
apps/ui/src/stores/bookmarks.ts | 39 +++++++++++++++++++++++++++++++--
1 file changed, 37 insertions(+), 2 deletions(-)
diff --git a/apps/ui/src/stores/bookmarks.ts b/apps/ui/src/stores/bookmarks.ts
index d86b5b1b1..11313897d 100644
--- a/apps/ui/src/stores/bookmarks.ts
+++ b/apps/ui/src/stores/bookmarks.ts
@@ -1,7 +1,7 @@
import { defineStore } from 'pinia';
import { enabledNetworks, getNetwork, offchainNetworks } from '@/networks';
import pkg from '../../package.json';
-import { Space } from '@/types';
+import { NetworkID, Space } from '@/types';
const offchainNetworkId = offchainNetworks.filter(network => enabledNetworks.includes(network))[0];
@@ -11,12 +11,14 @@ function compositeSpaceId(space: Space) {
export const useBookmarksStore = defineStore('bookmarks', () => {
const spacesStore = useSpacesStore();
+ const actions = useActions();
const { web3, authInitiated } = useWeb3();
const { mixpanel } = useMixpanel();
const spacesData = ref([]);
const followedSpacesIds = ref([]);
const followedSpacesLoaded = ref(false);
+ const followSpaceLoading = ref(false);
const starredSpacesIds = useStorage(`${pkg.name}.spaces-starred`, [] as string[]);
const starredSpacesLoaded = ref(false);
// Combined list of starred and followed spaces by account, to keep sort order
@@ -108,6 +110,37 @@ export const useBookmarksStore = defineStore('bookmarks', () => {
});
}
+ async function toggleSpaceFollow(id: string) {
+ const alreadyFollowed = followedSpacesIds.value.includes(id);
+ const [spaceNetwork, spaceId] = id.split(':');
+ followSpaceLoading.value = true;
+
+ try {
+ if (alreadyFollowed) {
+ const result = await actions.unfollowSpace(spaceNetwork as NetworkID, spaceId);
+ if (!result) return;
+
+ followedSpacesIds.value = followedSpacesIds.value.filter(
+ (spaceId: string) => spaceId !== id
+ );
+ accountsBookmarkedSpacesIds.value[web3.value.account] = accountsBookmarkedSpacesIds.value[
+ web3.value.account
+ ].filter((spaceId: string) => spaceId !== id);
+ } else {
+ const result = await actions.followSpace(spaceNetwork as NetworkID, spaceId);
+ if (!result) return;
+
+ fetchSpacesData([id]);
+
+ followedSpacesIds.value = [id, ...followedSpacesIds.value];
+ accountsBookmarkedSpacesIds.value[web3.value.account] = [id, ...bookmarkedSpacesIds.value];
+ }
+ } catch (e) {
+ } finally {
+ followSpaceLoading.value = false;
+ }
+ }
+
function isStarred(spaceId: string) {
return starredSpacesIds.value.includes(spaceId);
}
@@ -163,8 +196,10 @@ export const useBookmarksStore = defineStore('bookmarks', () => {
starredSpacesLoaded,
followedSpacesIds,
followedSpacesLoaded,
+ followSpaceLoading,
isStarred,
isFollowed,
- toggleSpaceStar
+ toggleSpaceStar,
+ toggleSpaceFollow
};
});
From c1bc4d3f57922940cc66c3a2479f5e4359f65a2c Mon Sep 17 00:00:00 2001
From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com>
Date: Tue, 7 May 2024 00:26:30 +0400
Subject: [PATCH 89/90] feat: enable vote and proposal creation/update with
session key
---
apps/ui/src/composables/useActions.ts | 10 ++++----
apps/ui/src/networks/evm/actions.ts | 3 +--
apps/ui/src/networks/offchain/actions.ts | 24 +++++++++++++-------
apps/ui/src/networks/types.ts | 6 ++---
packages/sx.js/src/clients/offchain/types.ts | 3 +++
5 files changed, 29 insertions(+), 17 deletions(-)
diff --git a/apps/ui/src/composables/useActions.ts b/apps/ui/src/composables/useActions.ts
index 80779ab01..4f93e8fd5 100644
--- a/apps/ui/src/composables/useActions.ts
+++ b/apps/ui/src/composables/useActions.ts
@@ -1,5 +1,5 @@
import { getInstance } from '@snapshot-labs/lock/plugins/vue3';
-import { getNetwork, getReadWriteNetwork } from '@/networks';
+import { getNetwork, getReadWriteNetwork, offchainNetworks } from '@/networks';
import { registerTransaction } from '@/helpers/mana';
import { convertToMetaTransactions } from '@/helpers/transactions';
import type {
@@ -107,6 +107,8 @@ export function useActions() {
}
async function aliasableSigner(networkId: NetworkID): Promise {
+ if (!offchainNetworks.includes(networkId)) return auth.web3;
+
const network = getNetwork(networkId);
if (!(await alias.isValid())) {
@@ -209,7 +211,7 @@ export function useActions() {
await wrapPromise(
proposal.network,
network.actions.vote(
- auth.web3,
+ await aliasableSigner(proposal.network),
web3.value.type as Connector,
web3.value.account,
proposal,
@@ -263,7 +265,7 @@ export function useActions() {
await wrapPromise(
space.network,
network.actions.propose(
- auth.web3,
+ await aliasableSigner(space.network),
web3.value.type as Connector,
web3.value.account,
space,
@@ -318,7 +320,7 @@ export function useActions() {
await wrapPromise(
space.network,
network.actions.updateProposal(
- auth.web3,
+ await aliasableSigner(space.network),
web3.value.type as Connector,
web3.value.account,
space,
diff --git a/apps/ui/src/networks/evm/actions.ts b/apps/ui/src/networks/evm/actions.ts
index cfb3a16d8..3bd595fa3 100644
--- a/apps/ui/src/networks/evm/actions.ts
+++ b/apps/ui/src/networks/evm/actions.ts
@@ -608,7 +608,6 @@ export function createActions(
);
},
followSpace: () => {},
- unfollowSpace: () => {},
- setAlias: () => {}
+ unfollowSpace: () => {}
};
}
diff --git a/apps/ui/src/networks/offchain/actions.ts b/apps/ui/src/networks/offchain/actions.ts
index 3f569a07a..f68ff25a1 100644
--- a/apps/ui/src/networks/offchain/actions.ts
+++ b/apps/ui/src/networks/offchain/actions.ts
@@ -41,7 +41,7 @@ export function createActions(
return {
async propose(
- web3: Web3Provider,
+ web3: Web3Provider | Wallet,
connectorType: Connector,
account: string,
space: Space,
@@ -78,13 +78,17 @@ export function createActions(
snapshot: (await provider.getBlockNumber()) - EDITOR_SNAPSHOT_OFFSET,
plugins: '{}',
app: EDITOR_APP_NAME,
- timestamp: currentTime
+ timestamp: currentTime,
+ from: getAddress(account)
};
- return client.propose({ signer: web3.getSigner(), data });
+ return client.propose({
+ signer: web3 instanceof Web3Provider ? web3.getSigner() : web3,
+ data
+ });
},
async updateProposal(
- web3: Web3Provider,
+ web3: Web3Provider | Wallet,
connectorType: Connector,
account: string,
space: Space,
@@ -114,10 +118,14 @@ export function createActions(
type: payload.type,
discussion: payload.discussion,
choices: payload.choices,
- plugins: '{}'
+ plugins: '{}',
+ from: getAddress(account)
};
- return client.updateProposal({ signer: web3.getSigner(), data });
+ return client.updateProposal({
+ signer: web3 instanceof Web3Provider ? web3.getSigner() : web3,
+ data
+ });
},
cancelProposal(web3: Web3Provider, proposal: Proposal) {
return client.cancel({
@@ -126,7 +134,7 @@ export function createActions(
});
},
vote(
- web3: Web3Provider,
+ web3: Web3Provider | Wallet,
connectorType: Connector,
account: string,
proposal: Proposal,
@@ -144,7 +152,7 @@ export function createActions(
};
return client.vote({
- signer: web3.getSigner(),
+ signer: web3 instanceof Web3Provider ? web3.getSigner() : web3,
data
});
},
diff --git a/apps/ui/src/networks/types.ts b/apps/ui/src/networks/types.ts
index 3a6616828..54b300b77 100644
--- a/apps/ui/src/networks/types.ts
+++ b/apps/ui/src/networks/types.ts
@@ -97,7 +97,7 @@ export type ReadOnlyNetworkActions = {
snapshotInfo: SnapshotInfo
): Promise;
propose(
- web3: Web3Provider,
+ web3: Web3Provider | Wallet,
connectorType: Connector,
account: string,
space: Space,
@@ -106,7 +106,7 @@ export type ReadOnlyNetworkActions = {
transactions: MetaTransaction[]
): Promise;
updateProposal(
- web3: Web3Provider,
+ web3: Web3Provider | Wallet,
connectorType: Connector,
account: string,
space: Space,
@@ -117,7 +117,7 @@ export type ReadOnlyNetworkActions = {
): Promise;
cancelProposal(web3: Web3Provider, proposal: Proposal);
vote(
- web3: Web3Provider,
+ web3: Web3Provider | Wallet,
connectorType: Connector,
account: string,
proposal: Proposal,
diff --git a/packages/sx.js/src/clients/offchain/types.ts b/packages/sx.js/src/clients/offchain/types.ts
index d54995aea..f0824ed1b 100644
--- a/packages/sx.js/src/clients/offchain/types.ts
+++ b/packages/sx.js/src/clients/offchain/types.ts
@@ -132,6 +132,7 @@ export type Vote = {
type: string;
privacy?: Privacy;
timestamp?: number;
+ from?: string;
};
export type Propose = {
@@ -147,6 +148,7 @@ export type Propose = {
plugins: string;
app: string;
timestamp?: number;
+ from?: string;
};
export type UpdateProposal = {
@@ -158,6 +160,7 @@ export type UpdateProposal = {
discussion: string;
choices: string[];
plugins: string;
+ from?: string;
};
export type CancelProposal = {
From 5f65c1afc92729f380df2de6614c4d0ea07c6769 Mon Sep 17 00:00:00 2001
From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com>
Date: Tue, 7 May 2024 00:35:19 +0400
Subject: [PATCH 90/90] fix: fix missing actions
---
apps/ui/src/networks/evm/actions.ts | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/apps/ui/src/networks/evm/actions.ts b/apps/ui/src/networks/evm/actions.ts
index 3bd595fa3..fe2f8ccbb 100644
--- a/apps/ui/src/networks/evm/actions.ts
+++ b/apps/ui/src/networks/evm/actions.ts
@@ -608,6 +608,7 @@ export function createActions(
);
},
followSpace: () => {},
- unfollowSpace: () => {}
+ unfollowSpace: () => {},
+ setAlias() {}
};
}