Skip to content

Commit

Permalink
reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
brucedonovan committed Sep 27, 2023
1 parent aa48e22 commit 230d31b
Show file tree
Hide file tree
Showing 12 changed files with 1,480 additions and 1,527 deletions.
2,930 changes: 1,443 additions & 1,487 deletions src/abi/SeaportAbi.ts

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions src/components/cactiComponents/ActionResponse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import { useEffect, useMemo, useState } from 'react';
import Skeleton from 'react-loading-skeleton';
import { CheckCircleIcon, ExclamationTriangleIcon } from '@heroicons/react/24/outline';
import { ConnectButton } from '@rainbow-me/rainbowkit';

import tw from 'tailwind-styled-components';
import { TransactionReceipt, TransactionRequestBase, formatUnits, zeroAddress } from 'viem';
import { useAccount, useNetwork, useSwitchNetwork, UsePrepareContractWriteConfig, } from 'wagmi';

import { UsePrepareContractWriteConfig, useAccount, useNetwork, useSwitchNetwork } from 'wagmi';
import useToken from '@/hooks/useToken';
import { cleanValue } from '@/utils';
import { ActionStepper } from './ActionStepper';
Expand Down Expand Up @@ -143,8 +141,7 @@ export const ActionResponse = ({

// explicitly showing approvalParams === undefined for clarity - as oppposed to !approvalParams
if (_approvalParams === undefined) return setHasEnoughBalance(true);
if (BigInt(sendParams?.value || '0') > BigInt(ethBal || '0'))
return setHasEnoughBalance(false);
if (BigInt(sendParams?.value || '0') > BigInt(ethBal || '0')) return setHasEnoughBalance(false);

// check approval token balance
if (balance && _approvalParams?.approvalAmount)
Expand Down
8 changes: 4 additions & 4 deletions src/components/cactiComponents/hooks/useApproval.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useMemo } from 'react';
import { useQuery } from 'react-query';
import { zeroAddress } from 'viem';
import { erc20ABI, useContractWrite, usePrepareContractWrite, useWaitForTransaction } from 'wagmi';
import { prepareWriteContract } from 'wagmi/actions';
import useChainId from '@/hooks/useChainId';
import useToken from '@/hooks/useToken';
import { cleanValue } from '@/utils';
import useAllowance from './useAllowance';
import { zeroAddress } from 'viem';

export type ApprovalBasicParams = {
approvalAmount: bigint;
Expand All @@ -21,7 +21,7 @@ const validateAddress = (addr: `0x${string}`): `0x${string}` | undefined =>
const useApproval = (params: ApprovalBasicParams) => {
const chainId = useChainId();
const { approvalAmount, tokenAddress: _tokenAddress, spender: _spender } = params;

const tokenAddress = validateAddress(_tokenAddress);
const spender = validateAddress(_spender);

Expand All @@ -41,7 +41,7 @@ const useApproval = (params: ApprovalBasicParams) => {
// Prepare the approval transaction - doesn't run if address or spender is undefined
const { data: config, isError: isPrepareError } = useQuery({
queryKey: ['prepareApprove', tokenAddress, spender, chainId],
queryFn: async () => {
queryFn: async () => {
// case: invalid spender
if (!spender) {
console.warn(`Spender not found for approval`);
Expand All @@ -53,7 +53,7 @@ const useApproval = (params: ApprovalBasicParams) => {
return;
}

const {request} = await prepareWriteContract({
const { request } = await prepareWriteContract({
address: tokenAddress,
abi: erc20ABI,
functionName: 'approve',
Expand Down
4 changes: 2 additions & 2 deletions src/components/cactiComponents/hooks/useBalance.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useEffect, useState } from 'react';
import { useQuery } from 'react-query';
import { zeroAddress } from 'viem';
import { useAccount } from 'wagmi';
import { fetchBalance, readContract } from 'wagmi/actions';
import erc1155ABI from '@/abi/erc1155ABI';
import useChainId from '@/hooks/useChainId';
import { zeroAddress } from 'viem';

/**
* @description gets the balance of a an account for a token address, or if no address is specified, get's eth balance
Expand Down Expand Up @@ -42,7 +42,7 @@ const useBalance = (
chainId,
abi: erc1155ABI,
functionName: 'balanceOf',
args: [account, BigInt(erc1155TokenId) ],
args: [account, BigInt(erc1155TokenId)],
});
return erc1155Bal;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useMemo } from 'react';
import { Address, UsePrepareContractWriteConfig } from 'wagmi';
import rETHAbi from '@/abi/rETH';
import {
ActionResponse,
HeaderResponse,
Expand All @@ -9,7 +10,6 @@ import {
import { ResponseRow } from '@/components/cactiComponents/helpers/layout';
import useToken from '@/hooks/useToken';
import { cleanValue } from '@/utils';
import rETHAbi from '@/abi/rETH';

interface RethProps {
inputString: string;
Expand Down
6 changes: 3 additions & 3 deletions src/components/current/widgets/transfer/Transfer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useMemo } from 'react';
import { parseUnits} from 'viem';
import { parseUnits } from 'viem';
import { erc20ABI, useAccount, useEnsAddress } from 'wagmi';
import { ActionResponse, HeaderResponse } from '@/components/cactiComponents';
import useToken from '@/hooks/useToken';
Expand Down Expand Up @@ -47,8 +47,8 @@ const Transfer = ({ tokenSymbol, amtString, receiver }: TransferWidgetProps) =>
/>
<ActionResponse
label={`Transfer ${amtString || ''} ${tokenSymbol}`}
txParams={ isETH ? undefined : tx}
approvalParams={undefined} // approval shouldn't be required?
txParams={isETH ? undefined : tx}
approvalParams={undefined} // approval shouldn't be required?
sendParams={isETH ? { to: receiverAddress, value: amount, from: account! } : undefined}
/>
</ConnectFirst>
Expand Down
2 changes: 1 addition & 1 deletion src/components/current/widgets/uniswap/Uniswap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const Uniswap = ({
const { data: tokenOutChecked } = useToken(tokenOutIsETH ? 'WETH' : tokenOutSymbol);
const input = useInput(inputAmount, tokenInChecked?.symbol!);

const slippage_ = +slippage || 0.5; // in percentage terms
const slippage_ = +slippage || 0.5; // in percentage terms
const getSlippageAdjustedAmount = (amount: bigint) =>
(amount * BigInt(10000 - slippage_ * 100)) / BigInt(10000);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { useEffect, useMemo, useState } from 'react';
import { Erc20Bridger, getL2Network } from '@arbitrum/sdk';
import { BigNumber, UnsignedTransaction } from 'ethers';
import { Interface } from 'ethers/lib/utils.js';
import { erc20ABI, useAccount, usePrepareContractWrite} from 'wagmi';
import { erc20ABI, useAccount, usePrepareContractWrite } from 'wagmi';
import { ActionResponse, HeaderResponse } from '@/components/cactiComponents';
import { ApprovalBasicParams } from '@/components/cactiComponents/hooks/useApproval';
import useInput from '@/hooks/useInput';
import useToken from '@/hooks/useToken';
import Inbox from './abi/Inbox';
import { unsignedTxToTxRequestBase, useEthersProvider } from '@/utils/ethersAdapter';
import Inbox from './abi/Inbox';

interface ArbitrumDepositETHProps {
tokenSymbol: string;
Expand Down Expand Up @@ -112,7 +112,7 @@ const ArbitrumDeposit = ({ tokenSymbol, amtString }: ArbitrumDepositETHProps) =>
label={`Deposit ${amount?.formatted || ''} ${tokenSymbol} to Arbitrum`}
txParams={undefined}
approvalParams={erc20ApprovalParams}
sendParams={ unsignedTxToTxRequestBase(sendParams as UnsignedTransaction, account!) }
sendParams={unsignedTxToTxRequestBase(sendParams as UnsignedTransaction, account!)}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { ActionResponse, HeaderResponse } from '@/components/cactiComponents';
import { ApprovalBasicParams } from '@/components/cactiComponents/hooks/useApproval';
import useInput from '@/hooks/useInput';
import useToken from '@/hooks/useToken';
import { unsignedTxToTxRequestBase, useEthersProvider } from '@/utils/ethersAdapter';
import { L2_CHAIN_ID } from './ArbitrumDeposit';
import ArbSys from './abi/ArbSys';
import { unsignedTxToTxRequestBase, useEthersProvider } from '@/utils/ethersAdapter';

interface ArbitrumWithdrawProps {
tokenSymbol: string;
Expand Down Expand Up @@ -80,7 +80,7 @@ const ArbitrumWithdraw = ({ tokenSymbol, amtString }: ArbitrumWithdrawProps) =>
label={`Withdraw ${amount?.formatted} ${tokenSymbol} from Arbitrum`}
txParams={undefined}
approvalParams={undefined}
sendParams={ unsignedTxToTxRequestBase(sendParams as UnsignedTransaction, account!) }
sendParams={unsignedTxToTxRequestBase(sendParams as UnsignedTransaction, account!)}
/>
</>
);
Expand Down
23 changes: 10 additions & 13 deletions src/contexts/ConnectionWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ import {
lightTheme,
} from '@rainbow-me/rainbowkit';
import axios from 'axios';

import { Chain, WagmiConfig, configureChains, createConfig, useEnsAvatar } from 'wagmi';
import { arbitrum, goerli, zkSyncTestnet } from 'wagmi/chains';
import { publicProvider } from 'wagmi/providers/public';
import useCachedState from '@/hooks/useCachedState';
import { getBackendApiUrl } from '@/utils/backend';
import { GetSiweMessageOptions, RainbowKitSiweNextAuthProvider } from '@/utils/rainbowSIWEmod';
import SettingsContext from './SettingsContext';
import { publicProvider } from 'wagmi/providers/public'

const ConnectionWrapper = ({ children, useSiwe = true }: any) => {

/* Use a fork url cached in the browser localStorage, else use the .env value */
const [forkUrl] = useCachedState(
'forkUrl',
Expand All @@ -47,17 +45,16 @@ const ConnectionWrapper = ({ children, useSiwe = true }: any) => {
},
} as Chain;

const arbitrumFork = {
...arbitrum,
name: 'Arbitrum One Fork',
rpcUrls: {
public: { http: [arbitrum.rpcUrls.public.http[0]] },
default: { http: [process.env.ARBITRUM_FORK_URL] },
},
} as Chain;

const arbitrumFork = {
...arbitrum,
name: 'Arbitrum One Fork',
rpcUrls: {
public: { http: [arbitrum.rpcUrls.public.http[0]] },
default: { http: [process.env.ARBITRUM_FORK_URL] },
},
} as Chain;

const { chains, publicClient, webSocketPublicClient } = configureChains(
const { chains, publicClient, webSocketPublicClient } = configureChains(
[mainnetFork, goerli, zkSyncTestnet, arbitrumFork],
[publicProvider()]
);
Expand Down
11 changes: 7 additions & 4 deletions src/utils/ethersAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as React from 'react';
import { type WalletClient } from '@wagmi/core';
import { UnsignedTransaction, providers } from 'ethers';
import { type PublicClient, usePublicClient, useWalletClient } from 'wagmi';
import { TransactionRequestBase } from 'viem';
import { type PublicClient, usePublicClient, useWalletClient } from 'wagmi';

export function publicClientToProvider(publicClient: PublicClient) {
const { chain, transport } = publicClient;
Expand Down Expand Up @@ -41,13 +41,16 @@ export function useEthersSigner({ chainId }: { chainId?: number } = {}) {
);
}

export const unsignedTxToTxRequestBase = (unsignedTx: UnsignedTransaction, from:`0x${string}` ): TransactionRequestBase => {
export const unsignedTxToTxRequestBase = (
unsignedTx: UnsignedTransaction,
from: `0x${string}`
): TransactionRequestBase => {
return {
data: unsignedTx.data as `0x${string}`,
from,
gas: BigInt(unsignedTx.gasLimit!.toString()),
nonce: unsignedTx.nonce,
to: unsignedTx.to as `0x${string}`,
value: BigInt(unsignedTx.value!.toString()),
}
}
};
};
4 changes: 2 additions & 2 deletions src/utils/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { formatEther, parseEther } from 'viem';
import projectListJson from '@/utils/ProjectList.json';
import tokenListJson from '@/utils/TokenList.json';
import { Project, Token } from '../types';
import { formatEther, parseEther } from 'viem';

export const shortenAddress = (address: string) => address.slice(0, 6) + '...' + address.slice(-4);

Expand All @@ -12,7 +12,7 @@ export const findTokenBySymbol = (symbol: string, chainId: number) =>
export const findTokenByAddress = (address: string, chainId: number) =>
tokenListJson.tokens.find(
(token) => token.address.toLowerCase() === address.toLowerCase() && token.chainId === chainId
) as Token | undefined;
) as Token | undefined;
export const formatToEther = (amount: string) => formatEther(BigInt(amount));
export const formatToWei = (amount: string) => parseEther(amount).toString();

Expand Down

0 comments on commit 230d31b

Please sign in to comment.