Skip to content

Commit

Permalink
added comments and removed unused imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen-Gordon committed Mar 21, 2024
1 parent d1d08b1 commit b54faa7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
11 changes: 8 additions & 3 deletions src/app/@auth/(.)confirm/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ import { useSearchParams } from 'next/navigation';
import { Avatar } from '@/app/components/ui/avatar';
// link
import Link from 'next/link';

// hooks
import useSendUsdc from '@/app/hooks/useSendUsdc';

// components
import Success from '@/app/components/Success/Success';
import { useEffect } from 'react';
// redux
import { useDispatch } from 'react-redux';
import { setPendingTxSlice } from '@/GlobalRedux/Features/pendingTx/pendingTxSlice';

interface ConfirmProps {
showConfirm: boolean;
}
Expand All @@ -43,6 +47,7 @@ export default function Page({ showConfirm }: ConfirmProps) {
const searchParams = useSearchParams();
let payee = searchParams.get('payee');
let amount = searchParams.get('amount');

const { sendUsdc, transactionStatus, loading, transactionHash } =
useSendUsdc();

Expand All @@ -52,8 +57,8 @@ export default function Page({ showConfirm }: ConfirmProps) {
if (!payee || !amount) return;
console.log('calling hook');
sendUsdc(amount, payee);

};

return (
<>
<DrawerHeader>
Expand Down
13 changes: 5 additions & 8 deletions src/app/hooks/useSendUsdc.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { useState, useEffect } from 'react';
// react
import { useState} from 'react';
// viem
import { encodeFunctionData, parseUnits, erc20Abi } from 'viem';
// privy
import { usePrivySmartAccount } from '@zerodev/privy';
import { useDispatch } from 'react-redux';
import { setPendingTxSlice } from '@/GlobalRedux/Features/pendingTx/pendingTxSlice';

const useSendUsdc = () => {
const { zeroDevReady, user, sendTransaction } = usePrivySmartAccount();
const { zeroDevReady, sendTransaction } = usePrivySmartAccount();
const [transactionStatus, setTransactionStatus] = useState<boolean>(false);
const [loading, setLoading] = useState<boolean>(false);
const [transactionHash, setTransactionHash] = useState<string>('');
Expand All @@ -23,7 +24,6 @@ const useSendUsdc = () => {
});

setLoading(true);
console.log('loading is true');
const txnHash = await sendTransaction({
to: '0x94a9D9AC8a22534E3FaCa9F4e7F2E2cf85d5E4C8', // USDC contract address
value: BigInt(0),
Expand All @@ -33,10 +33,7 @@ const useSendUsdc = () => {
if (txnHash) {
setLoading(false);
setTransactionStatus(true);

setTransactionHash(txnHash);

console.log('Transaction Hash:', txnHash);
}
} catch (error) {
console.log(error);
Expand Down

0 comments on commit b54faa7

Please sign in to comment.