Skip to content

Commit

Permalink
Merge pull request #39 from lum-network/hotfix/lum-772
Browse files Browse the repository at this point in the history
[LUM-772] WebApp -> Fix "Past transactions" section
  • Loading branch information
greedyboi authored Sep 20, 2023
2 parents 214bbbd + b8dd19d commit 95efd8a
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 34 deletions.
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 @@ -358,6 +358,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: PrizeModel[];
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 @@ -426,7 +418,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 @@ -50,7 +51,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 @@ -145,7 +152,7 @@ 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) * 5 + smallTableVisibleItem === transactions.length - 1}
disabled={((pagination?.page || 1) - 1) * 5 + smallTableVisibleItem === transactions.length - 1 && !pagination?.hasNextPage}
onClick={() => {
if (smallTableVisibleItem === 4) {
if (pagination) {
Expand All @@ -165,11 +172,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 @@ -25,7 +25,6 @@ interface SetWalletDataPayload {
result: TransactionModel[];
currentPage: number;
pagesTotal: number;
pagesLoaded: number;
};
deposits?: AggregatedDepositModel[];
prizes?: PrizeModel[];
Expand All @@ -34,8 +33,6 @@ interface SetWalletDataPayload {

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

Expand Down Expand Up @@ -103,7 +100,6 @@ export const wallet = createModel<RootModel>()({
result: [],
currentPage: 1,
pagesTotal: 1,
pagesLoaded: 1,
},
deposits: [],
prizes: [],
Expand Down Expand Up @@ -430,8 +426,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 @@ -441,9 +436,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

0 comments on commit 95efd8a

Please sign in to comment.