Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LUM-772] WebApp -> Fix "Past transactions" section #39

Merged
merged 4 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/constant/navigation.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
const isTestEnv = (): boolean => {
return window.location.href.includes('localhost') || window.location.href.includes('testnet');
};

export const LANDING = '/';
export const HOME = '/dashboard';
export const POOLS = '/pools';
export const POOL_DETAILS = '/pools/details';
export const MY_SAVINGS = '/my-savings';
export const WINNERS = '/winners';
export const LUM_EXPLORER = 'https://explorer.lum.network';
export const LUM_EXPLORER = `https://explorer.${isTestEnv() ? 'testnet.' : ''}lum.network`;
export const DOCUMENTATION = 'https://docs.cosmosmillions.com';
export const FAQ = '#faq';
export const DISCORD = 'https://discord.com/invite/PWHUMdwQ5r';
Expand Down
4 changes: 4 additions & 0 deletions src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ export default {
claimPrize: 'Claim Prize',
deposit: 'Deposit',
},
transactionTooltips: {
claim: '{{ count }} prizes claimed',
withdraw: '{{ count }} deposits withdrawn',
},
txListHeaders: ['Type', 'Hash', 'Amount'],
deposits: 'Pool Deposits',
leavePoolCta: 'Leave Pool',
Expand Down
1 change: 0 additions & 1 deletion src/models/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export interface LumWalletModel {
result: TransactionModel[];
currentPage: number;
pagesTotal: number;
pagesLoaded: number;
};
deposits: AggregatedDepositModel[];
prizes: Prize[];
Expand Down
10 changes: 1 addition & 9 deletions src/pages/MySavings/MySavings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,6 @@ const MySavings = () => {
}
}, [leaderboardPage]);

useEffect(() => {
const page = activities?.currentPage;

if (lumWallet && page && page > 1 && page > activities.pagesLoaded) {
dispatch.wallet.getActivities({ address: lumWallet.address, page });
}
}, [activities?.currentPage]);

useEffect(() => {
if (isReloadingInfos) {
dispatch.wallet.setActivitiesPage(1);
Expand Down Expand Up @@ -395,7 +387,7 @@ const MySavings = () => {
<h2 className='mt-5'>{I18n.t('mySavings.activities')}</h2>
<Card withoutPadding className='py-1 py-sm-2 py-xl-4 px-3 px-sm-4 px-xl-5 glow-bg'>
<TransactionsTable
transactions={activities.result.slice((activities.currentPage - 1) * 5, (activities.currentPage - 1) * 5 + 5)}
transactions={activities.result}
pagination={
activities.pagesTotal > 1
? {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState } from 'react';
import { useSelector } from 'react-redux';
import numeral from 'numeral';
import { LumMessages } from '@lum-network/sdk-javascript';

import { Pagination, SmallerDecimal, Table, Tooltip } from 'components';
import { Breakpoints, NavigationConstants } from 'constant';
Expand Down Expand Up @@ -55,7 +56,13 @@ const TransactionsTable = ({
)}
<h4 className='mb-0 align-middle text-nowrap'>{type}</h4>
{transaction.messages.length > 1 ? (
<span data-tooltip-id={`claim-tooltip-${transaction.hash}`} data-tooltip-html={`${transaction.messages.length} prizes claimed`}>
<span
data-tooltip-id={`claim-tooltip-${transaction.hash}`}
data-tooltip-html={I18n.t(
transaction.messages[0] === LumMessages.MsgClaimPrizeUrl ? 'mySavings.transactionTooltips.claim' : 'mySavings.transactionTooltips.withdraw',
{ count: transaction.messages.length },
)}
>
<div className='msg-count-badge d-flex align-items-center justify-content-center ms-2 rounded-pill px-2 py-1'>+{transaction.messages.length - 1}</div>
<Tooltip id={`claim-tooltip-${transaction.hash}`} />
</span>
Expand Down Expand Up @@ -128,18 +135,16 @@ const TransactionsTable = ({

return (
<div className='transactions-table py-3'>
{renderItem(transactions[((pagination?.page || 1) - 1) * 30 + smallTableVisibleItem], ((pagination?.page || 1) - 1) * 30 + smallTableVisibleItem)}
{renderItem(transactions[((pagination?.page || 1) - 1) * 5 + smallTableVisibleItem], ((pagination?.page || 1) - 1) * 5 + smallTableVisibleItem)}
<div className='d-flex flex-row mt-4'>
<button
type='button'
className='d-flex align-items-center justify-content-center py-1 w-100 selectable-btn'
disabled={smallTableVisibleItem === 0 && !pagination?.hasPreviousPage}
onClick={() => {
if (smallTableVisibleItem === 0) {
if (pagination) {
onPageChange(pagination.page - 1);
}
setSmallTableVisibleItem(29);
if (smallTableVisibleItem === 0 && pagination) {
onPageChange(pagination.page - 1);
setSmallTableVisibleItem(4);
} else {
setSmallTableVisibleItem(smallTableVisibleItem - 1);
}
Expand All @@ -150,12 +155,10 @@ const TransactionsTable = ({
<button
type='button'
className='d-flex align-items-center justify-content-center py-1 w-100 selectable-btn ms-4'
disabled={((pagination?.page || 1) - 1) * 30 + smallTableVisibleItem === transactions.length - 1}
disabled={((pagination?.page || 1) - 1) * 5 + smallTableVisibleItem === transactions.length - 1 && !pagination?.hasNextPage}
onClick={() => {
if (smallTableVisibleItem === 29) {
if (pagination) {
onPageChange(pagination.page + 1);
}
if (smallTableVisibleItem === 4 && pagination) {
onPageChange(pagination.page + 1);
setSmallTableVisibleItem(0);
} else {
setSmallTableVisibleItem(smallTableVisibleItem + 1);
Expand All @@ -170,11 +173,13 @@ const TransactionsTable = ({
);
};

const normalTableTxs = pagination ? transactions.slice((pagination.page - 1) * 5, (pagination.page - 1) * 5 + 5) : transactions;

return winSizes.width < Breakpoints.MD || (winSizes.width > Breakpoints.LG && winSizes.width < Breakpoints.XL) ? (
renderSmallTable(transactions)
) : (
<Table className='transactions-table' pagination={pagination} onPageChange={onPageChange}>
{transactions.map((transaction, index) => renderRow(transaction, index))}
{normalTableTxs.map((transaction, index) => renderRow(transaction, index))}
</Table>
);
};
Expand Down
10 changes: 2 additions & 8 deletions src/redux/models/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,13 @@ interface SetWalletDataPayload {
result: TransactionModel[];
currentPage: number;
pagesTotal: number;
pagesLoaded: number;
};
deposits?: AggregatedDepositModel[];
prizes?: Prize[];
}

interface GetActivitiesPayload {
address: string;
page?: number;
prevTxs?: TransactionModel[];
reset?: boolean;
}

Expand Down Expand Up @@ -94,7 +91,6 @@ export const wallet = createModel<RootModel>()({
result: [],
currentPage: 1,
pagesTotal: 1,
pagesLoaded: 1,
},
deposits: [],
prizes: [],
Expand Down Expand Up @@ -413,8 +409,7 @@ export const wallet = createModel<RootModel>()({
},
async getActivities(payload: GetActivitiesPayload, state) {
try {
const res = await LumClient.getWalletActivities(payload.address, payload.page);
const currPagesLoaded = state.wallet.lumWallet?.activities.pagesLoaded || 1;
const res = await LumClient.getWalletActivities(payload.address);

if (res) {
const txs = [...(payload.reset ? [] : state.wallet.lumWallet?.activities.result || []), ...res.activities];
Expand All @@ -424,9 +419,8 @@ export const wallet = createModel<RootModel>()({
dispatch.wallet.setLumWalletData({
activities: {
result: txs,
currentPage: res.currentPage,
pagesTotal,
pagesLoaded: payload.reset ? 1 : res.currentPage > currPagesLoaded ? res.currentPage : currPagesLoaded,
currentPage: 1,
},
});
}
Expand Down
31 changes: 19 additions & 12 deletions src/utils/lumClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,30 +198,37 @@ class LumClient {
return { balances };
};

getWalletActivities = async (address: string, page = 1) => {
getWalletActivities = async (address: string) => {
if (this.client === null) {
return null;
}

const LIMIT = 5;
const txs = [];
let totalCount = 0;

let totalCount: number | null = null;
const queries = [
// Query deposits
`deposit.depositor='${address}' AND deposit.winner='${address}'`,

const query = LumUtils.searchTxByTags([
{ key: 'message.module', value: 'millions' },
{ key: 'transfer.sender', value: address },
]);
// Query claim prize
`prize_claim.winner='${address}'`,

const res = await this.client.tmClient.txSearch({ query, page, per_page: LIMIT, order_by: 'desc' });
// Query leave pool
`withdraw_deposit.depositor='${address}' AND withdraw_deposit.recipient='${address}'`,
];

if (page === 1) {
totalCount = res.totalCount;
const res = await Promise.allSettled(queries.map((query) => this.client?.tmClient.txSearchAll({ query })));

for (const r of res) {
if (r.status === 'fulfilled' && r.value !== undefined) {
txs.push(...r.value.txs);
totalCount += r.value.totalCount;
}
}

return {
activities: await formatTxs(res.txs, true),
activities: await formatTxs(txs, true),
totalCount,
currentPage: page,
};
};

Expand Down
Loading