This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import { CHAIN_NAMESPACES, WALLET_ADAPTERS, WEB3AUTH_NETWORK } from '@web3auth/base'; | |
| import { EthereumPrivateKeyProvider } from '@web3auth/ethereum-provider'; | |
| import { MetamaskAdapter } from '@web3auth/metamask-adapter'; | |
| import { Web3Auth } from '@web3auth/modal'; | |
| import { OpenloginAdapter } from '@web3auth/openlogin-adapter'; | |
| import { ethers } from 'ethers'; | |
| import wallet from './store/wallet'; | |
| const clientId = '...'; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function atLeastTwice(word) { | |
| const wordArray = word.split(''); | |
| const repeatedWords = {}; | |
| wordArray.forEach((char) => { | |
| if (repeatedWords[char]) { | |
| repeatedWords[char] += 1; | |
| } else { | |
| repeatedWords[char] = 1; | |
| } | |
| }); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | await tryAgain(10, async () => { | |
| const result = await fetchEvent(parseInt(requestId, 10)); | |
| if (result) { | |
| setValue(result); | |
| return true; | |
| } | |
| return false; | |
| }); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | const { data, errors } = await response.json(); | |
| if (errors) { | |
| throw errors[0]; | |
| } | |
| if (data && Array.isArray(data.getEntries)) { | |
| const request = data.getEntries.find((e) => | |
| e.event.args.some((a) => a[0] === "requestId" && parseInt(a[1], 16) === requestId) | |
| ); | |
| if (request) { | |
| const arg = request.event.args.find((a) => a[0] === "result"); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | const endpoint = "https://api.kenshi.io/index/graphql"; | |
| const apiKey = process.env.REACT_APP_DEEP_INDEX_API_KEY; | |
| const owner = process.env.REACT_APP_OWNER; | |
| const contract = process.env.REACT_APP_ADDRESS; | |
| const query = `{ | |
| getEntries(blockchain: "avalanche-fuji", apikey: "${apiKey}", owner: "${owner}", address: "${contract}", event: "Rolled") { | |
| event { | |
| args, | |
| name | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | export const rollDice = async (contract, account) => { | |
| const sides = 20; | |
| const callResult = await contract.methods.roll(sides).send({ from: account }); | |
| const requestEvent = callResult.events?.Request; | |
| if (!requestEvent) { | |
| throw new Error("No request event."); | |
| } | |
| const requestId = requestEvent.returnValues.requestId; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | const hasConfigFlag = () => { | |
| return localStorage.getItem(CONFIG_FLAG) === "true"; | |
| }; | |
| const setConfigFlag = () => { | |
| localStorage.setItem(CONFIG_FLAG, "true"); | |
| }; | |
| export const maybeConfig = async (contract, account) => { | |
| if (!hasConfigFlag()) { | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | const roll = async () => { | |
| // Step 1: roll the dice | |
| const requestId = await rollDice(contract, accounts[0]); | |
| // Step 2: try to listen for the final event for 10 times | |
| await tryAgain(10, async () => { | |
| const result = await fetchEvent(parseInt(requestId, 10)); | |
| if (result) { | |
| setValue(result); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | //SPDX-License-Identifier: Apache-2.0 | |
| pragma solidity ^0.8.15; | |
| import "@kenshi.io/vrf-consumer/contracts/VRFConsumer.sol"; | |
| contract DiceRoller is VRFConsumer { | |
| struct Roll { | |
| address player; | |
| uint8 size; | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // @flow | |
| import React from 'react'; | |
| import { Text as RNText, StyleSheet } from 'react-native'; | |
| type Props = { | |
| children: string, | |
| color: string, | |
| style: object | |
| }; | 
NewerOlder