Skip to content

Commit 8a3ecef

Browse files
committed
fix: load notifications and transactions in chunks
1 parent c391825 commit 8a3ecef

File tree

6 files changed

+36
-33
lines changed

6 files changed

+36
-33
lines changed

src/composables/viewport.ts

+7-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { debounce } from 'lodash-es';
2-
import { onBeforeUnmount, onMounted, ref } from 'vue';
3-
import { MOBILE_WIDTH } from '@/constants';
2+
import { onBeforeUnmount, ref } from 'vue';
43

54
export interface IScrollCallbackParams {
65
isOutsideOfViewport: boolean
@@ -11,18 +10,9 @@ export type OnViewportScrollCallback = (p: IScrollCallbackParams) => any;
1110
const viewportElement = ref<Element | undefined>();
1211

1312
export const useViewport = () => {
14-
function checkIsDesktop(): boolean {
15-
return !!(
16-
document.documentElement.clientWidth > MOBILE_WIDTH
17-
|| process.env.IS_EXTENSION
18-
);
19-
}
20-
2113
const viewportScroll = debounce((callback: OnViewportScrollCallback) => {
22-
const element = checkIsDesktop() ? viewportElement.value : document.documentElement;
23-
24-
if (element) {
25-
const { scrollHeight, scrollTop, clientHeight } = element;
14+
if (viewportElement.value) {
15+
const { scrollHeight, scrollTop, clientHeight } = viewportElement.value;
2616
const isOutsideOfViewport = scrollHeight - scrollTop <= clientHeight + 100;
2717

2818
callback({ isOutsideOfViewport });
@@ -34,12 +24,10 @@ export const useViewport = () => {
3424
}
3525

3626
function onViewportScroll(onScrollMethod: OnViewportScrollCallback) {
37-
onMounted(() => {
38-
if (viewportElement.value) {
39-
viewportElement.value.addEventListener('scroll', () => viewportScroll(onScrollMethod));
40-
}
41-
window.addEventListener('scroll', () => viewportScroll(onScrollMethod));
42-
});
27+
if (viewportElement.value) {
28+
viewportElement.value.addEventListener('scroll', () => viewportScroll(onScrollMethod));
29+
}
30+
window.addEventListener('scroll', () => viewportScroll(onScrollMethod));
4331
onBeforeUnmount(() => {
4432
if (viewportElement.value) {
4533
viewportElement.value.removeEventListener('scroll', () => viewportScroll(onScrollMethod));

src/popup/App.vue

-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
</button>
2020
<div
2121
v-show="!qrScannerOpen"
22-
ref="innerElement"
2322
class="app-inner"
2423
:class="{ 'styled-scrollbar': showScrollbar }"
2524
>
@@ -92,7 +91,6 @@ import {
9291
useModals,
9392
useNotifications,
9493
useUi,
95-
useViewport,
9694
} from '@/composables';
9795
import { useAeTippingBackend } from '@/protocols/aeternity/composables';
9896
import { useTransferSendHandler } from '@/composables/transferSendHandler';
@@ -129,7 +127,6 @@ export default defineComponent({
129127
const { isLoggedIn } = useAccounts({ store });
130128
const { addWalletNotification } = useNotifications({ store });
131129
const { loadCoinsData } = useCurrencies({ store, withoutPolling: true });
132-
const { initViewport } = useViewport();
133130
const { restore: restoreTransferSendForm } = useTransferSendHandler();
134131
135132
const innerElement = ref<HTMLDivElement>();
@@ -223,7 +220,6 @@ export default defineComponent({
223220
onMounted(async () => {
224221
setDocumentHeight();
225222
checkExtensionUpdates();
226-
initViewport(innerElement.value);
227223
228224
// Hide splash screen programmatically when app is ready
229225
// to avoid white screen on app start

src/popup/components/InfiniteScroll.vue

+13-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</template>
66

77
<script lang="ts">
8-
import { defineComponent } from 'vue';
8+
import { defineComponent, watch } from 'vue';
99
import { useViewport } from '../../composables/viewport';
1010
1111
export default defineComponent({
@@ -15,13 +15,19 @@ export default defineComponent({
1515
},
1616
emits: ['loadMore'],
1717
setup(props, { emit }) {
18-
const { onViewportScroll } = useViewport();
18+
const { viewportElement, onViewportScroll } = useViewport();
1919
20-
onViewportScroll(({ isOutsideOfViewport }) => {
21-
if (props.isMoreData && isOutsideOfViewport) {
22-
emit('loadMore');
23-
}
24-
});
20+
watch(
21+
viewportElement,
22+
() => {
23+
onViewportScroll(({ isOutsideOfViewport }) => {
24+
if (props.isMoreData && isOutsideOfViewport) {
25+
emit('loadMore');
26+
}
27+
});
28+
},
29+
{ immediate: true },
30+
);
2531
},
2632
});
2733
</script>

src/popup/components/TransactionList.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
/>
1919
</InfiniteScroll>
2020
<AnimatedSpinner
21-
v-if="loading"
21+
v-show="loading"
2222
class="spinner"
2323
data-cy="loader"
2424
/>
2525
<div
26-
v-else-if="!filteredTransactions.length"
26+
v-if="!loading && !filteredTransactions.length"
2727
class="message"
2828
>
2929
<p v-text="$t('pages.recentTransactions.noTransactionsFound')" />

src/popup/pages/Notifications.vue

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<template>
22
<IonPage>
33
<IonContent class="ion-padding ion-content-bg">
4-
<div class="notifications">
4+
<div
5+
ref="innerElement"
6+
class="notifications"
7+
>
58
<InfiniteScroll
69
v-if="notificationsToShow.length"
710
:is-more-data="canLoadMore"
@@ -31,10 +34,12 @@ import {
3134
onBeforeUnmount,
3235
onMounted,
3336
nextTick,
37+
ref,
3438
} from 'vue';
3539
import { useStore } from 'vuex';
3640
import { IS_EXTENSION } from '@/constants';
3741
42+
import { useViewport } from '@/composables';
3843
import NotificationItem from '../components/NotificationItem.vue';
3944
import InfiniteScroll from '../components/InfiniteScroll.vue';
4045
import { useNotifications } from '../../composables/notifications';
@@ -49,6 +54,9 @@ export default defineComponent({
4954
},
5055
setup() {
5156
const store = useStore();
57+
const { initViewport } = useViewport();
58+
59+
const innerElement = ref<HTMLElement>();
5260
5361
const {
5462
notificationsToShow,
@@ -58,6 +66,7 @@ export default defineComponent({
5866
} = useNotifications({ store, requirePolling: true });
5967
6068
onMounted(async () => {
69+
initViewport(innerElement.value?.parentElement!);
6170
loadMoreNotifications();
6271
if (IS_EXTENSION) {
6372
await nextTick();
@@ -72,6 +81,7 @@ export default defineComponent({
7281
});
7382
7483
return {
84+
innerElement,
7585
notificationsToShow,
7686
canLoadMore,
7787
loadMoreNotifications,

src/protocols/aeternity/views/AccountDetailsTransactions.vue

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
useTransactionList,
4040
useUi,
4141
useScrollConfig,
42+
useViewport,
4243
} from '@/composables';
4344
4445
import MessageOffline from '@/popup/components/MessageOffline.vue';
@@ -67,6 +68,7 @@ export default defineComponent({
6768
const { isAppActive } = useUi();
6869
const { activeAccount } = useAccounts({ store });
6970
const { setScrollConf } = useScrollConfig();
71+
const { initViewport } = useViewport();
7072
7173
const {
7274
getAccountAllTransactions,
@@ -124,6 +126,7 @@ export default defineComponent({
124126
);
125127
126128
onMounted(() => {
129+
initViewport(appInnerElem.value!);
127130
if (innerScrollElem.value && appInnerElem.value) {
128131
appInnerElem.value.addEventListener('scroll', throttledScroll());
129132
}

0 commit comments

Comments
 (0)