Skip to content

Commit 1b451b5

Browse files
committed
fix: load filtered transactions correctly
1 parent c1c0491 commit 1b451b5

File tree

3 files changed

+45
-37
lines changed

3 files changed

+45
-37
lines changed

src/popup/components/TransactionList.vue

+30-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
PropType,
3737
computed,
3838
defineComponent,
39+
watch,
3940
} from 'vue';
4041
import { useI18n } from 'vue-i18n';
4142
import { useStore } from 'vuex';
@@ -54,6 +55,7 @@ import {
5455
useAccounts,
5556
useAeSdk,
5657
useTransactionAndTokenFilter,
58+
useViewport,
5759
} from '@/composables';
5860
import { AE_TRANSACTION_OWNERSHIP_STATUS } from '@/protocols/aeternity/config';
5961
import {
@@ -83,11 +85,12 @@ export default defineComponent({
8385
loading: Boolean,
8486
},
8587
emits: ['loadMore'],
86-
setup(props) {
88+
setup(props, { emit }) {
8789
const store = useStore();
8890
const { t } = useI18n();
8991
const { accounts, activeAccount } = useAccounts({ store });
9092
const { dexContracts } = useAeSdk({ store });
93+
const { viewportElement } = useViewport();
9194
9295
const {
9396
searchPhrase,
@@ -144,6 +147,32 @@ export default defineComponent({
144147
);
145148
}
146149
150+
function checkLoadMore() {
151+
if (!viewportElement.value) {
152+
return;
153+
}
154+
155+
const {
156+
scrollHeight,
157+
scrollTop,
158+
clientHeight,
159+
} = viewportElement.value!;
160+
161+
if (scrollHeight - scrollTop <= clientHeight + 100) {
162+
emit('loadMore');
163+
}
164+
}
165+
166+
watch(displayMode, () => {
167+
checkLoadMore();
168+
});
169+
170+
watch(() => props.loading, (val) => {
171+
if (!val) {
172+
checkLoadMore();
173+
}
174+
});
175+
147176
const filteredTransactions = computed(
148177
() => pipe([
149178
filterTransactionsByDisplayMode,

src/popup/pages/FungibleTokens/TokenTransactions.vue

+13-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
</template>
99

1010
<script lang="ts">
11-
import { computed, defineComponent, ref } from 'vue';
11+
import {
12+
computed, defineComponent, ref, onMounted,
13+
} from 'vue';
1214
import { useStore } from 'vuex';
1315
import type { ICommonTransaction, ITokenList, ITx } from '@/types';
1416
import { TXS_PER_PAGE } from '@/constants';
@@ -36,6 +38,7 @@ export default defineComponent({
3638
const {
3739
fetchTransactions,
3840
getAccountAllTransactions,
41+
getAccountTransactionsState,
3942
} = useTransactionList({ store });
4043
4144
const loading = ref(false);
@@ -48,6 +51,10 @@ export default defineComponent({
4851
: activeAccount.value.address,
4952
);
5053
54+
const canLoadMore = computed(() => (
55+
!!getAccountTransactionsState(currentAddress.value!).nextPageUrl
56+
));
57+
5158
const loadedTransactionList = computed(
5259
(): ICommonTransaction[] => getAccountAllTransactions(currentAddress.value!),
5360
);
@@ -89,11 +96,15 @@ export default defineComponent({
8996
}
9097
9198
async function loadMore() {
92-
if (!loading.value) {
99+
if (!loading.value && canLoadMore.value) {
93100
await fetchTransactionList();
94101
}
95102
}
96103
104+
onMounted(() => {
105+
fetchTransactionList();
106+
});
107+
97108
return {
98109
loading,
99110
filteredTransactions,

src/protocols/aeternity/views/AccountDetailsTransactions.vue

+2-34
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
onMounted,
2222
onUnmounted,
2323
ref,
24-
watch,
2524
} from 'vue';
2625
import { useStore } from 'vuex';
2726
@@ -30,10 +29,8 @@ import { TXS_PER_PAGE } from '@/constants';
3029
import {
3130
useAccounts,
3231
useConnection,
33-
useTransactionAndTokenFilter,
3432
useTransactionList,
3533
useUi,
36-
useViewport,
3734
} from '@/composables';
3835
3936
import MessageOffline from '@/popup/components/MessageOffline.vue';
@@ -58,7 +55,6 @@ export default defineComponent({
5855
5956
const { isOnline } = useConnection();
6057
const { isAppActive } = useUi();
61-
const { viewportElement } = useViewport();
6258
const { activeAccount } = useAccounts({ store });
6359
6460
const {
@@ -67,8 +63,6 @@ export default defineComponent({
6763
fetchTransactions,
6864
} = useTransactionList({ store });
6965
70-
const { displayMode } = useTransactionAndTokenFilter();
71-
7266
const loading = ref(false);
7367
const isDestroyed = ref(false);
7468
@@ -94,39 +88,13 @@ export default defineComponent({
9488
}
9589
9690
async function loadMore() {
97-
if (!loading.value) {
91+
if (!loading.value && !isDestroyed.value && canLoadMore.value) {
9892
await fetchTransactionList();
9993
}
10094
}
10195
102-
async function checkLoadMore() {
103-
if (viewportElement.value && (isDestroyed.value || !canLoadMore.value)) {
104-
return;
105-
}
106-
107-
const {
108-
scrollHeight,
109-
scrollTop,
110-
clientHeight,
111-
} = viewportElement.value!;
112-
113-
if (scrollHeight - scrollTop <= clientHeight + 100) {
114-
await loadMore();
115-
}
116-
}
117-
118-
watch(displayMode, () => {
119-
checkLoadMore();
120-
});
121-
122-
watch(loading, async (val) => {
123-
if (!val) {
124-
await checkLoadMore();
125-
}
126-
});
127-
12896
onMounted(() => {
129-
loadMore();
97+
fetchTransactionList();
13098
polling = setInterval(() => {
13199
if (isAppActive.value) {
132100
fetchTransactionList(true);

0 commit comments

Comments
 (0)