diff --git a/src/contexts/WalletContext.tsx b/src/contexts/WalletContext.tsx index e32b1e3..02017d1 100644 --- a/src/contexts/WalletContext.tsx +++ b/src/contexts/WalletContext.tsx @@ -68,8 +68,18 @@ const isMetamaskProvider = ( ) => provider?.connection?.url === 'metamask'; export const WalletProvider: React.FC = ({ children }) => { - const [{ rawProvider, fallbackProvider, provider, biconomy, chainId, address, ensName }, setWalletState] = - useState({}); + const [ + { + rawProvider, + fallbackProvider, + provider, + biconomy, + chainId, + address, + ensName + }, + setWalletState + ] = useState({}); const isConnected: boolean = useMemo( () => !!provider && !!address && !!chainId, @@ -82,6 +92,7 @@ export const WalletProvider: React.FC = ({ children }) => { const disconnect = useCallback(async () => { web3Modal.clearCachedProvider(); setWalletState({}); + window.location.reload(); }, []); const addMetaMaskListeners = useCallback( @@ -113,19 +124,20 @@ export const WalletProvider: React.FC = ({ children }) => { network = DEFAULT_NETWORK; } - const biconomy = new window.Biconomy(window.ethereum, { + console.log('PROV: ', prov); + const biconomy = new window.Biconomy(prov, { strictMode: true, apiKey: process.env.REACT_APP_BICONOMY_API, debug: true - }) + }); try { new Promise((resolve, reject) => { biconomy .onEvent(biconomy.READY, () => resolve(0)) - .onEvent(biconomy.ERROR, (err: Error) => reject(err)) - }) + .onEvent(biconomy.ERROR, (err: Error) => reject(err)); + }); } catch (err) { - throw new Error("Biconomy failed to connect") + throw new Error('Biconomy failed to connect'); } // TODO: Move to better location const isPolygonChain = network === 137 || network === 80001; @@ -137,7 +149,7 @@ export const WalletProvider: React.FC = ({ children }) => { rawProvider: prov, fallbackProvider: ethersProvider, provider: new ethers.providers.Web3Provider(biconomy), - biconomy, + biconomy, chainId: network, address: signerAddress.toLowerCase(), ensName: signerName diff --git a/src/views/BuildBoardView/index.tsx b/src/views/BuildBoardView/index.tsx index cc0cb16..861ae30 100644 --- a/src/views/BuildBoardView/index.tsx +++ b/src/views/BuildBoardView/index.tsx @@ -128,7 +128,9 @@ export default function BuildBoard(): JSX.Element { IPFS_CIDS.board.circuit, IPFS_CIDS.board.zkey ); - const vkey = await fetch(IPFS_CIDS.board.verification_key).then((res) => { return res.json() }); + const vkey = await fetch(IPFS_CIDS.board.verification_key).then((res) => { + return res.json(); + }); await window.snarkjs.groth16.verify(vkey, publicSignals, proof); const proofArgs = buildProofArgs(proof); return { hash: _shipHash, proof: proofArgs }; @@ -163,8 +165,8 @@ export default function BuildBoard(): JSX.Element { proof[1], proof[2], proof[3] - ] - const tx = await metatransaction(biconomy, 'joinGame', params) + ]; + const tx = await metatransaction(biconomy, 'joinGame', params); localStorage.setItem( `BOARD_STATE_${id}_${address}`, JSON.stringify(placedShips) @@ -175,14 +177,9 @@ export default function BuildBoard(): JSX.Element { } else { toast.loading(`Creating game...`, { id: loadingToast }); const currentIndex = await getGameIndex(chainId, provider); - const params = [ - BN.from(hash), - proof[0], - proof[1], - proof[2], - proof[3] - ] - const tx = await metatransaction(biconomy, 'newGame', params) + const params = [BN.from(hash), proof[0], proof[1], proof[2], proof[3]]; + debugger; + const tx = await metatransaction(biconomy, 'newGame', params); localStorage.setItem( `BOARD_STATE_${+currentIndex + 1}_${address}`, JSON.stringify(placedShips) diff --git a/src/web3/erc2771.ts b/src/web3/erc2771.ts index c797fd3..1a0973d 100644 --- a/src/web3/erc2771.ts +++ b/src/web3/erc2771.ts @@ -16,7 +16,7 @@ export const metatransaction = async (biconomy: any, name: string, args: any[]): Promise => { const provider = biconomy.getEthersProvider(); const sender = provider.getSigner(); - const contractAddress = BATTLESHIP_GAME_CONTRACT[parseInt(provider.provider.chainId, 16)]; + const contractAddress = BATTLESHIP_GAME_CONTRACT[provider.provider.networkId]; const instance = new Contract(contractAddress, ABI, sender); const { data } = await instance.populateTransaction[name](...args); const gasLimit = await provider.estimateGas({ @@ -31,7 +31,7 @@ export const metatransaction = async (biconomy: any, name: string, args: any[]): gasLimit, signatureType: "EIP712_SIGN" } - + let tx = await provider.send("eth_sendTransaction", [params]) provider.once(tx, (transaction: any) => { console.log('xxx', tx)