Hey is a decentralized and permissionless social media app built with Lens Protocol 🌿

refactor: enhance wallet client handling in Trade component for improved error management

yoginth.com d16dc17a e8d1b9db

verified
+11 -6
+11 -6
apps/web/src/components/Account/CreatorCoin/Trade.tsx
··· 30 30 31 31 const Trade = ({ coin, onClose }: TradeModalProps) => { 32 32 const { address } = useAccount(); 33 - const { data: walletClient } = useWalletClient(); 33 + const { data: walletClient } = useWalletClient({ chainId: base.id }); 34 34 const publicClient = useMemo( 35 35 () => createPublicClient({ chain: base, transport: http() }), 36 36 [] ··· 107 107 }; 108 108 109 109 const handleSubmit = async () => { 110 - console.log(walletClient); 111 - if (!walletClient || !publicClient || !address) { 110 + if (!publicClient || !address) { 112 111 return toast.error("Connect a wallet to trade"); 113 112 } 114 113 115 114 const params = makeParams(); 116 115 if (!params) return; 116 + 117 117 try { 118 118 setLoading(true); 119 119 await handleWrongNetwork(); 120 + 121 + if (!walletClient) { 122 + setLoading(false); 123 + return toast.error("Connect a wallet to trade"); 124 + } 125 + 120 126 const receipt = await tradeCoin({ 121 127 account: walletClient.account, 122 128 publicClient, ··· 142 148 setEstimatedOut(""); 143 149 return; 144 150 } 151 + 145 152 const params: TradeParameters = 146 153 mode === "buy" 147 154 ? { ··· 158 165 sender, 159 166 slippage: 0.01 160 167 }; 168 + 161 169 try { 162 170 const q = await createTradeCall(params); 163 171 if (!cancelled) { ··· 193 201 { name: "Sell", type: "sell" } 194 202 ]} 195 203 /> 196 - 197 204 <div className="relative mb-2"> 198 205 <Input 199 206 inputMode="decimal" ··· 231 238 </div> 232 239 <div>{balanceLabel}</div> 233 240 </div> 234 - 235 241 <div className="mb-3 grid grid-cols-4 gap-2"> 236 242 {[25, 50, 75].map((p) => ( 237 243 <Button key={p} onClick={() => setPercentAmount(p)} outline> ··· 242 248 Max 243 249 </Button> 244 250 </div> 245 - 246 251 <Button 247 252 className="mt-4 w-full" 248 253 disabled={!amount || !address}