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

[WIP]Add plinko as separated game #75

Open
wants to merge 32 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e23b121
WIP need back end to continue
Mart-Dan-Rossi Sep 6, 2024
ea8321e
Fix chips amount in Plinko in maze
Mart-Dan-Rossi Sep 11, 2024
7cb34c1
Fix chips amount in Plinko in maze
Mart-Dan-Rossi Sep 11, 2024
f7d2219
Backend calling done
Mart-Dan-Rossi Sep 16, 2024
8bcbeb5
Fix balls left bug in plinko
Mart-Dan-Rossi Sep 18, 2024
f9c7851
WIP connecting with plinko back
Mart-Dan-Rossi Sep 20, 2024
e6533ae
add plinko minter contract to local in config.ts
Mart-Dan-Rossi Sep 23, 2024
230ced5
Fix game feedback in non minigame version & can't drop balls while st…
Mart-Dan-Rossi Sep 24, 2024
72b96fd
{
Mart-Dan-Rossi Sep 25, 2024
4324226
Fix area not clickable in plinko board
Mart-Dan-Rossi Sep 25, 2024
882a1a1
Fix when plinko ball get's to the end & backend send's error show it …
Mart-Dan-Rossi Sep 25, 2024
5207067
Add plinko to mobile navbar/sidebar
Mart-Dan-Rossi Sep 25, 2024
36b6ed2
Make available to merge with dev
Mart-Dan-Rossi Sep 26, 2024
5e17897
Move isTest variables to .env
Mart-Dan-Rossi Sep 27, 2024
8bc90e5
Merge branch 'dev' of https://github.com/alpha-fi/cheddar-ecosystem i…
Mart-Dan-Rossi Sep 30, 2024
847d9fe
Internal-external flow in plinko done
Mart-Dan-Rossi Oct 1, 2024
7fd5e5d
Random initial velocity added to plinko balls
Mart-Dan-Rossi Oct 1, 2024
24d4048
Remove console.logs
Mart-Dan-Rossi Oct 1, 2024
a4eb4ef
Rename MAX_BALLS_AMOUNT
Mart-Dan-Rossi Oct 1, 2024
9e9ee12
Fix plinko minigame (It was laking context)
Mart-Dan-Rossi Oct 1, 2024
7ed7363
Move plinko context to PlinkoGameboard.tsx
Mart-Dan-Rossi Oct 2, 2024
8ac9f0f
Move plinko context to PlinkoGameboard.tsx
Mart-Dan-Rossi Oct 2, 2024
43fcd7f
Change mint chedder in plinko feedback
Mart-Dan-Rossi Oct 2, 2024
9892aee
Pull changes on original branch
Mart-Dan-Rossi Oct 2, 2024
4944b87
Remove resetQuery from ModalBuyChips.tsx
Mart-Dan-Rossi Oct 3, 2024
7e7d37c
Font side ended
Mart-Dan-Rossi Oct 3, 2024
b411dfb
Test failed
Mart-Dan-Rossi Oct 3, 2024
b39ad97
Fix debounce
Mart-Dan-Rossi Oct 4, 2024
55b5a67
Toast improved
Mart-Dan-Rossi Oct 4, 2024
9f48eca
fix: move plinko context
RodrigoCSolari Nov 28, 2024
d0f5097
Merge branch 'add-debounce-to-call-ball-played' into add-plinko-as-se…
RodrigoCSolari Dec 2, 2024
89a279f
Merge pull request #84 from alpha-fi/increase-plinko-ball-drop-random…
RodrigoCSolari Dec 2, 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
5 changes: 4 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
NEXT_PUBLIC_NETWORK="[mainnet | testnet | local]"
NEXT_PUBLIC_NETWORK="[mainnet | testnet | local]"
NEXT_PUBLIC_IS_TEST_WIN="[undefined | true]"
NEXT_PUBLIC_IS_TEST_PLINKO="[undefined | true]"
NEXT_PUBLIC_IS_TEST_CARTEL="[undefined | true]"
20 changes: 15 additions & 5 deletions .github/workflows/nextjs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ name: Deploy Next.js site to Pages
on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]
branches: ['main']

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

env:
NEXT_PUBLIC_NETWORK: mainnet
NEXT_PUBLIC_IS_TEST_WIN: false
NEXT_PUBLIC_IS_TEST_PLINKO: false
NEXT_PUBLIC_IS_TEST_CARTEL: false

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
Expand All @@ -24,7 +27,7 @@ permissions:
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
group: 'pages'
cancel-in-progress: false

jobs:
Expand Down Expand Up @@ -54,7 +57,7 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20"
node-version: '20'
cache: ${{ steps.detect-package-manager.outputs.manager }}
- name: Setup Pages
uses: actions/configure-pages@v5
Expand All @@ -70,16 +73,23 @@ jobs:
path: |
.next/cache
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
key:
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json',
'**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
- name: Install dependencies
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
run:
${{ steps.detect-package-manager.outputs.manager }} ${{
steps.detect-package-manager.outputs.command }}
- name: Build with Next.js
run: ${{ steps.detect-package-manager.outputs.runner }} next build
env:
NEXT_PUBLIC_NETWORK: ${{ env.NEXT_PUBLIC_NETWORK }}
NEXT_PUBLIC_IS_TEST_WIN: ${{ env.IS_TEST_WIN }}
NEXT_PUBLIC_IS_TEST_PLINKO: ${{ env.IS_TEST_PLINKO }}
NEXT_PUBLIC_IS_TEST_CARTEL: ${{ env.IS_TEST_CARTEL }}
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"react": "^18",
"react-dom": "^18",
"react-matter-js": "^1.0.5",
"use-debounce": "^10.0.3",
"zustand": "^4.5.4"
},
"devDependencies": {
Expand Down
17 changes: 17 additions & 0 deletions src/app/plinko/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use client';
import { PlinkoBoard } from '@/components/plinko/PlinkoGameboard';
import React from 'react';
import styles from '@/styles/plinko-page.module.css';
import { PlinkoContextProvider } from '@/contexts/plinko/PlinkoContextProvider';
import { PlinkoGame } from '@/components/plinko/PlinkoGame';

export default function Plinko() {
return (
<PlinkoContextProvider>

<div className={styles.gameContainer}>
<PlinkoGame isMinigame={false} />
</div>
</PlinkoContextProvider>
);
}
5 changes: 5 additions & 0 deletions src/components/Navbar/components/DrawerMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ export function DrawerMenu({
Checkers
</Text>
</Link>
<Link href={'/plinko'} style={{ textDecorationColor: 'purple' }}>
<Text fontSize={'16px'} fontWeight="600" color="purple">
Plinko
</Text>
</Link>
</VStack>
</DrawerBody>

Expand Down
8 changes: 8 additions & 0 deletions src/components/Navbar/containers/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ export default function Navbar() {
Checkers
</Text>
</Link>
<Link
href={'/plinko'}
style={{ textDecorationColor: 'white' }}
>
<Text fontSize={'16px'} fontWeight="600" color="white">
Plinko
</Text>
</Link>
</HStack>
</Flex>
</Flex>
Expand Down
18 changes: 9 additions & 9 deletions src/components/maze/GameboardContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Gameboard } from './Gameboard';
import { PlinkoBoard } from '../plinko/PlinkoGameboard';
import styles from '@/styles/GameboardContainer.module.css';
import {
Button,
Expand Down Expand Up @@ -43,7 +42,8 @@ import { Scoreboard } from './Scoreboard';
import { callMintCheddar } from '@/queries/maze/api';
import { getConfig } from '@/configs/config';
import ModalHolonym from '../ModalHolonymSBT';

import Plinko from '@/app/plinko/page';
import { PlinkoGame } from '../plinko/PlinkoGame';
interface Props {
remainingMinutes: number;
remainingSeconds: number;
Expand Down Expand Up @@ -321,29 +321,29 @@ export function GameboardContainer({

if (!isUserNadabotVerfied && !isUserHolonymVerified && !hasEnoughBalance) {
message = (
<>
<span>
Verify on {nadabotLink} or {holonymLink} and buy/hold 555{' '}
{cheddarIcon} from {refLink}.
</>
</span>
);
} else if (
(isUserNadabotVerfied || isUserHolonymVerified) &&
!hasEnoughBalance
) {
message = (
<>
<span>
Buy/hold 555 {cheddarIcon} from {refLink}.
</>
</span>
);
} else if (
!isUserNadabotVerfied &&
!isUserHolonymVerified &&
hasEnoughBalance
) {
message = (
<>
<span>
Verify on {nadabotLink} or {holonymLink}.
</>
</span>
);
}

Expand Down Expand Up @@ -560,7 +560,7 @@ export function GameboardContainer({
hideButtons={true}
showCloseBtn={false}
>
<PlinkoBoard />
<PlinkoGame />
</ModalContainer>
<ModalContainer
title={'Maze scoreboard'}
Expand Down
163 changes: 163 additions & 0 deletions src/components/plinko/ModalBuyChips.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import {
FormControl,
FormLabel,
Button,
useToast,
NumberInput,
NumberInputField,
NumberInputStepper,
NumberIncrementStepper,
NumberDecrementStepper,
Flex,
} from '@chakra-ui/react';
import { useWalletSelector } from '@/contexts/WalletSelectorContext';
import { useContext, useState } from 'react';

import styles from '@/styles/BuyNFTSection.module.css';
import { RenderCheddarIcon } from '../maze/RenderCheddarIcon';
import { ModalContainer } from '../ModalContainer';
import { buyBalls } from '@/contracts/plinko/plinkoCalls';
import { useGetBallCost } from '@/hooks/plinko';
import { yton } from '@/contracts/contractUtils';
import { GameContext } from '@/contexts/maze/GameContextProvider';
import { PlinkoContext } from '@/contexts/plinko/PlinkoContextProvider';

interface Props {
onClose: () => void;
isOpen: boolean;
}

export const ModalBuyChips = ({ isOpen, onClose }: Props) => {
const { /*setResetQuery,*/ setThrownBallsQuantity } =
useContext(PlinkoContext);

const [isLoading, setIsLoading] = useState(false);
const [selectAmountOfChips, setSelectAmountOfChips] = useState(3);
const { selector } = useWalletSelector();
const { data: chipPriceInCheddar, isLoading: isChipPriceInCheddarLoading } =
useGetBallCost();
const toast = useToast();

const cheddarInfo = {
name: 'Cheddar',
price: isChipPriceInCheddarLoading ? 'Loading' : yton(chipPriceInCheddar!),
icon: <RenderCheddarIcon className={styles.tokenIcon} />,
color: 'yellow',
};

function getAmountOfChipsToBuy() {
return (
BigInt(selectAmountOfChips) * BigInt(chipPriceInCheddar!)
).toString();
}

async function handleBuy() {
try {
setIsLoading(true);
const wallet = await selector.wallet();
const amount = getAmountOfChipsToBuy();

if (amount) {
// const resp =
await buyBalls(wallet, amount.toString()!);
// const genericLastResult = await getTransactionLastResult(resp);
// const lastResult: MintNFTLastResult = genericLastResult[1];

// setResetQuery(true);
setThrownBallsQuantity(0);

toast({
title: "Let's play!",
status: 'success',
duration: 9000,
position: 'bottom-right',
isClosable: true,
});
} else {
toast({
title:
'There was an error getting the chips price. Please, try again',
status: 'error',
duration: 9000,
position: 'bottom-right',
isClosable: true,
});
}
} catch (err: any) {
toast({
title: err.message,
status: 'error',
duration: 9000,
position: 'bottom-right',
isClosable: true,
});
}
setIsLoading(false);
}

function changeSelectedAmountOfChips(e: string) {
setSelectAmountOfChips(Number(e));
}

function openToast() {
toast({
title: 'You have to buy at least 1 chip',
status: 'error',
duration: 9000,
position: 'bottom-right',
isClosable: true,
});
}

return (
<ModalContainer title="Buy More Chips" onClose={onClose} isOpen={isOpen}>
<form className={styles.form}>
<FormControl isRequired>
<FormLabel>Amount of chips</FormLabel>
<NumberInput
onChange={changeSelectedAmountOfChips}
size="md"
maxW={24}
defaultValue={3}
min={1}
>
<NumberInputField />
<NumberInputStepper>
<NumberIncrementStepper />
<NumberDecrementStepper />
</NumberInputStepper>
</NumberInput>
</FormControl>

<FormLabel>
<Flex>
<p>
{`Chip cost: ${cheddarInfo.price}`} {cheddarInfo.icon}
</p>
<p>
{`Total cost: ${Number(cheddarInfo.price) * selectAmountOfChips}`}{' '}
{cheddarInfo.icon}
</p>
</Flex>
</FormLabel>
{selectAmountOfChips === 0 ? (
<Button
colorScheme="yellow"
onClick={openToast}
isLoading={isLoading}
>
Purchase
</Button>
) : (
<Button
colorScheme="yellow"
onClick={handleBuy}
isLoading={isLoading}
>
Purchase
</Button>
)}
</form>
</ModalContainer>
);
};
14 changes: 14 additions & 0 deletions src/components/plinko/PlinkoGame.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { PlinkoContextProvider } from '@/contexts/plinko/PlinkoContextProvider';
import { PlinkoBoard } from './PlinkoGameboard';

interface Props {
isMinigame?: boolean;
}

export const PlinkoGame = ({ isMinigame = true }: Props) => {
return (
<PlinkoContextProvider>
<PlinkoBoard isMinigame={isMinigame} />
</PlinkoContextProvider>
);
};
Loading