Skip to content

Commit d26e294

Browse files
authored
Merge pull request #13 from Apillon/develop
Updated EW
2 parents b5a30df + c31c05c commit d26e294

15 files changed

Lines changed: 2170 additions & 805 deletions

.env

Lines changed: 0 additions & 6 deletions
This file was deleted.

.env.example

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Uncomment the chain you are using:
2+
VITE_CHAIN_ID=1287
3+
4+
# Paste the address of the contract.
5+
VITE_CONTRACT_ADDRESS=''
6+
7+
# Paste UUID of the embedded wallet.
8+
VITE_EMBEDDED_WALLET_CLIENT=''
9+
10+
# Paste WalletConnect project ID if you want to offer WalletConnect.
11+
VITE_WALLET_CONNECT_PROJECT=''
12+
13+
# Define logo and cover images.
14+
VITE_IMG_LOGO=''
15+
VITE_IMG_COVER=''

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ typings/
6969

7070
# misc
7171
.DS_Store
72+
.env
7273
.env.local
7374
.env.development.local
7475
.env.test.local

package-lock.json

Lines changed: 2071 additions & 729 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"preview": "vite preview"
1111
},
1212
"dependencies": {
13-
"@apillon/wallet-react": "^2.1.2",
13+
"@apillon/wallet-react": "^3.0.3",
1414
"@tanstack/react-query": "^5.76.1",
1515
"react": "^18.2.0",
1616
"react-dom": "^18.2.0",

src/App.tsx

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,6 @@ function App() {
6666
</div>
6767
</div>
6868

69-
{connected && collectionInfo?.name && (
70-
<div className='max-w-lg mx-auto my-12'>
71-
<h3>
72-
The collection you are viewing supports nesting NFTs you own. To setup the nested relationship between NFTs,
73-
you first have to own them.
74-
</h3>
75-
<strong>Instructions:</strong>
76-
<ol>
77-
<li>Mint one or multiple NFTs</li>
78-
<li>Once minted, click on “My NFTs”</li>
79-
<li>The NFTs you own will be displayed</li>
80-
</ol>
81-
</div>
82-
)}
83-
8469
{connected && collectionInfo?.name && (
8570
<div className='mb-6'>
8671
<h2 className='text-center'>Show NFTs:</h2>

src/components/Btn.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const Btn = ({
2424
}
2525

2626
return (
27-
<button {...attrs} className={disabled ? 'relative disabled' : 'relative'} onClick={(e) => handleClick(e)}>
27+
<button {...attrs} className={disabled ? 'relative btn disabled' : 'relative btn'} onClick={(e) => handleClick(e)}>
2828
{loading && <Spinner />}
2929
<span className={loading ? 'opacity-0' : ''}>{children}</span>
3030
</button>

src/components/Mint.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default function Mint() {
4343

4444
toast.info('NFT minting has started');
4545

46-
const receipt = await publicClient.waitForTransactionReceipt({ hash: tx });
46+
const receipt: any = await publicClient.waitForTransactionReceipt({ hash: tx });
4747
toast.success('NFT has been successfully minted');
4848

4949
const logs = receipt?.logs || receipt.data?.logs;
@@ -78,7 +78,7 @@ export default function Mint() {
7878
<label htmlFor='amount'>Number of tokens (1-5):</label>
7979
<input type='number' min='1' max='5' value={amount} onChange={() => handleChange} />
8080
</div>
81-
<button className='btn-mint' id='btnMint' onClick={() => mint()}>
81+
<button className='btn btn-mint' onClick={() => mint()}>
8282
{loading ? <Spinner /> : 'Mint'}
8383
</button>
8484
</div>

src/components/WalletConnect.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useEffect, useState } from 'react';
22
import { useAccount, useConnect, useChains } from 'wagmi';
3-
import { EmbeddedWallet } from '@apillon/wallet-react';
4-
import { useWallet } from '@apillon/wallet-react';
3+
import { type Network } from '@apillon/wallet-sdk';
4+
import { EmbeddedWallet, useWallet } from '@apillon/wallet-react';
55
import { useWalletConnect } from '../hooks/useWalletConnect';
66
import { EMBEDDED_WALLET_CLIENT } from '../lib/config';
77
import { shortHash } from '../lib/strings';
@@ -22,9 +22,9 @@ export default function WalletConnect() {
2222
const networks = chains.map((chain) => ({
2323
name: chain.name,
2424
id: chain.id,
25-
rpcUrl: chain.rpcUrls.default.http[0],
26-
explorerUrl: chain.blockExplorers?.default?.url,
27-
}));
25+
rpcUrl: chain.rpcUrls.default.http[0]||'',
26+
explorerUrl: chain.blockExplorers?.default?.url||'',
27+
} as Network));
2828

2929
function openModal() {
3030
scrollLock.enable();
@@ -53,6 +53,14 @@ export default function WalletConnect() {
5353
setConnectorName(conn.name);
5454
connect({ connector: conn });
5555
};
56+
57+
const disconnect =() => {
58+
if (isConnected) {
59+
disconnectWallet();
60+
} else if (wallet) {
61+
wallet.events.emit('open', true);
62+
}
63+
}
5664

5765
useEffect(() => {
5866
if (isConnected) closeWallet();
@@ -68,7 +76,7 @@ export default function WalletConnect() {
6876
variant='secondary'
6977
disabled={false}
7078
loading={false}
71-
onClick={() => disconnectWallet()}
79+
onClick={() => disconnect()}
7280
>
7381
Disconnect
7482
</Btn>

src/hooks/useContract.tsx

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,27 +59,38 @@ export function useContract() {
5959
return Number(collectionInfo.balance);
6060
};
6161

62-
const mintToken = async (price: bigint, amount = 1): Promise<Address | void> => {
62+
const mintToken = async (price: bigint, amount = 1): Promise<Address | null> => {
63+
if(!walletAddress) return null;
64+
6365
const value = price * BigInt(amount);
6466
const args = [walletAddress, amount];
65-
const gas = await publicClient.estimateContractGas({
66-
address: CONTRACT_ADDRESS,
67-
abi: nftAbi,
68-
functionName: 'mint',
69-
args,
70-
account: walletAddress,
71-
value,
72-
});
73-
const gasLimit = (gas * 110n) / 100n;
7467

7568
if (info.activeWallet?.address) {
76-
return await mintEW(args, value, gasLimit);
69+
return await mintEW(args, value);
7770
}
7871

7972
await initContract(true);
73+
const gasLimit = await calcGas(args, value);
8074
return await contract.write.mint(args, { value }, { gasLimit });
8175
};
8276

77+
async function calcGas(args: Array<any>, value: bigint): Promise<bigint>{
78+
try {
79+
const gas = await publicClient.estimateContractGas({
80+
address: CONTRACT_ADDRESS,
81+
abi: nftAbi,
82+
functionName: 'mint',
83+
args,
84+
account: walletAddress as Address,
85+
value,
86+
});
87+
return (gas * 110n) / 100n;
88+
} catch (e: any) {
89+
console.error(e);
90+
return 250000n;
91+
}
92+
}
93+
8394
const loadCollectionInfo = async () => {
8495
await initContract();
8596
await Promise.all([

0 commit comments

Comments
 (0)