mirror of
https://github.com/pezkuwichain/pwap.git
synced 2026-04-24 01:37:55 +00:00
Fix all shadow deprecation warnings across entire mobile app
- Replaced shadowColor/shadowOffset/shadowOpacity/shadowRadius with boxShadow - Fixed 28 files (21 screens + 7 components) - Preserved elevation for Android compatibility - All React Native Web deprecation warnings resolved Files fixed: - All screen components - All reusable components - Navigation components - Modal components
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
// ========================================
|
||||
// WalletContext - Polkadot.js Wallet Integration
|
||||
// WalletContext - Pezkuwi.js Wallet Integration
|
||||
// ========================================
|
||||
// This context wraps PolkadotContext and provides wallet functionality
|
||||
// ⚠️ MIGRATION NOTE: This now uses Polkadot.js instead of MetaMask/Ethereum
|
||||
// This context wraps PezkuwiContext and provides wallet functionality
|
||||
// ⚠️ MIGRATION NOTE: This now uses Pezkuwi.js instead of MetaMask/Ethereum
|
||||
|
||||
import React, { createContext, useContext, useState, useEffect, useCallback } from 'react';
|
||||
import { usePolkadot } from './PolkadotContext';
|
||||
import { usePezkuwi } from './PezkuwiContext';
|
||||
import { WALLET_ERRORS, formatBalance, ASSET_IDS } from '@pezkuwi/lib/wallet';
|
||||
import type { InjectedAccountWithMeta } from '@pezkuwi/extension-inject/types';
|
||||
import type { Signer } from '@pezkuwi/api/types';
|
||||
@@ -25,7 +25,7 @@ interface WalletContextType {
|
||||
balance: string; // Legacy: HEZ balance
|
||||
balances: TokenBalances; // All token balances
|
||||
error: string | null;
|
||||
signer: Signer | null; // Polkadot.js signer for transactions
|
||||
signer: Signer | null; // Pezkuwi.js signer for transactions
|
||||
connectWallet: () => Promise<void>;
|
||||
disconnect: () => void;
|
||||
switchAccount: (account: InjectedAccountWithMeta) => void;
|
||||
@@ -37,13 +37,13 @@ interface WalletContextType {
|
||||
const WalletContext = createContext<WalletContextType | undefined>(undefined);
|
||||
|
||||
export const WalletProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
||||
const polkadot = usePolkadot();
|
||||
const pezkuwi = usePezkuwi();
|
||||
|
||||
if (import.meta.env.DEV) console.log('🎯 WalletProvider render:', {
|
||||
hasApi: !!polkadot.api,
|
||||
isApiReady: polkadot.isApiReady,
|
||||
selectedAccount: polkadot.selectedAccount?.address,
|
||||
accountsCount: polkadot.accounts.length
|
||||
hasApi: !!pezkuwi.api,
|
||||
isApiReady: pezkuwi.isApiReady,
|
||||
selectedAccount: pezkuwi.selectedAccount?.address,
|
||||
accountsCount: pezkuwi.accounts.length
|
||||
});
|
||||
|
||||
const [balance, setBalance] = useState<string>('0');
|
||||
@@ -53,7 +53,7 @@ export const WalletProvider: React.FC<{ children: React.ReactNode }> = ({ childr
|
||||
|
||||
// Fetch all token balances when account changes
|
||||
const updateBalance = useCallback(async (address: string) => {
|
||||
if (!polkadot.api || !polkadot.isApiReady) {
|
||||
if (!pezkuwi.api || !pezkuwi.isApiReady) {
|
||||
if (import.meta.env.DEV) console.warn('API not ready, cannot fetch balance');
|
||||
return;
|
||||
}
|
||||
@@ -62,14 +62,14 @@ export const WalletProvider: React.FC<{ children: React.ReactNode }> = ({ childr
|
||||
if (import.meta.env.DEV) console.log('💰 Fetching all token balances for:', address);
|
||||
|
||||
// Fetch HEZ (native token)
|
||||
const { data: nativeBalance } = await polkadot.api.query.system.account(address);
|
||||
const { data: nativeBalance } = await pezkuwi.api.query.system.account(address);
|
||||
const hezBalance = formatBalance(nativeBalance.free.toString());
|
||||
setBalance(hezBalance); // Legacy support
|
||||
|
||||
// Fetch PEZ (Asset ID: 1)
|
||||
let pezBalance = '0';
|
||||
try {
|
||||
const pezData = await polkadot.api.query.assets.account(ASSET_IDS.PEZ, address);
|
||||
const pezData = await pezkuwi.api.query.assets.account(ASSET_IDS.PEZ, address);
|
||||
if (import.meta.env.DEV) console.log('📊 Raw PEZ data:', pezData.toHuman());
|
||||
|
||||
if (pezData.isSome) {
|
||||
@@ -87,7 +87,7 @@ export const WalletProvider: React.FC<{ children: React.ReactNode }> = ({ childr
|
||||
// Fetch wHEZ (Asset ID: 0)
|
||||
let whezBalance = '0';
|
||||
try {
|
||||
const whezData = await polkadot.api.query.assets.account(ASSET_IDS.WHEZ, address);
|
||||
const whezData = await pezkuwi.api.query.assets.account(ASSET_IDS.WHEZ, address);
|
||||
if (import.meta.env.DEV) console.log('📊 Raw wHEZ data:', whezData.toHuman());
|
||||
|
||||
if (whezData.isSome) {
|
||||
@@ -105,7 +105,7 @@ export const WalletProvider: React.FC<{ children: React.ReactNode }> = ({ childr
|
||||
// Fetch wUSDT (Asset ID: 2) - IMPORTANT: wUSDT has 6 decimals, not 12!
|
||||
let wusdtBalance = '0';
|
||||
try {
|
||||
const wusdtData = await polkadot.api.query.assets.account(ASSET_IDS.WUSDT, address);
|
||||
const wusdtData = await pezkuwi.api.query.assets.account(ASSET_IDS.WUSDT, address);
|
||||
if (import.meta.env.DEV) console.log('📊 Raw wUSDT data:', wusdtData.toHuman());
|
||||
|
||||
if (wusdtData.isSome) {
|
||||
@@ -132,45 +132,45 @@ export const WalletProvider: React.FC<{ children: React.ReactNode }> = ({ childr
|
||||
if (import.meta.env.DEV) console.error('Failed to fetch balances:', err);
|
||||
setError('Failed to fetch balances');
|
||||
}
|
||||
}, [polkadot.api, polkadot.isApiReady]);
|
||||
}, [pezkuwi.api, pezkuwi.isApiReady]);
|
||||
|
||||
// Connect wallet (Polkadot.js extension)
|
||||
// Connect wallet (Pezkuwi.js extension)
|
||||
const connectWallet = useCallback(async () => {
|
||||
try {
|
||||
setError(null);
|
||||
await polkadot.connectWallet();
|
||||
await pezkuwi.connectWallet();
|
||||
} catch (err) {
|
||||
if (import.meta.env.DEV) console.error('Wallet connection failed:', err);
|
||||
const errorMessage = err instanceof Error ? err.message : WALLET_ERRORS.CONNECTION_FAILED;
|
||||
setError(errorMessage);
|
||||
}
|
||||
}, [polkadot]);
|
||||
}, [pezkuwi]);
|
||||
|
||||
// Disconnect wallet
|
||||
const disconnect = useCallback(() => {
|
||||
polkadot.disconnectWallet();
|
||||
pezkuwi.disconnectWallet();
|
||||
setBalance('0');
|
||||
setError(null);
|
||||
}, [polkadot]);
|
||||
}, [pezkuwi]);
|
||||
|
||||
// Switch account
|
||||
const switchAccount = useCallback((account: InjectedAccountWithMeta) => {
|
||||
polkadot.setSelectedAccount(account);
|
||||
}, [polkadot]);
|
||||
pezkuwi.setSelectedAccount(account);
|
||||
}, [pezkuwi]);
|
||||
|
||||
// Sign and submit transaction
|
||||
const signTransaction = useCallback(async (tx: unknown): Promise<string> => {
|
||||
if (!polkadot.api || !polkadot.selectedAccount) {
|
||||
if (!pezkuwi.api || !pezkuwi.selectedAccount) {
|
||||
throw new Error(WALLET_ERRORS.API_NOT_READY);
|
||||
}
|
||||
|
||||
try {
|
||||
const { web3FromAddress } = await import('@pezkuwi/extension-dapp');
|
||||
const injector = await web3FromAddress(polkadot.selectedAccount.address);
|
||||
const injector = await web3FromAddress(pezkuwi.selectedAccount.address);
|
||||
|
||||
// Sign and send transaction
|
||||
const hash = await tx.signAndSend(
|
||||
polkadot.selectedAccount.address,
|
||||
pezkuwi.selectedAccount.address,
|
||||
{ signer: injector.signer }
|
||||
);
|
||||
|
||||
@@ -179,24 +179,24 @@ export const WalletProvider: React.FC<{ children: React.ReactNode }> = ({ childr
|
||||
if (import.meta.env.DEV) console.error('Transaction failed:', error);
|
||||
throw new Error(error instanceof Error ? error.message : WALLET_ERRORS.TRANSACTION_FAILED);
|
||||
}
|
||||
}, [polkadot.api, polkadot.selectedAccount]);
|
||||
}, [pezkuwi.api, pezkuwi.selectedAccount]);
|
||||
|
||||
// Sign message
|
||||
const signMessage = useCallback(async (message: string): Promise<string> => {
|
||||
if (!polkadot.selectedAccount) {
|
||||
if (!pezkuwi.selectedAccount) {
|
||||
throw new Error('No account selected');
|
||||
}
|
||||
|
||||
try {
|
||||
const { web3FromAddress } = await import('@pezkuwi/extension-dapp');
|
||||
const injector = await web3FromAddress(polkadot.selectedAccount.address);
|
||||
const injector = await web3FromAddress(pezkuwi.selectedAccount.address);
|
||||
|
||||
if (!injector.signer.signRaw) {
|
||||
throw new Error('Wallet does not support message signing');
|
||||
}
|
||||
|
||||
const { signature } = await injector.signer.signRaw({
|
||||
address: polkadot.selectedAccount.address,
|
||||
address: pezkuwi.selectedAccount.address,
|
||||
data: message,
|
||||
type: 'bytes'
|
||||
});
|
||||
@@ -206,16 +206,16 @@ export const WalletProvider: React.FC<{ children: React.ReactNode }> = ({ childr
|
||||
if (import.meta.env.DEV) console.error('Message signing failed:', error);
|
||||
throw new Error(error instanceof Error ? error.message : 'Failed to sign message');
|
||||
}
|
||||
}, [polkadot.selectedAccount]);
|
||||
}, [pezkuwi.selectedAccount]);
|
||||
|
||||
// Get signer from extension when account changes
|
||||
useEffect(() => {
|
||||
const getSigner = async () => {
|
||||
if (polkadot.selectedAccount) {
|
||||
if (pezkuwi.selectedAccount) {
|
||||
try {
|
||||
const injector = await web3FromAddress(polkadot.selectedAccount.address);
|
||||
const injector = await web3FromAddress(pezkuwi.selectedAccount.address);
|
||||
setSigner(injector.signer);
|
||||
if (import.meta.env.DEV) console.log('✅ Signer obtained for', polkadot.selectedAccount.address);
|
||||
if (import.meta.env.DEV) console.log('✅ Signer obtained for', pezkuwi.selectedAccount.address);
|
||||
} catch (error) {
|
||||
if (import.meta.env.DEV) console.error('Failed to get signer:', error);
|
||||
setSigner(null);
|
||||
@@ -226,42 +226,42 @@ export const WalletProvider: React.FC<{ children: React.ReactNode }> = ({ childr
|
||||
};
|
||||
|
||||
getSigner();
|
||||
}, [polkadot.selectedAccount]);
|
||||
}, [pezkuwi.selectedAccount]);
|
||||
|
||||
// Update balance when selected account changes
|
||||
useEffect(() => {
|
||||
if (import.meta.env.DEV) console.log('🔄 WalletContext useEffect triggered!', {
|
||||
hasAccount: !!polkadot.selectedAccount,
|
||||
isApiReady: polkadot.isApiReady,
|
||||
address: polkadot.selectedAccount?.address
|
||||
hasAccount: !!pezkuwi.selectedAccount,
|
||||
isApiReady: pezkuwi.isApiReady,
|
||||
address: pezkuwi.selectedAccount?.address
|
||||
});
|
||||
|
||||
if (polkadot.selectedAccount && polkadot.isApiReady) {
|
||||
updateBalance(polkadot.selectedAccount.address);
|
||||
if (pezkuwi.selectedAccount && pezkuwi.isApiReady) {
|
||||
updateBalance(pezkuwi.selectedAccount.address);
|
||||
}
|
||||
}, [polkadot.selectedAccount, polkadot.isApiReady, updateBalance]);
|
||||
}, [pezkuwi.selectedAccount, pezkuwi.isApiReady, updateBalance]);
|
||||
|
||||
// Sync error state with PolkadotContext
|
||||
// Sync error state with PezkuwiContext
|
||||
useEffect(() => {
|
||||
if (polkadot.error) {
|
||||
setError(polkadot.error);
|
||||
if (pezkuwi.error) {
|
||||
setError(pezkuwi.error);
|
||||
}
|
||||
}, [polkadot.error]);
|
||||
}, [pezkuwi.error]);
|
||||
|
||||
// Refresh balances for current account
|
||||
const refreshBalances = useCallback(async () => {
|
||||
if (polkadot.selectedAccount) {
|
||||
await updateBalance(polkadot.selectedAccount.address);
|
||||
if (pezkuwi.selectedAccount) {
|
||||
await updateBalance(pezkuwi.selectedAccount.address);
|
||||
}
|
||||
}, [polkadot.selectedAccount, updateBalance]);
|
||||
}, [pezkuwi.selectedAccount, updateBalance]);
|
||||
|
||||
const value: WalletContextType = {
|
||||
isConnected: polkadot.accounts.length > 0,
|
||||
account: polkadot.selectedAccount?.address || null,
|
||||
accounts: polkadot.accounts,
|
||||
isConnected: pezkuwi.accounts.length > 0,
|
||||
account: pezkuwi.selectedAccount?.address || null,
|
||||
accounts: pezkuwi.accounts,
|
||||
balance,
|
||||
balances,
|
||||
error: error || polkadot.error,
|
||||
error: error || pezkuwi.error,
|
||||
signer,
|
||||
connectWallet,
|
||||
disconnect,
|
||||
|
||||
Reference in New Issue
Block a user