diff --git a/package.json b/package.json index 27a6af4..4b57830 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pezkuwi-telegram-miniapp", - "version": "1.0.177", + "version": "1.0.181", "type": "module", "description": "Pezkuwichain Telegram Mini App - Forum, Announcements, Rewards", "author": "Pezkuwichain Team", diff --git a/src/components/wallet/DepositUSDTModal.tsx b/src/components/wallet/DepositUSDTModal.tsx index f1358ab..b4c5443 100644 --- a/src/components/wallet/DepositUSDTModal.tsx +++ b/src/components/wallet/DepositUSDTModal.tsx @@ -80,7 +80,6 @@ interface Deposit { interface Props { isOpen: boolean; onClose: () => void; - userId: string | null; } export function DepositUSDTModal({ isOpen, onClose }: Props) { diff --git a/src/components/wallet/TokensCard.tsx b/src/components/wallet/TokensCard.tsx index 4d26911..f5dac61 100644 --- a/src/components/wallet/TokensCard.tsx +++ b/src/components/wallet/TokensCard.tsx @@ -954,11 +954,7 @@ export function TokensCard({ onSendToken }: Props) { setShowFundFeesModal(false)} /> {/* Deposit USDT Modal */} - setShowDepositModal(false)} - userId={null} - /> + setShowDepositModal(false)} /> ); } diff --git a/src/components/wallet/WalletDashboard.tsx b/src/components/wallet/WalletDashboard.tsx index 29676e2..29088c0 100644 --- a/src/components/wallet/WalletDashboard.tsx +++ b/src/components/wallet/WalletDashboard.tsx @@ -26,6 +26,7 @@ import { SwapModal } from './SwapModal'; import { PoolsModal } from './PoolsModal'; import { LPStakingModal } from './LPStakingModal'; import { HEZStakingModal } from './HEZStakingModal'; +import { DepositUSDTModal } from './DepositUSDTModal'; import { useWallet } from '@/contexts/WalletContext'; import { useTelegram } from '@/hooks/useTelegram'; import { formatAddress } from '@/lib/wallet-service'; @@ -62,6 +63,7 @@ export function WalletDashboard({ onDisconnect }: Props) { const [isLPStakingModalOpen, setIsLPStakingModalOpen] = useState(false); const [isHEZStakingModalOpen, setIsHEZStakingModalOpen] = useState(false); const [isStakingSelectorOpen, setIsStakingSelectorOpen] = useState(false); + const [isDepositUSDTModalOpen, setIsDepositUSDTModalOpen] = useState(false); // Subscribe to PEZ balance (Asset ID: 1) - Uses Asset Hub API useEffect(() => { @@ -189,13 +191,35 @@ export function WalletDashboard({ onDisconnect }: Props) { const { method, signer } = extrinsic; const fromAddress = signer.toString(); - // Parse assets.transfer and transferKeepAlive (PEZ) + // Parse assets.transfer and transferKeepAlive (PEZ/wUSDT) if ( method.section === 'assets' && (method.method === 'transfer' || method.method === 'transferKeepAlive') ) { const [assetId, dest, value] = method.args; - const toAddress = dest.toString(); + // Extract address from MultiAddress format + let toAddress = ''; + try { + const destStr = String(dest); + if (destStr.startsWith('5') || destStr.startsWith('1')) { + toAddress = destStr; + } else { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const destObj = dest as any; + if (destObj.isId) { + toAddress = destObj.asId.toString(); + } else if (destObj.Id) { + toAddress = destObj.Id.toString(); + } else if (typeof destObj.toHuman === 'function') { + const human = destObj.toHuman(); + toAddress = typeof human === 'string' ? human : human?.Id || destStr; + } else { + toAddress = destStr; + } + } + } catch { + toAddress = String(dest); + } const isFromUs = fromAddress === address; const isToUs = toAddress === address; @@ -363,7 +387,50 @@ export function WalletDashboard({ onDisconnect }: Props) { }; }, [api, address, hapticNotification]); - // Real-time subscription to Asset Hub for PEZ transactions + // Helper function to extract address from MultiAddress format + const extractAddress = (dest: unknown): string => { + if (!dest) return ''; + + // If it's already a string that looks like an address + const destStr = String(dest); + if (destStr.startsWith('5') || destStr.startsWith('1')) { + return destStr; + } + + // Try to parse as MultiAddress object + try { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const destObj = dest as any; + + // Handle { Id: '5xxx...' } format + if (destObj.isId) { + return destObj.asId.toString(); + } + if (destObj.Id) { + return destObj.Id.toString(); + } + + // Handle direct object with id property + if (typeof destObj.toHuman === 'function') { + const human = destObj.toHuman(); + if (typeof human === 'string') return human; + if (human?.Id) return human.Id; + } + + // Try JSON parse for string representation + if (destStr.startsWith('{')) { + const parsed = JSON.parse(destStr); + if (parsed.Id) return parsed.Id; + if (parsed.id) return parsed.id; + } + } catch { + // Fall back to string + } + + return destStr; + }; + + // Real-time subscription to Asset Hub for PEZ/wUSDT transactions useEffect(() => { if (!assetHubApi || !address) return; @@ -390,7 +457,7 @@ export function WalletDashboard({ onDisconnect }: Props) { (method.method === 'transfer' || method.method === 'transferKeepAlive') ) { const [assetId, dest, value] = method.args; - const toAddress = dest.toString(); + const toAddress = extractAddress(dest); const isFromUs = fromAddress === address; const isToUs = toAddress === address; @@ -457,8 +524,19 @@ export function WalletDashboard({ onDisconnect }: Props) { fetchRecentTransactions(); }; + const getDecimalsForAsset = (section: string, assetId?: string): number => { + if (section === 'balances') return 12; // HEZ + if (assetId === '1') return 12; // PEZ + if (assetId === '1000') return 6; // wUSDT + if (assetId === '1001') return 10; // DOT + if (assetId === '1002') return 18; // ETH + if (assetId === '1003') return 8; // BTC + return 12; // Default + }; + const formatAmount = (amount: string, decimals: number = 12) => { const value = parseInt(amount) / Math.pow(10, decimals); + if (decimals <= 6) return value.toFixed(2); // wUSDT return value.toFixed(4); }; @@ -635,6 +713,28 @@ export function WalletDashboard({ onDisconnect }: Props) { + {/* Add USDT Card */} +
+ +
+ {/* Recent Activity */}
@@ -702,14 +802,22 @@ export function WalletDashboard({ onDisconnect }: Props) { className={`text-sm font-mono ${tx.direction === 'sent' ? 'text-yellow-400' : 'text-green-400'}`} > {tx.direction === 'sent' ? '-' : '+'} - {formatAmount(tx.amount || '0')} + {formatAmount(tx.amount || '0', getDecimalsForAsset(tx.section, tx.assetId))}
{tx.section === 'balances' ? 'HEZ' : tx.assetId === '1' ? 'PEZ' - : `Asset #${tx.assetId}`} + : tx.assetId === '1000' + ? 'wUSDT' + : tx.assetId === '1001' + ? 'DOT' + : tx.assetId === '1002' + ? 'ETH' + : tx.assetId === '1003' + ? 'BTC' + : `Asset #${tx.assetId}`}
@@ -735,6 +843,10 @@ export function WalletDashboard({ onDisconnect }: Props) { isOpen={isHEZStakingModalOpen} onClose={() => setIsHEZStakingModalOpen(false)} /> + setIsDepositUSDTModalOpen(false)} + /> {/* Staking Selector */} {isStakingSelectorOpen && ( @@ -1296,8 +1408,19 @@ function HistoryTab({ }) { const { hapticImpact } = useTelegram(); + const getDecimalsForAsset = (section: string, assetId?: string): number => { + if (section === 'balances') return 12; // HEZ + if (assetId === '1') return 12; // PEZ + if (assetId === '1000') return 6; // wUSDT + if (assetId === '1001') return 10; // DOT + if (assetId === '1002') return 18; // ETH + if (assetId === '1003') return 8; // BTC + return 12; // Default + }; + const formatAmount = (amount: string, decimals: number = 12) => { const value = parseInt(amount) / Math.pow(10, decimals); + if (decimals <= 6) return value.toFixed(2); // wUSDT return value.toFixed(4); }; @@ -1366,7 +1489,7 @@ function HistoryTab({ className={`font-mono font-semibold ${tx.direction === 'sent' ? 'text-yellow-400' : 'text-green-400'}`} > {tx.direction === 'sent' ? '-' : '+'} - {formatAmount(tx.amount || '0')} + {formatAmount(tx.amount || '0', getDecimalsForAsset(tx.section, tx.assetId))}
{tx.section === 'balances' diff --git a/src/version.json b/src/version.json index b664a5d..466db1a 100644 --- a/src/version.json +++ b/src/version.json @@ -1,5 +1,5 @@ { - "version": "1.0.177", - "buildTime": "2026-02-08T01:24:06.896Z", - "buildNumber": 1770513846897 + "version": "1.0.181", + "buildTime": "2026-02-08T02:31:45.624Z", + "buildNumber": 1770517905625 }