Skip to content

Commit

Permalink
Fix type issue and render error message (#37)
Browse files Browse the repository at this point in the history
* fix: security issue

* fix: update src/actions/web3.ts

Co-authored-by: Marin Petrunić <[email protected]>

* fix type issue and show error message

Co-authored-by: wei3erHase <[email protected]>
  • Loading branch information
mpetrunic and wei3erHase authored Oct 27, 2021
1 parent 45aaf6b commit db7f6db
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/actions/web3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function getWeb3Provider(): JsonRpcProvider {

export async function getWeb3Signer(): Promise<Web3Provider> {
const provider = new providers.Web3Provider(await web3Modal.connect())
if(provider.network.chainId !== 69) {
if((await provider.getNetwork()).chainId !== 69) {
throw new Error("Invalid network")
}
return provider;
Expand Down
11 changes: 8 additions & 3 deletions src/scenes/main/planets/planet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@ export class Planet extends Phaser.GameObjects.Sprite {
console.log(e);
}

const signer = await getWeb3Signer();
const contract = new Contract(planetAddress, PlanetABI, signer.getSigner()) as PlanetContract;
await contract.collect("0x36Ca879e11aA582AB92d43547da1EA5cFd57067b", this.id);
try {
const signer = await getWeb3Signer();
const contract = new Contract(planetAddress, PlanetABI, signer.getSigner()) as PlanetContract;
await contract.collect("0x36Ca879e11aA582AB92d43547da1EA5cFd57067b", this.id);
} catch (e) {
window.alert((e as Error).message);
}

});
}

Expand Down

0 comments on commit db7f6db

Please sign in to comment.