fix: show total HEZ balance in card, use RC free for send tab

- Balance card shows RC + AH + staked total with staked note
- Tokens section shows free balances only
- Send tab checks against RC free balance to prevent failed transfers
This commit is contained in:
2026-02-21 15:12:08 +03:00
parent 9a2f74b783
commit 123183038f
12 changed files with 35 additions and 9 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "pezkuwi-telegram-miniapp", "name": "pezkuwi-telegram-miniapp",
"version": "1.0.215", "version": "1.0.216",
"type": "module", "type": "module",
"description": "Pezkuwichain Telegram Mini App - Forum, Announcements, Rewards", "description": "Pezkuwichain Telegram Mini App - Forum, Announcements, Rewards",
"author": "Pezkuwichain Team", "author": "Pezkuwichain Team",
+1 -1
View File
@@ -188,7 +188,7 @@ interface Props {
} }
export function TokensCard({ onSendToken }: Props) { export function TokensCard({ onSendToken }: Props) {
const { address, balance: hezBalance } = useWallet(); const { address, rcBalance: hezBalance } = useWallet();
const { hapticImpact } = useTelegram(); const { hapticImpact } = useTelegram();
const { t } = useTranslation(); const { t } = useTranslation();
const [rpcConnected, setRpcConnected] = useState(false); const [rpcConnected, setRpcConnected] = useState(false);
+9 -4
View File
@@ -50,7 +50,7 @@ interface Transaction {
} }
export function WalletDashboard({ onDisconnect }: Props) { export function WalletDashboard({ onDisconnect }: Props) {
const { address, balance, api, assetHubApi, disconnect, isLoading } = useWallet(); const { address, balance, stakedBalance, api, assetHubApi, disconnect, isLoading } = useWallet();
const { hapticImpact, hapticNotification, showAlert } = useTelegram(); const { hapticImpact, hapticNotification, showAlert } = useTelegram();
const { t } = useTranslation(); const { t } = useTranslation();
@@ -618,6 +618,11 @@ export function WalletDashboard({ onDisconnect }: Props) {
{isLoading ? '...' : (balance ?? '0')} {isLoading ? '...' : (balance ?? '0')}
<span className="text-lg text-gray-400 ml-2">HEZ</span> <span className="text-lg text-gray-400 ml-2">HEZ</span>
</div> </div>
{stakedBalance && parseFloat(stakedBalance) > 0 && (
<p className="text-xs text-gray-400 mt-1">
{t('dashboard.stakedNote', { amount: parseFloat(stakedBalance).toLocaleString() })}
</p>
)}
</div> </div>
{/* PEZ Balance Card */} {/* PEZ Balance Card */}
@@ -952,7 +957,7 @@ const SEND_TOKENS: TokenOption[] = [
// Send Tab // Send Tab
function SendTab({ onBack }: { onBack: () => void }) { function SendTab({ onBack }: { onBack: () => void }) {
const { balance, api, assetHubApi, keypair } = useWallet(); const { rcBalance, api, assetHubApi, keypair } = useWallet();
const { hapticNotification, hapticImpact } = useTelegram(); const { hapticNotification, hapticImpact } = useTelegram();
const { t } = useTranslation(); const { t } = useTranslation();
@@ -1008,7 +1013,7 @@ function SendTab({ onBack }: { onBack: () => void }) {
}, [assetHubApi, keypair]); }, [assetHubApi, keypair]);
const getCurrentBalance = () => { const getCurrentBalance = () => {
if (selectedToken === 'HEZ') return balance ?? '0.0000'; if (selectedToken === 'HEZ') return rcBalance ?? '0.0000';
if (selectedToken === 'PEZ') return pezBalance; if (selectedToken === 'PEZ') return pezBalance;
if (selectedToken === 'USDT') return usdtBalance; if (selectedToken === 'USDT') return usdtBalance;
if (selectedToken === 'DOT') return dotBalance; if (selectedToken === 'DOT') return dotBalance;
@@ -1138,7 +1143,7 @@ function SendTab({ onBack }: { onBack: () => void }) {
{SEND_TOKENS.map((token) => { {SEND_TOKENS.map((token) => {
const tokenBalance = const tokenBalance =
token.symbol === 'HEZ' token.symbol === 'HEZ'
? (balance ?? '0.0000') ? (rcBalance ?? '0.0000')
: token.symbol === 'PEZ' : token.symbol === 'PEZ'
? pezBalance ? pezBalance
: token.symbol === 'USDT' : token.symbol === 'USDT'
+14
View File
@@ -39,6 +39,8 @@ interface WalletContextType {
isLoading: boolean; isLoading: boolean;
address: string | null; address: string | null;
balance: string | null; balance: string | null;
rcBalance: string | null;
stakedBalance: string | null;
error: string | null; error: string | null;
// Wallet management // Wallet management
@@ -68,6 +70,8 @@ export function WalletProvider({ children }: { children: React.ReactNode }) {
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
const [address, setAddress] = useState<string | null>(null); const [address, setAddress] = useState<string | null>(null);
const [balance, setBalance] = useState<string | null>(null); const [balance, setBalance] = useState<string | null>(null);
const [rcBalance, setRcBalance] = useState<string | null>(null);
const [stakedBalance, setStakedBalance] = useState<string | null>(null);
const [error, setError] = useState<string | null>(null); const [error, setError] = useState<string | null>(null);
const [api, setApi] = useState<ApiPromise | null>(null); const [api, setApi] = useState<ApiPromise | null>(null);
const [assetHubApi, setAssetHubApi] = useState<ApiPromise | null>(null); const [assetHubApi, setAssetHubApi] = useState<ApiPromise | null>(null);
@@ -165,6 +169,7 @@ export function WalletProvider({ children }: { children: React.ReactNode }) {
if (!api || !address || !isConnected) { if (!api || !address || !isConnected) {
rcFreeRef.current = 0n; rcFreeRef.current = 0n;
setRcBalance(null);
return; return;
} }
@@ -179,6 +184,7 @@ export function WalletProvider({ children }: { children: React.ReactNode }) {
rcFreeRef.current = accountInfo.data.free.toBigInt rcFreeRef.current = accountInfo.data.free.toBigInt
? accountInfo.data.free.toBigInt() ? accountInfo.data.free.toBigInt()
: BigInt(accountInfo.data.free.toString()); : BigInt(accountInfo.data.free.toString());
setRcBalance((Number(rcFreeRef.current) / 1e12).toFixed(4));
updateTotalBalance(); updateTotalBalance();
} }
); );
@@ -235,8 +241,10 @@ export function WalletProvider({ children }: { children: React.ReactNode }) {
ahStakedRef.current = ledger.active.toBigInt ahStakedRef.current = ledger.active.toBigInt
? ledger.active.toBigInt() ? ledger.active.toBigInt()
: BigInt(ledger.active.toString()); : BigInt(ledger.active.toString());
setStakedBalance((Number(ahStakedRef.current) / 1e12).toFixed(4));
} else { } else {
ahStakedRef.current = 0n; ahStakedRef.current = 0n;
setStakedBalance(null);
} }
updateTotalBalance(); updateTotalBalance();
} }
@@ -343,6 +351,8 @@ export function WalletProvider({ children }: { children: React.ReactNode }) {
setKeypair(null); setKeypair(null);
setIsConnected(false); setIsConnected(false);
setBalance(null); setBalance(null);
setRcBalance(null);
setStakedBalance(null);
rcFreeRef.current = 0n; rcFreeRef.current = 0n;
ahFreeRef.current = 0n; ahFreeRef.current = 0n;
ahStakedRef.current = 0n; ahStakedRef.current = 0n;
@@ -355,6 +365,8 @@ export function WalletProvider({ children }: { children: React.ReactNode }) {
setKeypair(null); setKeypair(null);
setIsConnected(false); setIsConnected(false);
setBalance(null); setBalance(null);
setRcBalance(null);
setStakedBalance(null);
rcFreeRef.current = 0n; rcFreeRef.current = 0n;
ahFreeRef.current = 0n; ahFreeRef.current = 0n;
ahStakedRef.current = 0n; ahStakedRef.current = 0n;
@@ -368,6 +380,8 @@ export function WalletProvider({ children }: { children: React.ReactNode }) {
isLoading, isLoading,
address, address,
balance, balance,
rcBalance,
stakedBalance,
error, error,
hasWallet, hasWallet,
generateNewWallet, generateNewWallet,
+1
View File
@@ -345,6 +345,7 @@ const ar: Translations = {
lpStakeDesc: 'رهن LP token', lpStakeDesc: 'رهن LP token',
pezRewardPlus: 'مكافأة PEZ +', pezRewardPlus: 'مكافأة PEZ +',
goBack: 'رجوع', goBack: 'رجوع',
stakedNote: 'المُرهَن: {{amount}} HEZ',
}, },
// Send // Send
+1
View File
@@ -347,6 +347,7 @@ const ckb: Translations = {
lpStakeDesc: 'LP token stake بکە', lpStakeDesc: 'LP token stake بکە',
pezRewardPlus: 'PEZ پاداشت +', pezRewardPlus: 'PEZ پاداشت +',
goBack: 'گەڕانەوە', goBack: 'گەڕانەوە',
stakedNote: 'ستەیک کراو: {{amount}} HEZ',
}, },
// Send // Send
+1
View File
@@ -346,6 +346,7 @@ const en: Translations = {
lpStakeDesc: 'Stake LP tokens', lpStakeDesc: 'Stake LP tokens',
pezRewardPlus: 'PEZ Reward +', pezRewardPlus: 'PEZ Reward +',
goBack: 'Back', goBack: 'Back',
stakedNote: 'Staked: {{amount}} HEZ',
}, },
// Send // Send
+1
View File
@@ -346,6 +346,7 @@ const fa: Translations = {
lpStakeDesc: 'استیک کردن LP token', lpStakeDesc: 'استیک کردن LP token',
pezRewardPlus: 'پاداش PEZ +', pezRewardPlus: 'پاداش PEZ +',
goBack: 'بازگشت', goBack: 'بازگشت',
stakedNote: 'استیک شده: {{amount}} HEZ',
}, },
// Send // Send
+1
View File
@@ -362,6 +362,7 @@ const krd: Translations = {
lpStakeDesc: 'LP token stake bike', lpStakeDesc: 'LP token stake bike',
pezRewardPlus: 'PEZ Xelat +', pezRewardPlus: 'PEZ Xelat +',
goBack: 'Pa\u015fve', goBack: 'Pa\u015fve',
stakedNote: 'Staked: {{amount}} HEZ',
}, },
// Send // Send
+1
View File
@@ -346,6 +346,7 @@ const tr: Translations = {
lpStakeDesc: 'LP token stake et', lpStakeDesc: 'LP token stake et',
pezRewardPlus: 'PEZ Ödül +', pezRewardPlus: 'PEZ Ödül +',
goBack: 'Geri', goBack: 'Geri',
stakedNote: 'Stake edilen: {{amount}} HEZ',
}, },
// Send // Send
+1
View File
@@ -351,6 +351,7 @@ export interface Translations {
lpStakeDesc: string; lpStakeDesc: string;
pezRewardPlus: string; pezRewardPlus: string;
goBack: string; goBack: string;
stakedNote: string;
}; };
// Send Tab // Send Tab
+3 -3
View File
@@ -1,5 +1,5 @@
{ {
"version": "1.0.215", "version": "1.0.216",
"buildTime": "2026-02-21T11:44:52.032Z", "buildTime": "2026-02-21T12:12:08.352Z",
"buildNumber": 1771674292034 "buildNumber": 1771675928353
} }