Skip to content

Commit

Permalink
fixes history
Browse files Browse the repository at this point in the history
  • Loading branch information
PanchoBubble committed Dec 23, 2024
1 parent 3690857 commit 593730e
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default function ShareRewardModal() {

const referralCode = userDetails?.user?.referral_code || '';
const gemsValue = (referralQuestPoints?.pointsForClaimingReferral || GIFT_GEMS).toLocaleString();
const block = item?.blockHeight || 0;
const block = item?.mined_in_block_height || 0;
const reward = item?.amount || 0;
const earningsFormatted = useMemo(() => formatNumber(reward, FormatPreset.TXTM_COMPACT).toLowerCase(), [reward]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ export default function Earnings() {
) : null;

const replayText =
replayItem?.amount && replayItem.blockHeight ? (
replayItem?.amount && replayItem.mined_in_block_height ? (
<RecapText>
<Trans
ns="mining-view"
i18nKey={'you-won-block'}
values={{
blockHeight: replayItem.blockHeight,
blockHeight: replayItem.mined_in_block_height,
}}
components={{ span: <span /> }}
/>
Expand Down
12 changes: 4 additions & 8 deletions src/containers/main/SideBar/components/Wallet/HistoryItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import { useCallback, useMemo, useState } from 'react';
import { AnimatePresence } from 'framer-motion';
import gemImage from '../../../Airdrop/AirdropGiftTracker/images/gem.png';
import { useShareRewardStore } from '@app/store/useShareRewardStore.ts';
import { Transaction } from '@app/types/wallet.ts';
import { GIFT_GEMS, useAirdropStore } from '@app/store/useAirdropStore.ts';
import { useAppConfigStore } from '@app/store/useAppConfigStore.ts';
import { ReplaySVG } from '@app/assets/icons/replay';
import { formatNumber, FormatPreset } from '@app/utils/formatters.ts';
import { TransactionInfo } from '@app/types/app-status.ts';

interface HistoryItemProps {
item: Transaction;
item: TransactionInfo;
}

const randomGradientColours = [
Expand Down Expand Up @@ -71,11 +71,7 @@ export default function HistoryItem({ item }: HistoryItemProps) {
handleWinReplay(item);
}, [handleWinReplay, item]);

// if (!item.blockHeight || item.payment_id?.length > 0) {
// return null;
// }

const itemTitle = `${t('block')} #${item.blockHeight}`;
const itemTitle = `${t('block')} #${item.mined_in_block_height}`;
const itemTime = new Date(item.timestamp * 1000)?.toLocaleString(systemLang ? undefined : appLanguage, {
month: 'short',
day: '2-digit',
Expand Down Expand Up @@ -122,7 +118,7 @@ export default function HistoryItem({ item }: HistoryItemProps) {
<TariSvg />
</SquadIconWrapper>
<InfoWrapper>
{item.blockHeight ? (
{item.mined_in_block_height ? (
<>
<Typography>{itemTitle}</Typography>
<Typography variant="p">{itemTime}</Typography>
Expand Down
12 changes: 6 additions & 6 deletions src/containers/main/SideBar/components/Wallet/Wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ export default function Wallet() {
const displayValue = balance === null ? '-' : showBalance ? formatted : '*****';

const handleShowClick = useCallback(async () => {
// if (balance && !transactions.length && !isTransactionLoading) {
// await fetchTx();
// } else {
// setRecapCount(undefined);
// }
await fetchTx();
console.log({ balance, transactions, isTransactionLoading });

Check warning on line 66 in src/containers/main/SideBar/components/Wallet/Wallet.tsx

View workflow job for this annotation

GitHub Actions / Run linters

Unexpected console statement
if (balance && !transactions.length && !isTransactionLoading) {
await fetchTx();
} else {
setRecapCount(undefined);
}

setShowHistory((c) => !c);
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
23 changes: 2 additions & 21 deletions src/hooks/mining/useTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,22 @@ import { useCallback } from 'react';
import { invoke } from '@tauri-apps/api/core';
import { useAppStateStore } from '@app/store/appStateStore.ts';
import { useWalletStore } from '@app/store/useWalletStore.ts';
import { Transaction } from '@app/types/wallet.ts';

export default function useFetchTx() {
const transactions = useWalletStore((s) => s.transactions);
const isTransactionLoading = useWalletStore((s) => s.isTransactionLoading);
const setTransactionsLoading = useWalletStore((s) => s.setTransactionsLoading);
const setupProgress = useAppStateStore((s) => s.setupProgress);
const setTransactions = useWalletStore((s) => s.setTransactions);

const setItems = useCallback(
async (newTx: Transaction[]) => {
const latestTx = newTx[0];
const latestId = latestTx?.tx_id;
const hasNewItems = transactions?.find((tx) => tx.tx_id === latestId);
if (hasNewItems) {
setTransactions(newTx);
}
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[transactions]
);

return useCallback(async () => {
if (isTransactionLoading || setupProgress < 0.75) return;
setTransactionsLoading(true);

try {
const txs = await invoke('get_transaction_history');
const sortedTransactions = txs.sort((a, b) => b.timestamp - a.timestamp);
const mapped = sortedTransactions?.map((tx) => {
return { ...tx, blockHeight: tx.mined_in_block_height };
}) as Transaction[];

if (mapped?.length) {
await setItems(mapped);
if (sortedTransactions?.length) {
setTransactions(sortedTransactions);
}
setTransactionsLoading(false);
} catch (error) {
Expand Down
7 changes: 3 additions & 4 deletions src/store/useBlockchainVisualisationStore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Transaction } from '@app/types/wallet';
import { create } from './create';
import { useMiningStore } from './useMiningStore.ts';

Expand All @@ -21,7 +20,7 @@ interface State {
recapData?: Recap;
recapCount?: number;
recapIds: TransactionInfo['tx_id'][];
replayItem?: Transaction;
replayItem?: TransactionInfo;
}

interface WinAnimation {
Expand All @@ -32,7 +31,7 @@ interface WinAnimation {
interface Actions {
handleWin: ({ latestTx, canAnimate, isRecap }: WinAnimation) => Promise<void>;
handleWinRecap: (recapData: Recap) => void;
handleWinReplay: (txItem: Transaction) => void;
handleWinReplay: (txItem: TransactionInfo) => void;
handleFail: (blockHeight: number, canAnimate?: boolean) => Promise<void>;
handleNewBlock: (newBlockHeight: number, isMining?: boolean) => Promise<void>;
setDisplayBlockHeight: (displayBlockHeight: number) => void;
Expand Down Expand Up @@ -100,7 +99,7 @@ export const useBlockchainVisualisationStore = create<BlockchainVisualisationSto
}
},
handleWin: async ({ latestTx, canAnimate }) => {
const blockHeight = Number(latestTx?.message?.split(': ')[1]);
const blockHeight = Number(latestTx?.mined_in_block_height);
const earnings = latestTx.amount;

console.info(`Block #${blockHeight} mined! Earnings: ${earnings}`);
Expand Down
6 changes: 3 additions & 3 deletions src/store/useShareRewardStore.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { TransactionInfo } from '@app/types/app-status.ts';
import { create } from './create.ts';
import { Transaction } from '@app/types/wallet.ts';

interface State {
showModal: boolean;
item: Transaction | null;
item: TransactionInfo | null;
}

interface Actions {
setShowModal: (showModal: boolean) => void;
setItemData: (item: Transaction | null) => void;
setItemData: (item: TransactionInfo | null) => void;
}

const initialState: State = {
Expand Down
7 changes: 3 additions & 4 deletions src/store/useWalletStore.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import { ALREADY_FETCHING } from '@app/App/sentryIgnore';
import { create } from './create';
import { WalletBalance } from '../types/app-status.ts';
import { TransactionInfo, WalletBalance } from '../types/app-status.ts';
import { invoke } from '@tauri-apps/api/core';
import { Transaction } from '@app/types/wallet.ts';

interface State extends WalletBalance {
tari_address_base58: string;
tari_address_emoji: string;
tari_address?: string;
balance: number | null;
transactions: Transaction[];
transactions: TransactionInfo[];
isTransactionLoading: boolean;
is_wallet_importing: boolean;
}

interface Actions {
fetchWalletDetails: () => Promise<void>;
setTransactionsLoading: (isTransactionLoading: boolean) => void;
setTransactions: (transactions?: Transaction[]) => void;
setTransactions: (transactions?: TransactionInfo[]) => void;
importSeedWords: (seedWords: string[]) => Promise<void>;
}

Expand Down
5 changes: 0 additions & 5 deletions src/types/wallet.ts

This file was deleted.

0 comments on commit 593730e

Please sign in to comment.