Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/nft buy not working #404

Merged
merged 3 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/components/cactiComponents/ActionResponse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export type ActionResponseProps = {
sendParams?: UnsignedTransaction | undefined;
label?: string;
disabled?: boolean;
skipBalanceCheck?: boolean;
stepper?: boolean;
onSuccess?: (txReceipt?: TransactionReceipt) => any;
onError?: (txHash?: string) => any;
Expand All @@ -73,6 +74,7 @@ export const ActionResponse = ({
label: label_,
disabled,
stepper,
skipBalanceCheck,
onSuccess,
onError,
}: ActionResponseProps) => {
Expand Down Expand Up @@ -119,19 +121,19 @@ export const ActionResponse = ({
const [hasEnoughBalance, setHasEnoughBalance] = useState(false);

useEffect(() => {
if (approvalParams?.skipBalanceCheck || approvalParams?.skipApproval)
return setHasEnoughBalance(true);
if (approvalParams?.skipApproval || skipBalanceCheck) return setHasEnoughBalance(true);

// check value balance if skipping approval cuz we assume user is using eth
if (sendParams?.value! <= ethBal!) return setHasEnoughBalance(true);
// ( explicitly showing approvalParams === undefined for clarity - as oppposed to !approvalParams)
if (approvalParams === undefined || sendParams?.value! <= ethBal!)
return setHasEnoughBalance(true);

// check approval token balance
if (balance && approvalParams?.approvalAmount)
setHasEnoughBalance(balance.gte(approvalParams?.approvalAmount!));
}, [
approvalParams?.approvalAmount,
approvalParams?.skipApproval,
approvalParams?.skipBalanceCheck,
balance,
ethBal,
sendParams?.value,
Expand Down
1 change: 0 additions & 1 deletion src/components/cactiComponents/hooks/useApproval.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export type ApprovalBasicParams = {
tokenAddress: `0x${string}`;
spender: `0x${string}`;
skipApproval?: boolean;
skipBalanceCheck?: boolean; // TODO make this more robust
};

const validateAddress = (addr: `0x${string}`): `0x${string}` | undefined =>
Expand Down
8 changes: 6 additions & 2 deletions src/components/experimental_/MessageInput_.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,13 @@ const MessageInput = () => {
</form>
</div>
</div>
) : botConnected ? (
<CustomConnectButton />
) : (
botConnected ? <CustomConnectButton /> :
<div className='text-white/30 text-sm animate-pulse'> Waiting for Cacti connection ... </div>
<div className="animate-pulse text-sm text-white/30">
{' '}
Waiting for Cacti connection ...{' '}
</div>
)}
</>
);
Expand Down
55 changes: 0 additions & 55 deletions src/components/experimental_/widgets/nft/BuyNft.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,6 @@ export const BuyNft = ({ nftAddress, tokenId }: { nftAddress: string; tokenId: s
return (
<ConnectFirst>
<HeaderResponse text={`Buy NFT`} projectName={'Opensea Seaport'} />
{/* <Widget
widget={{
name: 'nft-asset-container',
params: {
network: 'ethereum-mainnet',
address: nftAddress,
tokenId: tokenId,
// collectionName: nftData?.collectionName,
// name: nftData?.name,
// previewImageUrl: nftData?.smallPreviewImageUrl,
variant: 'showcase',
},
}}
/> */}
<NftAsset
address={nftAddress}
tokenId={tokenId}
Expand All @@ -155,46 +141,5 @@ export const BuyNft = ({ nftAddress, tokenId }: { nftAddress: string; tokenId: s
disabled={isExpired || notForSale}
/>
</ConnectFirst>

/* <div className="mb-2 flex flex-col items-center justify-center gap-1">
<NFTMetadata nftAddress={nftAddress} tokenId={tokenId} />
<NftOwner nftAddress={nftAddress} tokenId={tokenId} />
</div> */

/* <SubmitButton
styleProps="flex rounded-sm border border-gray-200/25 bg-gray-700/80 p-3.5 hover:bg-gray-700"
label={
isSuccess
? 'Success! You now own the NFT.'
: isTxPending
? 'Buying NFT...'
: isWriteError
? 'Error buying NFT'
: isPrepareError
? 'NFT not available for purchase'
: isQueryError
? 'Error fetching NFT listing'
: isFulfillError
? 'Error fetching fulfillment data'
: isQueryLoading
? 'Fetching NFT listing...'
: isExpired
? 'Listing expired'
: `Buy NFT ${valueAmount ? `for ${formatEther(valueAmount)} ETH` : ''}`
}
onClick={() => seaportWrite?.()}
isLoading={isQueryLoading || isTxPending}
isError={isQueryError || isFulfillError || isWriteError || isPrepareError}
disabled={
isQueryLoading ||
isExpired ||
isQueryError ||
isFulfillError ||
isWriteError ||
isPrepareError ||
isTxPending ||
isSuccess
}
/> */
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ const SingleVault = ({ vaultId }: { vaultId: `0x${string}` }) => {
spender: ladleAddress,
approvalAmount: vault?.accruedArt.mul(110).div(100), // 10% buffer: TODO make more kosher
tokenAddress: vault.borrowToken?.address!,
skipBalanceCheck: vault.borrowToken?.symbol === 'WETH',
};
}, [ladleAddress, vault]);

Expand Down Expand Up @@ -207,6 +206,7 @@ const SingleVault = ({ vaultId }: { vaultId: `0x${string}` }) => {
approvalParams={approvalParams}
sendParams={sendParams}
txParams={undefined}
skipBalanceCheck={vault.borrowToken?.symbol === 'WETH'}
/>
</div>
</SingleLineResponse>
Expand Down