Skip to content

Commit

Permalink
Refreshing contract state on mint (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
liarco authored Jun 8, 2022
1 parent bc865ae commit 831dbe2
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions minting-dapp/src/scripts/react/Dapp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export default class Dapp extends React.Component<Props, State> {
<a href={this.generateTransactionUrl(receipt.transactionHash)} target="_blank" rel="noopener">View on {this.state.networkConfig.blockExplorer.name}</a>
</>);

this.refreshContractState();
this.setState({loading: false});
} catch (e) {
this.setError(e);
Expand All @@ -127,6 +128,7 @@ export default class Dapp extends React.Component<Props, State> {
<a href={this.generateTransactionUrl(receipt.transactionHash)} target="_blank" rel="noopener">View on {this.state.networkConfig.blockExplorer.name}</a>
</>);

this.refreshContractState();
this.setState({loading: false});
} catch (e) {
this.setError(e);
Expand Down Expand Up @@ -317,6 +319,19 @@ export default class Dapp extends React.Component<Props, State> {
}
}

private async refreshContractState(): Promise<void>
{
this.setState({
maxSupply: (await this.contract.maxSupply()).toNumber(),
totalSupply: (await this.contract.totalSupply()).toNumber(),
maxMintAmountPerTx: (await this.contract.maxMintAmountPerTx()).toNumber(),
tokenPrice: await this.contract.cost(),
isPaused: await this.contract.paused(),
isWhitelistMintEnabled: await this.contract.whitelistMintEnabled(),
isUserInWhitelist: Whitelist.contains(this.state.userAddress ?? ''),
});
}

private async initWallet(): Promise<void>
{
const walletAccounts = await this.provider.listAccounts();
Expand Down Expand Up @@ -358,15 +373,7 @@ export default class Dapp extends React.Component<Props, State> {
this.provider.getSigner(),
) as NftContractType;

this.setState({
maxSupply: (await this.contract.maxSupply()).toNumber(),
totalSupply: (await this.contract.totalSupply()).toNumber(),
maxMintAmountPerTx: (await this.contract.maxMintAmountPerTx()).toNumber(),
tokenPrice: await this.contract.cost(),
isPaused: await this.contract.paused(),
isWhitelistMintEnabled: await this.contract.whitelistMintEnabled(),
isUserInWhitelist: Whitelist.contains(this.state.userAddress ?? ''),
});
this.refreshContractState();
}

private registerWalletEvents(browserProvider: ExternalProvider): void
Expand Down

0 comments on commit 831dbe2

Please sign in to comment.