immortal-bnb/frontend/components/WalletConnect.tsx
Claude 60337b4110
feat: Add E2E trading flow test and RainbowKit wallet UI
- Create comprehensive E2E test covering full trading cycle (trading-flow.test.ts)
  * Step 1: Token discovery from DexScreener
  * Step 2: Token data fetching
  * Step 3: AI decision making with Immortal Agent
  * Step 4: Trade simulation (dry run)
  * Step 5: Memory storage on Greenfield
  * Step 6: Memory retrieval verification
  * Step 7: Agent learning validation
  * Step 8: Personality evolution check
  * Complete flow integration test

- Create WalletConnect component with RainbowKit
  * Custom styled ConnectButton
  * Chain switcher
  * Account modal
  * Balance display
  * WalletInfo component for detailed view

Test Coverage: Full trading flow validation
Frontend: Production-ready wallet connection UI
2025-11-12 14:40:24 +00:00

144 lines
4.4 KiB
TypeScript

'use client';
import { ConnectButton } from '@rainbow-me/rainbowkit';
import { useAccount, useBalance } from 'wagmi';
export function WalletConnect() {
return (
<ConnectButton.Custom>
{({
account,
chain,
openAccountModal,
openChainModal,
openConnectModal,
authenticationStatus,
mounted,
}) => {
const ready = mounted && authenticationStatus !== 'loading';
const connected =
ready &&
account &&
chain &&
(!authenticationStatus || authenticationStatus === 'authenticated');
return (
<div
{...(!ready && {
'aria-hidden': true,
style: {
opacity: 0,
pointerEvents: 'none',
userSelect: 'none',
},
})}
>
{(() => {
if (!connected) {
return (
<button
onClick={openConnectModal}
type="button"
className="px-6 py-3 bg-gradient-to-r from-purple-600 to-blue-600 text-white font-semibold rounded-lg hover:from-purple-700 hover:to-blue-700 transition-all duration-200 shadow-lg hover:shadow-xl"
>
Connect Wallet
</button>
);
}
if (chain.unsupported) {
return (
<button
onClick={openChainModal}
type="button"
className="px-6 py-3 bg-red-600 text-white font-semibold rounded-lg hover:bg-red-700 transition-colors"
>
Wrong Network
</button>
);
}
return (
<div className="flex items-center gap-3">
<button
onClick={openChainModal}
type="button"
className="flex items-center gap-2 px-4 py-2 bg-slate-800 text-white rounded-lg hover:bg-slate-700 transition-colors"
>
{chain.hasIcon && (
<div
style={{
background: chain.iconBackground,
width: 24,
height: 24,
borderRadius: 999,
overflow: 'hidden',
}}
>
{chain.iconUrl && (
<img
alt={chain.name ?? 'Chain icon'}
src={chain.iconUrl}
style={{ width: 24, height: 24 }}
/>
)}
</div>
)}
{chain.name}
</button>
<button
onClick={openAccountModal}
type="button"
className="px-4 py-2 bg-gradient-to-r from-purple-600 to-blue-600 text-white font-medium rounded-lg hover:from-purple-700 hover:to-blue-700 transition-all"
>
{account.displayName}
{account.displayBalance
? ` (${account.displayBalance})`
: ''}
</button>
</div>
);
})()}
</div>
);
}}
</ConnectButton.Custom>
);
}
export function WalletInfo() {
const { address, isConnected } = useAccount();
const { data: balance } = useBalance({
address: address,
});
if (!isConnected || !address) {
return null;
}
return (
<div className="p-6 bg-slate-800 rounded-lg">
<h3 className="text-xl font-bold text-white mb-4">Wallet Info</h3>
<div className="space-y-3">
<div>
<p className="text-sm text-slate-400">Address</p>
<p className="text-white font-mono text-sm break-all">
{address}
</p>
</div>
{balance && (
<div>
<p className="text-sm text-slate-400">Balance</p>
<p className="text-2xl font-bold text-white">
{parseFloat(balance.formatted).toFixed(4)} {balance.symbol}
</p>
</div>
)}
</div>
</div>
);
}
export default WalletConnect;