Skip to content

Commit

Permalink
add transaction count
Browse files Browse the repository at this point in the history
  • Loading branch information
zlayine committed Oct 1, 2024
1 parent 38cb81f commit 6a14c06
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion resources/js/api/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class TransactionApi {
results: getTransactionsData.results,
accounts: getTransactionsData.accounts,
after: getTransactionsData.after,
first: 20,
first: getTransactionsData.first ?? 20,
},
};

Expand Down
23 changes: 21 additions & 2 deletions resources/js/components/SideNavbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@
:to="item.to"
class="text-light-content dark:text-dark-content hover:bg-light-surface-background hover:dark:bg-dark-surface-background hover:text-light-content-selected hover:dark:text-dark-content-selected group flex items-center px-4 py-3 font-medium transition-all"
>
<span class="flex-1">{{ item.name }}</span>
<span class="">{{ item.name }}</span>
<span
v-if="item.count && transactionsCount > 0"
class="text-xs font-normal ml-4 rounded-full text-light-content-brand dark:text-dark-content-brand bg-light-surface-brand-alpha p-1 w-6 h-6 flex items-center justify-center animate-fade-in"
>
{{ transactionsCount }}
</span>
</RouterLink>
</nav>
</div>
Expand Down Expand Up @@ -92,15 +98,24 @@
</template>

<script setup lang="ts">
import { computed } from 'vue';
import { computed, onMounted, ref } from 'vue';
import { useAppStore } from '~/store';
import EnjinLogo from '~/components/EnjinLogo.vue';
import CanaryEnjinLogo from '~/components/CanaryEnjinLogo.vue';
import { TransactionApi } from '~/api/transaction';
import { DTOTransactionFactory as DTOFactory } from '~/factory/transaction';
const navigations = computed(() => useAppStore().navigations);
const canaryHost = computed(() => useAppStore().config.network === 'canary');
const transactionsCount = ref(0);
const loadTransactions = async () => {
const res = await TransactionApi.getTransactions({ first: 500 });
transactionsCount.value = DTOFactory.getPendingTransactionsCount(res.data);
};
const pageTitle = () => {
if (window.bootstrap?.name) {
return window.bootstrap.name;
Expand All @@ -112,6 +127,10 @@ const pageTitle = () => {
return 'Platform';
}
};
onMounted(() => {
loadTransactions();
});
</script>

<style lang="scss" scoped>
Expand Down
7 changes: 7 additions & 0 deletions resources/js/factory/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,11 @@ export class DTOTransactionFactory {

return DTOTransactionFactory.buildTransaction(transaction);
}

public static getPendingTransactionsCount(transactionsData: any): number {
const transactions = transactionsData.GetTransactions;
const total = transactions.edges.filter((transaction) => transaction.node.state === 'PENDING').length;

return total;
}
}
2 changes: 1 addition & 1 deletion resources/js/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const useAppStore = defineStore('app', {
navigations: [
{ name: 'Collections', to: { name: 'platform.collections' }, pos: 1 },
{ name: 'Tokens', to: { name: 'platform.tokens' }, pos: 2 },
{ name: 'Transactions', to: { name: 'platform.transactions' }, pos: 6 },
{ name: 'Transactions', to: { name: 'platform.transactions' }, count: true, pos: 6 },
{ name: 'Wallets', to: { name: 'platform.wallets' }, pos: 7 },
],
collections: [],
Expand Down

0 comments on commit 6a14c06

Please sign in to comment.