mirror of
https://github.com/pezkuwichain/pwap.git
synced 2026-04-28 02:38:00 +00:00
Fix ESLint errors: remove any types, fix console statements, remove unused vars
This commit is contained in:
@@ -14,15 +14,22 @@ import {
|
|||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
import { useFocusEffect } from '@react-navigation/native';
|
import { useFocusEffect } from '@react-navigation/native';
|
||||||
import { LinearGradient } from 'expo-linear-gradient';
|
import { LinearGradient } from 'expo-linear-gradient';
|
||||||
import { useNavigation } from '@react-navigation/native';
|
import { useNavigation, NavigationProp, ParamListBase } from '@react-navigation/native';
|
||||||
import { useAuth } from '../contexts/AuthContext';
|
import { useAuth } from '../contexts/AuthContext';
|
||||||
import { useTheme } from '../contexts/ThemeContext';
|
import { useTheme } from '../contexts/ThemeContext';
|
||||||
import { KurdistanColors } from '../theme/colors';
|
import { KurdistanColors } from '../theme/colors';
|
||||||
import { supabase } from '../lib/supabase';
|
import { supabase } from '../lib/supabase';
|
||||||
import AvatarPickerModal from '../components/AvatarPickerModal';
|
import AvatarPickerModal from '../components/AvatarPickerModal';
|
||||||
|
|
||||||
|
// Alert button type for cross-platform compatibility
|
||||||
|
interface AlertButton {
|
||||||
|
text: string;
|
||||||
|
onPress?: () => void;
|
||||||
|
style?: 'default' | 'cancel' | 'destructive';
|
||||||
|
}
|
||||||
|
|
||||||
// Cross-platform alert helper
|
// Cross-platform alert helper
|
||||||
const showAlert = (title: string, message: string, buttons?: Array<{text: string; onPress?: () => void; style?: string}>) => {
|
const showAlert = (title: string, message: string, buttons?: AlertButton[]) => {
|
||||||
if (Platform.OS === 'web') {
|
if (Platform.OS === 'web') {
|
||||||
if (buttons && buttons.length > 1) {
|
if (buttons && buttons.length > 1) {
|
||||||
const result = window.confirm(`${title}\n\n${message}`);
|
const result = window.confirm(`${title}\n\n${message}`);
|
||||||
@@ -33,7 +40,7 @@ const showAlert = (title: string, message: string, buttons?: Array<{text: string
|
|||||||
window.alert(`${title}\n\n${message}`);
|
window.alert(`${title}\n\n${message}`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Alert.alert(title, message, buttons as any);
|
Alert.alert(title, message, buttons);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -83,7 +90,7 @@ interface ProfileData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const ProfileScreen: React.FC = () => {
|
const ProfileScreen: React.FC = () => {
|
||||||
const navigation = useNavigation<any>();
|
const navigation = useNavigation<NavigationProp<ParamListBase>>();
|
||||||
const { user, signOut } = useAuth();
|
const { user, signOut } = useAuth();
|
||||||
const { isDarkMode, colors, fontScale } = useTheme();
|
const { isDarkMode, colors, fontScale } = useTheme();
|
||||||
const [profileData, setProfileData] = useState<ProfileData | null>(null);
|
const [profileData, setProfileData] = useState<ProfileData | null>(null);
|
||||||
@@ -235,7 +242,7 @@ const ProfileScreen: React.FC = () => {
|
|||||||
icon="👥"
|
icon="👥"
|
||||||
title="Referrals"
|
title="Referrals"
|
||||||
value={`${profileData?.referral_count || 0} people`}
|
value={`${profileData?.referral_count || 0} people`}
|
||||||
onPress={() => (navigation as any).navigate('Referral')}
|
onPress={() => navigation.navigate('Referral')}
|
||||||
testID="profile-card-referrals"
|
testID="profile-card-referrals"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ const SignInScreen: React.FC<SignInScreenProps> = ({ onSignIn, onNavigateToSignU
|
|||||||
onPress={onNavigateToSignUp}
|
onPress={onNavigateToSignUp}
|
||||||
>
|
>
|
||||||
<Text style={styles.signUpPromptText}>
|
<Text style={styles.signUpPromptText}>
|
||||||
Don't have an account?{' '}
|
Don't have an account?{' '}
|
||||||
<Text style={styles.signUpLink}>Sign Up</Text>
|
<Text style={styles.signUpLink}>Sign Up</Text>
|
||||||
</Text>
|
</Text>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
|
|||||||
@@ -70,8 +70,10 @@ export default function StakingScreen() {
|
|||||||
const scores = await getAllScores(api, selectedAccount.address);
|
const scores = await getAllScores(api, selectedAccount.address);
|
||||||
|
|
||||||
// 3. Get Current Era
|
// 3. Get Current Era
|
||||||
const currentEraOpt = await api.query.staking.currentEra() as any;
|
const currentEraOpt = await api.query.staking.currentEra();
|
||||||
const currentEra = currentEraOpt.unwrapOrDefault().toNumber();
|
const currentEra = currentEraOpt.isSome
|
||||||
|
? (currentEraOpt as unknown as { unwrap: () => { toNumber: () => number } }).unwrap().toNumber()
|
||||||
|
: 0;
|
||||||
|
|
||||||
// Calculations
|
// Calculations
|
||||||
const stakedAmount = stakingInfo.bonded;
|
const stakedAmount = stakingInfo.bonded;
|
||||||
|
|||||||
@@ -8,27 +8,25 @@ import {
|
|||||||
TouchableOpacity,
|
TouchableOpacity,
|
||||||
TextInput,
|
TextInput,
|
||||||
Modal,
|
Modal,
|
||||||
ActivityIndicator,
|
|
||||||
Alert,
|
Alert,
|
||||||
Platform,
|
|
||||||
Image,
|
Image,
|
||||||
|
ImageSourcePropType,
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
import { useNavigation } from '@react-navigation/native';
|
|
||||||
import { KurdistanColors } from '../theme/colors';
|
import { KurdistanColors } from '../theme/colors';
|
||||||
import { usePezkuwi } from '../contexts/PezkuwiContext';
|
import { usePezkuwi } from '../contexts/PezkuwiContext';
|
||||||
import { KurdistanSun } from '../components/KurdistanSun';
|
import { KurdistanSun } from '../components/KurdistanSun';
|
||||||
|
|
||||||
// Standardized token logos
|
// Standardized token logos
|
||||||
const hezLogo = require('../../../shared/images/hez_token_512.png');
|
import hezLogo from '../../../shared/images/hez_token_512.png';
|
||||||
const pezLogo = require('../../../shared/images/pez_token_512.png');
|
import pezLogo from '../../../shared/images/pez_token_512.png';
|
||||||
const usdtLogo = require('../../../shared/images/USDT(hez)logo.png');
|
import usdtLogo from '../../../shared/images/USDT(hez)logo.png';
|
||||||
|
|
||||||
interface TokenInfo {
|
interface TokenInfo {
|
||||||
symbol: string;
|
symbol: string;
|
||||||
name: string;
|
name: string;
|
||||||
assetId: number;
|
assetId: number;
|
||||||
decimals: number;
|
decimals: number;
|
||||||
logo: any;
|
logo: ImageSourcePropType;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TOKENS: TokenInfo[] = [
|
const TOKENS: TokenInfo[] = [
|
||||||
@@ -40,7 +38,6 @@ const TOKENS: TokenInfo[] = [
|
|||||||
type TransactionStatus = 'idle' | 'signing' | 'submitting' | 'success' | 'error';
|
type TransactionStatus = 'idle' | 'signing' | 'submitting' | 'success' | 'error';
|
||||||
|
|
||||||
const SwapScreen: React.FC = () => {
|
const SwapScreen: React.FC = () => {
|
||||||
const navigation = useNavigation<any>();
|
|
||||||
const { api, isApiReady, selectedAccount, getKeyPair } = usePezkuwi();
|
const { api, isApiReady, selectedAccount, getKeyPair } = usePezkuwi();
|
||||||
|
|
||||||
const [fromToken, setFromToken] = useState<TokenInfo>(TOKENS[0]);
|
const [fromToken, setFromToken] = useState<TokenInfo>(TOKENS[0]);
|
||||||
@@ -64,7 +61,6 @@ const SwapScreen: React.FC = () => {
|
|||||||
const [isDexAvailable, setIsDexAvailable] = useState(false);
|
const [isDexAvailable, setIsDexAvailable] = useState(false);
|
||||||
|
|
||||||
const [txStatus, setTxStatus] = useState<TransactionStatus>('idle');
|
const [txStatus, setTxStatus] = useState<TransactionStatus>('idle');
|
||||||
const [errorMessage, setErrorMessage] = useState('');
|
|
||||||
|
|
||||||
const [showTokenSelector, setShowTokenSelector] = useState<'from' | 'to' | null>(null);
|
const [showTokenSelector, setShowTokenSelector] = useState<'from' | 'to' | null>(null);
|
||||||
const [showSettings, setShowSettings] = useState(false);
|
const [showSettings, setShowSettings] = useState(false);
|
||||||
@@ -78,28 +74,32 @@ const SwapScreen: React.FC = () => {
|
|||||||
// Fetch From Token Balance
|
// Fetch From Token Balance
|
||||||
try {
|
try {
|
||||||
if (fromToken.symbol === 'HEZ') {
|
if (fromToken.symbol === 'HEZ') {
|
||||||
const accountInfo = await api.query.system.account(selectedAccount.address) as any;
|
const accountInfo = await api.query.system.account(selectedAccount.address);
|
||||||
setFromBalance(accountInfo.data.free.toString());
|
const accountData = accountInfo.toJSON() as { data?: { free?: string } } | null;
|
||||||
|
setFromBalance(accountData?.data?.free?.toString() || '0');
|
||||||
} else {
|
} else {
|
||||||
const balanceData = await api.query.assets.account(fromToken.assetId, selectedAccount.address) as any;
|
const balanceData = await api.query.assets.account(fromToken.assetId, selectedAccount.address);
|
||||||
setFromBalance(balanceData.isSome ? balanceData.unwrap().balance.toString() : '0');
|
const assetBalance = balanceData.toJSON() as { balance?: string } | null;
|
||||||
|
setFromBalance(assetBalance?.balance?.toString() || '0');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (_error) {
|
||||||
console.error('Failed to fetch from balance:', error);
|
if (__DEV__) console.error('Failed to fetch from balance:', _error);
|
||||||
setFromBalance('0');
|
setFromBalance('0');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch To Token Balance
|
// Fetch To Token Balance
|
||||||
try {
|
try {
|
||||||
if (toToken.symbol === 'HEZ') {
|
if (toToken.symbol === 'HEZ') {
|
||||||
const accountInfo = await api.query.system.account(selectedAccount.address) as any;
|
const accountInfo = await api.query.system.account(selectedAccount.address);
|
||||||
setToBalance(accountInfo.data.free.toString());
|
const accountData = accountInfo.toJSON() as { data?: { free?: string } } | null;
|
||||||
|
setToBalance(accountData?.data?.free?.toString() || '0');
|
||||||
} else {
|
} else {
|
||||||
const balanceData = await api.query.assets.account(toToken.assetId, selectedAccount.address) as any;
|
const balanceData = await api.query.assets.account(toToken.assetId, selectedAccount.address);
|
||||||
setToBalance(balanceData.isSome ? balanceData.unwrap().balance.toString() : '0');
|
const assetBalance = balanceData.toJSON() as { balance?: string } | null;
|
||||||
|
setToBalance(assetBalance?.balance?.toString() || '0');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (_error) {
|
||||||
console.error('Failed to fetch to balance:', error);
|
if (__DEV__) console.error('Failed to fetch to balance:', _error);
|
||||||
setToBalance('0');
|
setToBalance('0');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -112,7 +112,7 @@ const SwapScreen: React.FC = () => {
|
|||||||
if (api && isApiReady) {
|
if (api && isApiReady) {
|
||||||
const hasAssetConversion = api.tx.assetConversion !== undefined;
|
const hasAssetConversion = api.tx.assetConversion !== undefined;
|
||||||
setIsDexAvailable(hasAssetConversion);
|
setIsDexAvailable(hasAssetConversion);
|
||||||
if (__DEV__ && !hasAssetConversion) {
|
if (!hasAssetConversion && __DEV__) {
|
||||||
console.warn('AssetConversion pallet not available in runtime');
|
console.warn('AssetConversion pallet not available in runtime');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -192,7 +192,7 @@ const SwapScreen: React.FC = () => {
|
|||||||
const reserve1 = Number(BigInt(balance1Hex)) / (10 ** decimals1);
|
const reserve1 = Number(BigInt(balance1Hex)) / (10 ** decimals1);
|
||||||
|
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
console.log('Pool reserves found:', { reserve0, reserve1, asset1, asset2 });
|
console.warn('Pool reserves found:', { reserve0, reserve1, asset1, asset2 });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store pool reserves for AMM calculation
|
// Store pool reserves for AMM calculation
|
||||||
@@ -274,7 +274,7 @@ const SwapScreen: React.FC = () => {
|
|||||||
const amountOut = numerator / denominator;
|
const amountOut = numerator / denominator;
|
||||||
|
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
console.log('AMM calculation:', {
|
console.warn('AMM calculation:', {
|
||||||
amountIn,
|
amountIn,
|
||||||
reserveIn,
|
reserveIn,
|
||||||
reserveOut,
|
reserveOut,
|
||||||
@@ -348,7 +348,6 @@ const SwapScreen: React.FC = () => {
|
|||||||
|
|
||||||
setTxStatus('signing');
|
setTxStatus('signing');
|
||||||
setShowConfirm(false);
|
setShowConfirm(false);
|
||||||
setErrorMessage('');
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const keypair = await getKeyPair(selectedAccount.address);
|
const keypair = await getKeyPair(selectedAccount.address);
|
||||||
@@ -426,7 +425,6 @@ const SwapScreen: React.FC = () => {
|
|||||||
if (status.isInBlock) {
|
if (status.isInBlock) {
|
||||||
if (dispatchError) {
|
if (dispatchError) {
|
||||||
const errorMsg = dispatchError.toString();
|
const errorMsg = dispatchError.toString();
|
||||||
setErrorMessage(errorMsg);
|
|
||||||
setTxStatus('error');
|
setTxStatus('error');
|
||||||
Alert.alert('Transaction Failed', errorMsg);
|
Alert.alert('Transaction Failed', errorMsg);
|
||||||
} else {
|
} else {
|
||||||
@@ -440,11 +438,11 @@ const SwapScreen: React.FC = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (error: any) {
|
} catch (error: unknown) {
|
||||||
console.error('Swap failed:', error);
|
if (__DEV__) console.error('Swap failed:', error);
|
||||||
setErrorMessage(error.message || 'Transaction failed');
|
|
||||||
setTxStatus('error');
|
setTxStatus('error');
|
||||||
Alert.alert('Error', error.message || 'Swap transaction failed');
|
const errorMessage = error instanceof Error ? error.message : 'Swap transaction failed';
|
||||||
|
Alert.alert('Error', errorMessage);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ import {
|
|||||||
Platform,
|
Platform,
|
||||||
Clipboard,
|
Clipboard,
|
||||||
Share,
|
Share,
|
||||||
|
ImageSourcePropType,
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
import { LinearGradient } from 'expo-linear-gradient';
|
import { useNavigation, NavigationProp, ParamListBase } from '@react-navigation/native';
|
||||||
import { useNavigation } from '@react-navigation/native';
|
|
||||||
import QRCode from 'react-native-qrcode-svg';
|
import QRCode from 'react-native-qrcode-svg';
|
||||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||||
import * as SecureStore from 'expo-secure-store';
|
import * as SecureStore from 'expo-secure-store';
|
||||||
@@ -27,8 +27,8 @@ import { usePezkuwi, NetworkType, NETWORKS } from '../contexts/PezkuwiContext';
|
|||||||
import { AddTokenModal } from '../components/wallet/AddTokenModal';
|
import { AddTokenModal } from '../components/wallet/AddTokenModal';
|
||||||
import { QRScannerModal } from '../components/wallet/QRScannerModal';
|
import { QRScannerModal } from '../components/wallet/QRScannerModal';
|
||||||
// Token logo PNG files are used directly instead of SVG components
|
// Token logo PNG files are used directly instead of SVG components
|
||||||
import { decodeAddress, checkAddress, encodeAddress } from '@pezkuwi/util-crypto';
|
import { decodeAddress, checkAddress } from '@pezkuwi/util-crypto';
|
||||||
import { fetchAllTokens, TokenInfo, subscribeToTokenBalances, KNOWN_TOKENS, TOKEN_LOGOS } from '../services/TokenService';
|
import { fetchAllTokens, TokenInfo, KNOWN_TOKENS, TOKEN_LOGOS } from '../services/TokenService';
|
||||||
|
|
||||||
// Secure storage helper - same as in PezkuwiContext
|
// Secure storage helper - same as in PezkuwiContext
|
||||||
const secureStorage = {
|
const secureStorage = {
|
||||||
@@ -41,8 +41,15 @@ const secureStorage = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Alert button type for cross-platform compatibility
|
||||||
|
interface AlertButton {
|
||||||
|
text: string;
|
||||||
|
onPress?: () => void;
|
||||||
|
style?: 'default' | 'cancel' | 'destructive';
|
||||||
|
}
|
||||||
|
|
||||||
// Cross-platform alert helper
|
// Cross-platform alert helper
|
||||||
const showAlert = (title: string, message: string, buttons?: Array<{text: string; onPress?: () => void; style?: string}>) => {
|
const showAlert = (title: string, message: string, buttons?: AlertButton[]) => {
|
||||||
if (Platform.OS === 'web') {
|
if (Platform.OS === 'web') {
|
||||||
if (buttons && buttons.length > 1) {
|
if (buttons && buttons.length > 1) {
|
||||||
const result = window.confirm(`${title}\n\n${message}`);
|
const result = window.confirm(`${title}\n\n${message}`);
|
||||||
@@ -56,20 +63,15 @@ const showAlert = (title: string, message: string, buttons?: Array<{text: string
|
|||||||
if (buttons?.[0]?.onPress) buttons[0].onPress();
|
if (buttons?.[0]?.onPress) buttons[0].onPress();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Alert.alert(title, message, buttons as any);
|
Alert.alert(title, message, buttons);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Token Images - From shared/images
|
// Token Images - From shared/images
|
||||||
// Standardized token logos
|
// Standardized token logos (only used ones imported)
|
||||||
const hezLogo = require('../../../shared/images/hez_token_512.png');
|
import hezLogo from '../../../shared/images/hez_token_512.png';
|
||||||
const pezLogo = require('../../../shared/images/pez_token_512.png');
|
import pezLogo from '../../../shared/images/pez_token_512.png';
|
||||||
const usdtLogo = require('../../../shared/images/USDT(hez)logo.png');
|
import usdtLogo from '../../../shared/images/USDT(hez)logo.png';
|
||||||
const dotLogo = require('../../../shared/images/dot.png');
|
|
||||||
const btcLogo = require('../../../shared/images/bitcoin.png');
|
|
||||||
const ethLogo = require('../../../shared/images/etherium.png');
|
|
||||||
const bnbLogo = require('../../../shared/images/BNB_logo.png');
|
|
||||||
const adaLogo = require('../../../shared/images/ADAlogo.png');
|
|
||||||
|
|
||||||
interface Token {
|
interface Token {
|
||||||
symbol: string;
|
symbol: string;
|
||||||
@@ -77,7 +79,7 @@ interface Token {
|
|||||||
balance: string;
|
balance: string;
|
||||||
value: string;
|
value: string;
|
||||||
change: string;
|
change: string;
|
||||||
logo: any; // Image source
|
logo: ImageSourcePropType;
|
||||||
assetId?: number;
|
assetId?: number;
|
||||||
isLive: boolean;
|
isLive: boolean;
|
||||||
}
|
}
|
||||||
@@ -95,28 +97,25 @@ interface Transaction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const WalletScreen: React.FC = () => {
|
const WalletScreen: React.FC = () => {
|
||||||
const navigation = useNavigation<any>();
|
const navigation = useNavigation<NavigationProp<ParamListBase>>();
|
||||||
const {
|
const {
|
||||||
api,
|
api,
|
||||||
isApiReady,
|
isApiReady,
|
||||||
accounts,
|
accounts,
|
||||||
selectedAccount,
|
selectedAccount,
|
||||||
setSelectedAccount,
|
setSelectedAccount,
|
||||||
connectWallet,
|
|
||||||
disconnectWallet,
|
|
||||||
createWallet,
|
createWallet,
|
||||||
deleteWallet,
|
deleteWallet,
|
||||||
getKeyPair,
|
getKeyPair,
|
||||||
currentNetwork,
|
currentNetwork,
|
||||||
switchNetwork,
|
switchNetwork,
|
||||||
error: pezkuwiError
|
|
||||||
} = usePezkuwi();
|
} = usePezkuwi();
|
||||||
|
|
||||||
const [selectedToken, setSelectedToken] = useState<Token | null>(null);
|
const [selectedToken, setSelectedToken] = useState<Token | null>(null);
|
||||||
const [sendModalVisible, setSendModalVisible] = useState(false);
|
const [sendModalVisible, setSendModalVisible] = useState(false);
|
||||||
const [receiveModalVisible, setReceiveModalVisible] = useState(false);
|
const [receiveModalVisible, setReceiveModalVisible] = useState(false);
|
||||||
const [createWalletModalVisible, setCreateWalletModalVisible] = useState(false);
|
const [_createWalletModalVisible, _setCreateWalletModalVisible] = useState(false);
|
||||||
const [importWalletModalVisible, setImportWalletModalVisible] = useState(false);
|
const [_importWalletModalVisible, _setImportWalletModalVisible] = useState(false);
|
||||||
const [backupModalVisible, setBackupModalVisible] = useState(false);
|
const [backupModalVisible, setBackupModalVisible] = useState(false);
|
||||||
const [networkSelectorVisible, setNetworkSelectorVisible] = useState(false);
|
const [networkSelectorVisible, setNetworkSelectorVisible] = useState(false);
|
||||||
const [walletSelectorVisible, setWalletSelectorVisible] = useState(false);
|
const [walletSelectorVisible, setWalletSelectorVisible] = useState(false);
|
||||||
@@ -128,16 +127,16 @@ const WalletScreen: React.FC = () => {
|
|||||||
const [hiddenTokens, setHiddenTokens] = useState<string[]>([]);
|
const [hiddenTokens, setHiddenTokens] = useState<string[]>([]);
|
||||||
const [recipientAddress, setRecipientAddress] = useState('');
|
const [recipientAddress, setRecipientAddress] = useState('');
|
||||||
const [sendAmount, setSendAmount] = useState('');
|
const [sendAmount, setSendAmount] = useState('');
|
||||||
const [walletName, setWalletName] = useState('');
|
const [walletName, _setWalletName] = useState('');
|
||||||
const [importMnemonic, setImportMnemonic] = useState('');
|
const [importMnemonic, setImportMnemonic] = useState('');
|
||||||
const [importWalletName, setImportWalletName] = useState('');
|
const [_importWalletName, _setImportWalletName] = useState('');
|
||||||
const [userMnemonic, setUserMnemonic] = useState<string>('');
|
const [userMnemonic, setUserMnemonic] = useState<string>('');
|
||||||
const [isSending, setIsSending] = useState(false);
|
const [isSending, setIsSending] = useState(false);
|
||||||
const [isLoadingBalances, setIsLoadingBalances] = useState(false);
|
const [isLoadingBalances, setIsLoadingBalances] = useState(false);
|
||||||
|
|
||||||
// Transaction History State
|
// Transaction History State (TODO: implement transaction history display)
|
||||||
const [transactions, setTransactions] = useState<Transaction[]>([]);
|
const [_transactions, _setTransactions] = useState<Transaction[]>([]);
|
||||||
const [isLoadingHistory, setIsLoadingHistory] = useState(false);
|
const [_isLoadingHistory, _setIsLoadingHistory] = useState(false);
|
||||||
|
|
||||||
const [balances, setBalances] = useState<{ [key: string]: string }>({
|
const [balances, setBalances] = useState<{ [key: string]: string }>({
|
||||||
HEZ: '0.00',
|
HEZ: '0.00',
|
||||||
@@ -221,43 +220,48 @@ const WalletScreen: React.FC = () => {
|
|||||||
setIsLoadingBalances(true);
|
setIsLoadingBalances(true);
|
||||||
try {
|
try {
|
||||||
// 1. Fetch Balances - decode address to raw bytes to avoid SS58 encoding issues
|
// 1. Fetch Balances - decode address to raw bytes to avoid SS58 encoding issues
|
||||||
let accountId: Uint8Array;
|
let accountId: Uint8Array | string;
|
||||||
try {
|
try {
|
||||||
accountId = decodeAddress(selectedAccount.address);
|
accountId = decodeAddress(selectedAccount.address);
|
||||||
} catch (e) {
|
} catch (_e) {
|
||||||
console.warn('[Wallet] Failed to decode address, using raw:', e);
|
if (__DEV__) console.warn('[Wallet] Failed to decode address, using raw:', _e);
|
||||||
accountId = selectedAccount.address as any;
|
accountId = selectedAccount.address;
|
||||||
}
|
}
|
||||||
|
|
||||||
const accountInfo = await api.query.system.account(accountId) as any;
|
const accountInfo = await api.query.system.account(accountId);
|
||||||
const hezBalance = (Number(accountInfo.data.free.toString()) / 1e12).toFixed(2);
|
const accountData = accountInfo.toJSON() as { data?: { free?: string | number } } | null;
|
||||||
|
const freeBalance = accountData?.data?.free ?? 0;
|
||||||
|
const hezBalance = (Number(freeBalance) / 1e12).toFixed(2);
|
||||||
|
|
||||||
let pezBalance = '0.00';
|
let pezBalance = '0.00';
|
||||||
try {
|
try {
|
||||||
if (api.query.assets?.account) {
|
if (api.query.assets?.account) {
|
||||||
const pezAsset = await api.query.assets.account(1, accountId) as any;
|
const pezAsset = await api.query.assets.account(1, accountId);
|
||||||
if (pezAsset.isSome) pezBalance = (Number(pezAsset.unwrap().balance.toString()) / 1e12).toFixed(2);
|
const pezData = pezAsset.toJSON() as { balance?: string | number } | null;
|
||||||
|
if (pezData?.balance) pezBalance = (Number(pezData.balance) / 1e12).toFixed(2);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (_e) {
|
||||||
console.warn('[Wallet] PEZ balance fetch failed:', e);
|
if (__DEV__) console.warn('[Wallet] PEZ balance fetch failed:', _e);
|
||||||
}
|
}
|
||||||
|
|
||||||
let usdtBalance = '0.00';
|
let usdtBalance = '0.00';
|
||||||
try {
|
try {
|
||||||
if (api.query.assets?.account) {
|
if (api.query.assets?.account) {
|
||||||
// Check ID 1000 first (as per constants), fallback to 2 just in case
|
// Check ID 1000 first (as per constants), fallback to 2 just in case
|
||||||
let usdtAsset = await api.query.assets.account(1000, accountId) as any;
|
let usdtAsset = await api.query.assets.account(1000, accountId);
|
||||||
if (usdtAsset.isNone) {
|
let usdtData = usdtAsset.toJSON() as { balance?: string | number } | null;
|
||||||
usdtAsset = await api.query.assets.account(2, accountId) as any;
|
if (!usdtData?.balance) {
|
||||||
|
usdtAsset = await api.query.assets.account(2, accountId);
|
||||||
|
usdtData = usdtAsset.toJSON() as { balance?: string | number } | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (usdtAsset.isSome) {
|
if (usdtData?.balance) {
|
||||||
// USDT uses 6 decimals usually, checking constants or assuming standard
|
// USDT uses 6 decimals usually, checking constants or assuming standard
|
||||||
usdtBalance = (Number(usdtAsset.unwrap().balance.toString()) / 1e6).toFixed(2);
|
usdtBalance = (Number(usdtData.balance) / 1e6).toFixed(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (_e) {
|
||||||
console.warn('[Wallet] USDT balance fetch failed:', e);
|
if (__DEV__) console.warn('[Wallet] USDT balance fetch failed:', _e);
|
||||||
}
|
}
|
||||||
|
|
||||||
setBalances({ HEZ: hezBalance, PEZ: pezBalance, USDT: usdtBalance });
|
setBalances({ HEZ: hezBalance, PEZ: pezBalance, USDT: usdtBalance });
|
||||||
@@ -270,7 +274,7 @@ const WalletScreen: React.FC = () => {
|
|||||||
setTransactions([]);
|
setTransactions([]);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Fetch error:', error);
|
if (__DEV__) console.error('Fetch error:', error);
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoadingBalances(false);
|
setIsLoadingBalances(false);
|
||||||
setIsLoadingHistory(false);
|
setIsLoadingHistory(false);
|
||||||
@@ -296,10 +300,10 @@ const WalletScreen: React.FC = () => {
|
|||||||
unsubscribe = await api.query.system.account(accountId, (accountInfo: any) => {
|
unsubscribe = await api.query.system.account(accountId, (accountInfo: any) => {
|
||||||
const hezBalance = (Number(accountInfo.data.free.toString()) / 1e12).toFixed(2);
|
const hezBalance = (Number(accountInfo.data.free.toString()) / 1e12).toFixed(2);
|
||||||
setBalances(prev => ({ ...prev, HEZ: hezBalance }));
|
setBalances(prev => ({ ...prev, HEZ: hezBalance }));
|
||||||
console.log('[Wallet] Balance updated via subscription:', hezBalance, 'HEZ');
|
if (__DEV__) console.warn('[Wallet] Balance updated via subscription:', hezBalance, 'HEZ');
|
||||||
}) as unknown as () => void;
|
}) as unknown as () => void;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('[Wallet] Subscription failed, falling back to polling:', e);
|
if (__DEV__) console.warn('[Wallet] Subscription failed, falling back to polling:', e);
|
||||||
// Fallback to polling if subscription fails
|
// Fallback to polling if subscription fails
|
||||||
fetchData();
|
fetchData();
|
||||||
}
|
}
|
||||||
@@ -326,9 +330,9 @@ const WalletScreen: React.FC = () => {
|
|||||||
try {
|
try {
|
||||||
const tokens = await fetchAllTokens(api, selectedAccount.address);
|
const tokens = await fetchAllTokens(api, selectedAccount.address);
|
||||||
setAllTokens(tokens);
|
setAllTokens(tokens);
|
||||||
console.log('[Wallet] Loaded', tokens.length, 'tokens from blockchain');
|
if (__DEV__) console.warn('[Wallet] Loaded', tokens.length, 'tokens from blockchain');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[Wallet] Failed to load tokens:', error);
|
if (__DEV__) console.error('[Wallet] Failed to load tokens:', error);
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoadingTokens(false);
|
setIsLoadingTokens(false);
|
||||||
}
|
}
|
||||||
@@ -415,7 +419,7 @@ const WalletScreen: React.FC = () => {
|
|||||||
setSavedAddresses(JSON.parse(stored));
|
setSavedAddresses(JSON.parse(stored));
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('[Wallet] Failed to load address book:', e);
|
if (__DEV__) console.warn('[Wallet] Failed to load address book:', e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
loadAddressBook();
|
loadAddressBook();
|
||||||
@@ -434,7 +438,7 @@ const WalletScreen: React.FC = () => {
|
|||||||
await AsyncStorage.setItem('@pezkuwi_address_book', JSON.stringify(updated));
|
await AsyncStorage.setItem('@pezkuwi_address_book', JSON.stringify(updated));
|
||||||
showAlert('Saved', `Address "${name}" saved to address book`);
|
showAlert('Saved', `Address "${name}" saved to address book`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('[Wallet] Failed to save address:', e);
|
if (__DEV__) console.warn('[Wallet] Failed to save address:', e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -445,7 +449,7 @@ const WalletScreen: React.FC = () => {
|
|||||||
setSavedAddresses(updated);
|
setSavedAddresses(updated);
|
||||||
await AsyncStorage.setItem('@pezkuwi_address_book', JSON.stringify(updated));
|
await AsyncStorage.setItem('@pezkuwi_address_book', JSON.stringify(updated));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('[Wallet] Failed to delete address:', e);
|
if (__DEV__) console.warn('[Wallet] Failed to delete address:', e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -502,7 +506,7 @@ const WalletScreen: React.FC = () => {
|
|||||||
const feeInHez = (Number(paymentInfo.partialFee.toString()) / 1e12).toFixed(6);
|
const feeInHez = (Number(paymentInfo.partialFee.toString()) / 1e12).toFixed(6);
|
||||||
setEstimatedFee(feeInHez);
|
setEstimatedFee(feeInHez);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('[Wallet] Fee estimation failed:', e);
|
if (__DEV__) console.warn('[Wallet] Fee estimation failed:', e);
|
||||||
setEstimatedFee('~0.001'); // Fallback estimate
|
setEstimatedFee('~0.001'); // Fallback estimate
|
||||||
} finally {
|
} finally {
|
||||||
setIsEstimatingFee(false);
|
setIsEstimatingFee(false);
|
||||||
@@ -568,7 +572,7 @@ const WalletScreen: React.FC = () => {
|
|||||||
|
|
||||||
await tx.signAndSend(keypair, ({ status, events }) => {
|
await tx.signAndSend(keypair, ({ status, events }) => {
|
||||||
if (status.isInBlock) {
|
if (status.isInBlock) {
|
||||||
console.log('[Wallet] Transaction in block:', status.asInBlock.toHex());
|
if (__DEV__) console.warn('[Wallet] Transaction in block:', status.asInBlock.toHex());
|
||||||
}
|
}
|
||||||
if (status.isFinalized) {
|
if (status.isFinalized) {
|
||||||
setSendModalVisible(false);
|
setSendModalVisible(false);
|
||||||
@@ -650,7 +654,7 @@ const WalletScreen: React.FC = () => {
|
|||||||
showAlert('No Backup', 'Mnemonic not found in secure storage. It may have been imported from another device.');
|
showAlert('No Backup', 'Mnemonic not found in secure storage. It may have been imported from another device.');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error retrieving mnemonic:', error);
|
if (__DEV__) console.error('Error retrieving mnemonic:', error);
|
||||||
showAlert('Error', 'Failed to retrieve mnemonic from secure storage.');
|
showAlert('Error', 'Failed to retrieve mnemonic from secure storage.');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -662,8 +666,8 @@ const WalletScreen: React.FC = () => {
|
|||||||
await Share.share({
|
await Share.share({
|
||||||
message: `My Pezkuwichain Address:\n${selectedAccount.address}`,
|
message: `My Pezkuwichain Address:\n${selectedAccount.address}`,
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (_e) {
|
||||||
console.error(e);
|
if (__DEV__) console.error(_e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user