Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gol2 new version #77

Draft
wants to merge 43 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
5a09a7d
Add new line in GitHub Actions workflow file
bgharbi-globalpos Jan 18, 2024
f8e421c
Migrate starknet v3/v4 to v5 && remove multiple versions
lorcan-codes Nov 6, 2023
e9b69e3
Migrate starknet-react to v2
lorcan-codes Nov 9, 2023
dfba09b
Add lazy loading to community games && show count
lorcan-codes Nov 30, 2023
0416c1b
Fix starknetjs migration bugs
lorcan-codes Dec 25, 2023
cfc7b75
Update contract abi and fix infinite request
lorcan-codes Dec 29, 2023
d0929b5
Fix sql highlight error
lorcan-codes Jan 3, 2024
817aa90
Update snapshot card and fix font weight script
lorcan-codes Jan 9, 2024
7e54760
Add highlight ui after evolving the game
lorcan-codes Jan 16, 2024
ba3ddf1
Add nft minting && update snapshot
lorcan-codes Jan 19, 2024
9e0a493
add axios to package.json
lorcan-codes Jan 19, 2024
5691a61
remove newrelic and axios && log root loader error message
lorcan-codes Jan 19, 2024
753588b
Fix snapshot created popup message
lorcan-codes Jan 22, 2024
d76978c
Fix google font && possibly useStarknet error
lorcan-codes Jan 24, 2024
280845c
Fetch minted nfts using starkscan && update snapshots page
lorcan-codes Jan 25, 2024
6c81c43
Remove state.frames from useGamePlayback deps
lorcan-codes Jan 25, 2024
f5a6fad
Fix increaseAllowance and mints && fix wallet name in dropdown
lorcan-codes Jan 27, 2024
d2452ea
Handle pending snapshot mints
lorcan-codes Jan 29, 2024
48a38ce
Add crt files to gitignore
lorcan-codes Jan 29, 2024
516342b
Fix creator page loading ui bug
lorcan-codes Jan 29, 2024
b97b1d9
Move providers to fix possible env errors
lorcan-codes Jan 30, 2024
af4dd4e
Add console logs
lorcan-codes Jan 30, 2024
159926e
Update console logs
lorcan-codes Jan 30, 2024
a000646
Add support for whitelist minting
lorcan-codes Jan 31, 2024
083af14
Fix revived cell not appearing without refresh
lorcan-codes Feb 2, 2024
4251d2d
Fix showing pending transactions && community games count
lorcan-codes Feb 2, 2024
273b080
fix/update error boundry && update snapshot copy && remove network dr…
lorcan-codes Feb 6, 2024
f590daf
Disable whitelist minting
lorcan-codes Feb 6, 2024
53bf45a
Fix pending transaction in creator mode
lorcan-codes Feb 7, 2024
5164963
Update mint as nft popup
lorcan-codes Feb 8, 2024
2027afa
Add GitHub Actions workflow for Docker build and push
bgharbi-globalpos Feb 10, 2024
31a62c6
Enable whitelist minting for pre migration users
lorcan-codes Feb 10, 2024
3057d98
Disable mint for pre migration
lorcan-codes Feb 10, 2024
3c9bb7c
Fix whitelist mint && get all details from db
lorcan-codes Feb 11, 2024
07852c5
Merge pull request #93 from yuki-wtf/fix-whitelist-mint
lorcan-codes Feb 11, 2024
d66fdbd
Show snapshot created popup for your own evolves only
lorcan-codes Feb 11, 2024
3b7311a
Merge pull request #94 from yuki-wtf/fix-evolve-popup
lorcan-codes Feb 11, 2024
39019bb
Add snapshot mint modal to infinite page && add page intro
lorcan-codes Feb 13, 2024
3dffe1e
Merge pull request #95 from yuki-wtf/infinite-page-mint
lorcan-codes Feb 14, 2024
c019e63
Get mint price and token address from env
lorcan-codes Feb 14, 2024
1928d02
Fix snapshots not updating when account changes
lorcan-codes Feb 14, 2024
7c09442
Merge pull request #97 from yuki-wtf/fix-account-snapshots
lorcan-codes Feb 15, 2024
4c3e777
Merge pull request #96 from yuki-wtf/get-mint-details-from-env
lorcan-codes Feb 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ BASE_URL=/

# Goerli
CONTRACT_ADDRESS=0x06dc4bd1212e67fd05b456a34b24a060c45aad08ab95843c42af31f86c7bd093
INFURA_API_KEY=
USE_MAINNET=false

# Mainnet
CONTRACT_ADDRESS=0x06a05844a03bb9e744479e3298f54705a35966ab04140d3d8dd797c1f6dc49d0
INFURA_API_KEY=
USE_MAINNET=true
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ module.exports = {
'@typescript-eslint/no-non-null-assertion': ['off'],
'@typescript-eslint/no-invalid-void-type': ['off'],
'@typescript-eslint/no-unsafe-member-access': ['off'],
"@typescript-eslint/no-unsafe-assignment": ["off"],
"@typescript-eslint/no-unsafe-call": ["off"],
"@typescript-eslint/no-unsafe-argument": ["off"],
},
// We're using vitest which has a very similar API to jest
// (so the linting plugins work nicely), but we have to
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/miigration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: ci

on:
push:
branches:
- 'update-starknet'

jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v3
with:
push: true
tags: yukilabs/gol2-app:update-starknet
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@
*.pem
.DS_Store
.idea

# certificate files
*.crt
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
"activityBar.background": "#332B35",
"titleBar.activeBackground": "#473C4B",
"titleBar.activeForeground": "#FBFAFB"
}
},
"editor.formatOnSave": true
}
30 changes: 27 additions & 3 deletions app/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ interface Props {
readonly to?: LinkProps['to']
readonly full?: boolean
readonly tertiaryColor?: string
readonly color?: string
readonly disableCursor?: boolean
}

const StyledButton = styled.button<Props>`
Expand Down Expand Up @@ -83,7 +85,13 @@ const StyledButton = styled.button<Props>`

${p.disabled &&
css`
pointer-events: none;
${p.disableCursor
? css`
cursor: not-allowed;
`
: css`
pointer-events: none;
`}
background: ${p.theme.colors.buttonSecondary.disabledBackground};
color: ${p.theme.colors.buttonSecondary.disabledColor};
border: 1px solid transparent;
Expand Down Expand Up @@ -136,7 +144,13 @@ const StyledButton = styled.button<Props>`
}
${p.disabled &&
css`
pointer-events: none;
${p.disableCursor
? css`
cursor: not-allowed;
`
: css`
pointer-events: none;
`}
background: ${p.theme.colors.buttonTertiary.disabledBackground};
color: ${p.theme.colors.buttonTertiary.disabledColor};
`}
Expand Down Expand Up @@ -185,6 +199,13 @@ const StyledButton = styled.button<Props>`
${p.disabled &&
css`
pointer-events: none;
${p.disableCursor
? css`
cursor: not-allowed;
`
: css`
pointer-events: none;
`}
background: ${p.theme.colors.buttonPrimary.disabledBackground};
color: ${p.theme.colors.buttonPrimary.disabledColor};
`}
Expand Down Expand Up @@ -213,6 +234,8 @@ export default function Button({
to,
full,
tertiaryColor,
color,
disableCursor,
}: Props) {
const Component = to != null ? StyledLink : StyledButton

Expand All @@ -235,9 +258,10 @@ export default function Button({
to={to!}
onClick={onClick}
tertiaryColor={tertiaryColor}
disableCursor={disableCursor}
>
{renderIconSpinner()}
<T.Button>{label}</T.Button>
<T.Button color={color}>{label}</T.Button>
</Component>
)
}
9 changes: 3 additions & 6 deletions app/components/Dialogs.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { useDialog } from '~/hooks/Dialog'

import { useStarknet } from '@starknet-react/core'
import { StarknetChainId } from 'starknet/dist/constants'
import { useRootLoaderData } from '~/hooks/useRootLoaderData'

import { HiOutlineX } from 'react-icons/hi'
import Dialog from './Dialog/Dialog'
import { getLibraryChainId } from '~/helpers/getLibraryChainId'
import { useNetwork } from '@starknet-react/core'

export default function Dialogs() {
const [dialog, setDialog] = useDialog()
const { library } = useStarknet()
const { env } = useRootLoaderData()
const { chain } = useNetwork()

return (
<>
Expand All @@ -21,8 +19,7 @@ export default function Dialogs() {
description={
<span>
You are using GoL2 on {env.USE_MAINNET ? 'Mainnet' : 'Testnet'}. Please switch your wallet network from{' '}
{getLibraryChainId(library) === StarknetChainId.MAINNET ? 'Mainnet' : 'Testnet'} to{' '}
{env.USE_MAINNET ? 'Mainnet' : 'Testnet'}
{!chain.testnet ? 'Mainnet' : 'Testnet'} to {env.USE_MAINNET ? 'Mainnet' : 'Testnet'}
<br /> <br /> Try refreshing the app if network used is not correctly detected by Gol2.
</span>
}
Expand Down
33 changes: 16 additions & 17 deletions app/components/GameMode/Creator/GameHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import { useStarknet, useStarknetInvoke } from '@starknet-react/core'
import { useContractWrite } from '@starknet-react/core'
import { useEffect, useState } from 'react'
import { HiOutlineLightningBolt, HiOutlineX } from 'react-icons/hi'
import { useLocalStorage } from 'react-use'
import { StarknetChainId } from 'starknet4/dist/constants'

import Button from '~/components/Button'
import Dialog from '~/components/Dialog/Dialog'
import Highlight from '~/components/Highlight'
import Loader from '~/components/Loader'
import { useDialog } from '~/hooks/Dialog'
import { useHelpMessage } from '~/hooks/HelpMessage'
import { useGameContract } from '~/hooks/useGameContract'
import { useRootLoaderData } from '~/hooks/useRootLoaderData'
import { useUser } from '~/hooks/useUser'
import Header from '../Shared/Game/Header'
import { getLibraryChainId } from '~/helpers/getLibraryChainId'

import { useCheckNetwork } from '~/helpers/useCheckNetwork'
interface Props {
readonly isGameOver: boolean
readonly gameId: string
Expand All @@ -26,15 +24,18 @@ export default function GameHeader({ gameId, isGameOver }: Props) {
const [userCancelledDialogOpen, setUserCancelledDialogOpen] = useState(false)
const { contract } = useGameContract()
const user = useUser()
const { library } = useStarknet()
const [, setDialog] = useDialog()
const [helpMessage, setHelpMessage] = useHelpMessage()
const { env } = useRootLoaderData()
const currentStarknetChainId = env.USE_MAINNET ? StarknetChainId.MAINNET : StarknetChainId.TESTNET

const { data, loading, error, reset, invoke } = useStarknetInvoke({
contract,
method: 'evolve',
const { isCorrectNetwork } = useCheckNetwork()

const {
write,
data,
isLoading: loading,
isError: error,
reset,
} = useContractWrite({
calls: contract ? [contract.populateTransaction.evolve!(gameId)] : [],
})

useEffect(() => {
Expand Down Expand Up @@ -71,7 +72,7 @@ export default function GameHeader({ gameId, isGameOver }: Props) {

const formData = new FormData()

formData.append('hash', data)
formData.append('hash', data.transaction_hash)
formData.append('status', 'RECEIVED')
formData.append('functionName', 'evolve')
formData.append('functionCaller', user!.userId)
Expand Down Expand Up @@ -128,16 +129,14 @@ export default function GameHeader({ gameId, isGameOver }: Props) {
onClick={() => {
setHasClickedEvolveCreator(true)

if (getLibraryChainId(library) != currentStarknetChainId) {
if (!isCorrectNetwork) {
setDialog('WrongNetworkDialog')
return
}

if (user != null) {
// TODO test this
void invoke({
args: [gameId],
})
write()
return
}
setHelpMessage('connectWalletMessage')
Expand Down
29 changes: 14 additions & 15 deletions app/components/GameMode/Infinite/GameHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { useStarknet, useStarknetInvoke } from '@starknet-react/core'
import { useContractWrite } from '@starknet-react/core'
import { useEffect, useState } from 'react'
import { HiOutlineLightningBolt, HiOutlineX } from 'react-icons/hi'
import { useLocalStorage } from 'react-use'
import { StarknetChainId } from 'starknet4/dist/constants'
import Dialog from '~/components/Dialog/Dialog'
import Highlight from '~/components/Highlight'
import Loader from '~/components/Loader'
Expand All @@ -11,12 +10,11 @@ import { useDialog } from '~/hooks/Dialog'
import { useHelpMessage } from '~/hooks/HelpMessage'
import { useSelectedCell } from '~/hooks/SelectedCell'
import { useGameContract } from '~/hooks/useGameContract'
import { useRootLoaderData } from '~/hooks/useRootLoaderData'
import { useUser } from '~/hooks/useUser'
import Button from '../../Button'
import TempOverlay from '../../TempOverlay'
import Header from '../Shared/Game/Header'
import { getLibraryChainId } from '~/helpers/getLibraryChainId'
import { useCheckNetwork } from '~/helpers/useCheckNetwork'

export default function GameHeader() {
const [hasClickedEvolveInfinite, setHasClickedEvolveInfinite] = useLocalStorage('has-clicked-evolve-infinite', false)
Expand All @@ -26,15 +24,18 @@ export default function GameHeader() {
const { contract } = useGameContract()
const user = useUser()
const [helpMessage, setHelpMessage] = useHelpMessage()
const { library } = useStarknet()
const [, setDialog] = useDialog()
const { env } = useRootLoaderData()
const currentStarknetChainId = env.USE_MAINNET ? StarknetChainId.MAINNET : StarknetChainId.TESTNET

const { data, loading, error, reset, invoke } = useStarknetInvoke({
contract,
method: 'evolve',
const {
write,
data,
isLoading: loading,
error,
reset,
} = useContractWrite({
calls: contract ? [contract.populateTransaction.evolve!(INFINITE_GAME_GENESIS)] : [],
})
const { isCorrectNetwork } = useCheckNetwork()

useEffect(() => {
if (hasClickedEvolveInfinite) return
Expand Down Expand Up @@ -69,7 +70,7 @@ export default function GameHeader() {

const formData = new FormData()

formData.append('hash', data)
formData.append('hash', data.transaction_hash)
formData.append('status', 'RECEIVED')
formData.append('functionName', 'evolve')
formData.append('functionCaller', user!.userId)
Expand Down Expand Up @@ -127,15 +128,13 @@ export default function GameHeader() {
onClick={() => {
setHasClickedEvolveInfinite(true)

if (getLibraryChainId(library) != currentStarknetChainId) {
if (!isCorrectNetwork) {
setDialog('WrongNetworkDialog')
return
}

if (user != null) {
void invoke({
args: [INFINITE_GAME_GENESIS],
})
write()
return
}

Expand Down
64 changes: 64 additions & 0 deletions app/components/GameMode/Infinite/MintSnapshot.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { HiOutlineX } from 'react-icons/hi'
import Snapshot from '~/components/Snapshot/Snapshot'
import * as SnapshotDialog from '~/components/Snapshot/SnapshotDialog'
import { twitter } from '~/helpers/twitter'
import { useRootLoaderData } from '~/hooks/useRootLoaderData'
import { useUser } from '~/hooks/useUser'

interface MintSnapshotProps {
snapshot: {
gameGeneration: string
gameState: string
}
onClose: () => void
onSnapshotMintCreated: () => void
}
export default function MintSnapshot({ snapshot, onClose, onSnapshotMintCreated }: MintSnapshotProps) {
const currentUser = useUser()
const { env } = useRootLoaderData()

return (
<SnapshotDialog.Dialog
open={!!snapshot.gameGeneration}
onOpenChange={(openState) => {
if (!openState) {
onClose()
}
}}
>
<SnapshotDialog.DialogContent>
<div style={{ position: 'absolute', top: 10, right: 5, zIndex: 100 }}>
<SnapshotDialog.DialogClose>
<HiOutlineX size={24} />
</SnapshotDialog.DialogClose>
</div>
<Snapshot
large
gameGeneration={snapshot.gameGeneration}
gameState={snapshot.gameState}
user={currentUser?.userId}
refreshPage={onSnapshotMintCreated}
initial={{
opacity: 0,
y: 10,
}}
animate={{
opacity: 1,
y: 0,
transition: {
delay: 0,
},
}}
onClickTwitter={() => {
open(
twitter(
`I own generation ${snapshot.gameGeneration} in @GoL2io 💪 #GoL2 #Starknet`,
`${env.BASE_URL!}/infinite/${snapshot.gameGeneration}`
)
)
}}
/>
</SnapshotDialog.DialogContent>
</SnapshotDialog.Dialog>
)
}
Loading
Loading