mirror of
https://github.com/pezkuwichain/pezkuwi-telegram-miniapp.git
synced 2026-04-21 23:37:55 +00:00
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:
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pezkuwi-telegram-miniapp",
|
||||
"version": "1.0.215",
|
||||
"version": "1.0.216",
|
||||
"type": "module",
|
||||
"description": "Pezkuwichain Telegram Mini App - Forum, Announcements, Rewards",
|
||||
"author": "Pezkuwichain Team",
|
||||
|
||||
@@ -188,7 +188,7 @@ interface Props {
|
||||
}
|
||||
|
||||
export function TokensCard({ onSendToken }: Props) {
|
||||
const { address, balance: hezBalance } = useWallet();
|
||||
const { address, rcBalance: hezBalance } = useWallet();
|
||||
const { hapticImpact } = useTelegram();
|
||||
const { t } = useTranslation();
|
||||
const [rpcConnected, setRpcConnected] = useState(false);
|
||||
|
||||
@@ -50,7 +50,7 @@ interface Transaction {
|
||||
}
|
||||
|
||||
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 { t } = useTranslation();
|
||||
|
||||
@@ -618,6 +618,11 @@ export function WalletDashboard({ onDisconnect }: Props) {
|
||||
{isLoading ? '...' : (balance ?? '0')}
|
||||
<span className="text-lg text-gray-400 ml-2">HEZ</span>
|
||||
</div>
|
||||
{stakedBalance && parseFloat(stakedBalance) > 0 && (
|
||||
<p className="text-xs text-gray-400 mt-1">
|
||||
{t('dashboard.stakedNote', { amount: parseFloat(stakedBalance).toLocaleString() })}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* PEZ Balance Card */}
|
||||
@@ -952,7 +957,7 @@ const SEND_TOKENS: TokenOption[] = [
|
||||
|
||||
// Send Tab
|
||||
function SendTab({ onBack }: { onBack: () => void }) {
|
||||
const { balance, api, assetHubApi, keypair } = useWallet();
|
||||
const { rcBalance, api, assetHubApi, keypair } = useWallet();
|
||||
const { hapticNotification, hapticImpact } = useTelegram();
|
||||
const { t } = useTranslation();
|
||||
|
||||
@@ -1008,7 +1013,7 @@ function SendTab({ onBack }: { onBack: () => void }) {
|
||||
}, [assetHubApi, keypair]);
|
||||
|
||||
const getCurrentBalance = () => {
|
||||
if (selectedToken === 'HEZ') return balance ?? '0.0000';
|
||||
if (selectedToken === 'HEZ') return rcBalance ?? '0.0000';
|
||||
if (selectedToken === 'PEZ') return pezBalance;
|
||||
if (selectedToken === 'USDT') return usdtBalance;
|
||||
if (selectedToken === 'DOT') return dotBalance;
|
||||
@@ -1138,7 +1143,7 @@ function SendTab({ onBack }: { onBack: () => void }) {
|
||||
{SEND_TOKENS.map((token) => {
|
||||
const tokenBalance =
|
||||
token.symbol === 'HEZ'
|
||||
? (balance ?? '0.0000')
|
||||
? (rcBalance ?? '0.0000')
|
||||
: token.symbol === 'PEZ'
|
||||
? pezBalance
|
||||
: token.symbol === 'USDT'
|
||||
|
||||
@@ -39,6 +39,8 @@ interface WalletContextType {
|
||||
isLoading: boolean;
|
||||
address: string | null;
|
||||
balance: string | null;
|
||||
rcBalance: string | null;
|
||||
stakedBalance: string | null;
|
||||
error: string | null;
|
||||
|
||||
// Wallet management
|
||||
@@ -68,6 +70,8 @@ export function WalletProvider({ children }: { children: React.ReactNode }) {
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [address, setAddress] = 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 [api, setApi] = 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) {
|
||||
rcFreeRef.current = 0n;
|
||||
setRcBalance(null);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -179,6 +184,7 @@ export function WalletProvider({ children }: { children: React.ReactNode }) {
|
||||
rcFreeRef.current = accountInfo.data.free.toBigInt
|
||||
? accountInfo.data.free.toBigInt()
|
||||
: BigInt(accountInfo.data.free.toString());
|
||||
setRcBalance((Number(rcFreeRef.current) / 1e12).toFixed(4));
|
||||
updateTotalBalance();
|
||||
}
|
||||
);
|
||||
@@ -235,8 +241,10 @@ export function WalletProvider({ children }: { children: React.ReactNode }) {
|
||||
ahStakedRef.current = ledger.active.toBigInt
|
||||
? ledger.active.toBigInt()
|
||||
: BigInt(ledger.active.toString());
|
||||
setStakedBalance((Number(ahStakedRef.current) / 1e12).toFixed(4));
|
||||
} else {
|
||||
ahStakedRef.current = 0n;
|
||||
setStakedBalance(null);
|
||||
}
|
||||
updateTotalBalance();
|
||||
}
|
||||
@@ -343,6 +351,8 @@ export function WalletProvider({ children }: { children: React.ReactNode }) {
|
||||
setKeypair(null);
|
||||
setIsConnected(false);
|
||||
setBalance(null);
|
||||
setRcBalance(null);
|
||||
setStakedBalance(null);
|
||||
rcFreeRef.current = 0n;
|
||||
ahFreeRef.current = 0n;
|
||||
ahStakedRef.current = 0n;
|
||||
@@ -355,6 +365,8 @@ export function WalletProvider({ children }: { children: React.ReactNode }) {
|
||||
setKeypair(null);
|
||||
setIsConnected(false);
|
||||
setBalance(null);
|
||||
setRcBalance(null);
|
||||
setStakedBalance(null);
|
||||
rcFreeRef.current = 0n;
|
||||
ahFreeRef.current = 0n;
|
||||
ahStakedRef.current = 0n;
|
||||
@@ -368,6 +380,8 @@ export function WalletProvider({ children }: { children: React.ReactNode }) {
|
||||
isLoading,
|
||||
address,
|
||||
balance,
|
||||
rcBalance,
|
||||
stakedBalance,
|
||||
error,
|
||||
hasWallet,
|
||||
generateNewWallet,
|
||||
|
||||
@@ -345,6 +345,7 @@ const ar: Translations = {
|
||||
lpStakeDesc: 'رهن LP token',
|
||||
pezRewardPlus: 'مكافأة PEZ +',
|
||||
goBack: 'رجوع',
|
||||
stakedNote: 'المُرهَن: {{amount}} HEZ',
|
||||
},
|
||||
|
||||
// Send
|
||||
|
||||
@@ -347,6 +347,7 @@ const ckb: Translations = {
|
||||
lpStakeDesc: 'LP token stake بکە',
|
||||
pezRewardPlus: 'PEZ پاداشت +',
|
||||
goBack: 'گەڕانەوە',
|
||||
stakedNote: 'ستەیک کراو: {{amount}} HEZ',
|
||||
},
|
||||
|
||||
// Send
|
||||
|
||||
@@ -346,6 +346,7 @@ const en: Translations = {
|
||||
lpStakeDesc: 'Stake LP tokens',
|
||||
pezRewardPlus: 'PEZ Reward +',
|
||||
goBack: 'Back',
|
||||
stakedNote: 'Staked: {{amount}} HEZ',
|
||||
},
|
||||
|
||||
// Send
|
||||
|
||||
@@ -346,6 +346,7 @@ const fa: Translations = {
|
||||
lpStakeDesc: 'استیک کردن LP token',
|
||||
pezRewardPlus: 'پاداش PEZ +',
|
||||
goBack: 'بازگشت',
|
||||
stakedNote: 'استیک شده: {{amount}} HEZ',
|
||||
},
|
||||
|
||||
// Send
|
||||
|
||||
@@ -362,6 +362,7 @@ const krd: Translations = {
|
||||
lpStakeDesc: 'LP token stake bike',
|
||||
pezRewardPlus: 'PEZ Xelat +',
|
||||
goBack: 'Pa\u015fve',
|
||||
stakedNote: 'Staked: {{amount}} HEZ',
|
||||
},
|
||||
|
||||
// Send
|
||||
|
||||
@@ -346,6 +346,7 @@ const tr: Translations = {
|
||||
lpStakeDesc: 'LP token stake et',
|
||||
pezRewardPlus: 'PEZ Ödül +',
|
||||
goBack: 'Geri',
|
||||
stakedNote: 'Stake edilen: {{amount}} HEZ',
|
||||
},
|
||||
|
||||
// Send
|
||||
|
||||
@@ -351,6 +351,7 @@ export interface Translations {
|
||||
lpStakeDesc: string;
|
||||
pezRewardPlus: string;
|
||||
goBack: string;
|
||||
stakedNote: string;
|
||||
};
|
||||
|
||||
// Send Tab
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "1.0.215",
|
||||
"buildTime": "2026-02-21T11:44:52.032Z",
|
||||
"buildNumber": 1771674292034
|
||||
"version": "1.0.216",
|
||||
"buildTime": "2026-02-21T12:12:08.352Z",
|
||||
"buildNumber": 1771675928353
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user