Skip to content

Commit

Permalink
feat: everything works
Browse files Browse the repository at this point in the history
  • Loading branch information
RasenGUY committed Dec 1, 2023
1 parent eec2da9 commit 04f4899
Show file tree
Hide file tree
Showing 22 changed files with 233 additions and 93 deletions.
61 changes: 41 additions & 20 deletions deployed-addresses.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,51 +67,72 @@
"80001": {
"contracts": {
"WegaERC20Escrow": {
"address": "0xCEBc6b24362cA2F4fA625d340BeF8Af4F91DB5bB",
"legacyAddresses": [],
"deploymentBlock": "263113a",
"implementation": "0x0993a07880aD59E02e72E745dC5b623409Ad24af"
"address": "0x4B4e9126b1701385dc5b0D02b12360635D57F12C",
"legacyAddresses": [
"0x0993a07880aD59E02e72E745dC5b623409Ad24af"
],
"deploymentBlock": null,
"implementation": "0xB08555B946a2fcef22074a9115250a6666A3b901"
},
"WegaERC20Dummy": {
"address": "0x802361100a4772847DBc29BC59F76FD1F186E002",
"address": "0x1CdB8176Ad8579aE748703f40864BB2E65e68529",
"legacyAddresses": [],
"deploymentBlock": "263112e"
},
"WegaGameController": {
"address": "0xe4da6EE02D91b7C03DB000B9295A815D6BEeC4ca",
"address": "0x39e851282C11AefE20B149F4509702B2DC8aEB73",
"legacyAddresses": [
"0x21A8Eda1B590268410e520B70635467720B41418",
"0x760D87Ce891F301d19F608044D42356De2D50D14",
"0x740e1416aE865E2bff8f95aa5776F5Fa0a3706e7",
"0x02D7EF0f678BCd9323f2FA88e7197528D113f24a",
"0x0000000000000000000000000000000000000000"
],
"deploymentBlock": "272c37b",
"implementation": "0x21A8Eda1B590268410e520B70635467720B41418"
"deploymentBlock": null,
"implementation": "0x6215002028eA5Ec1F89D5bc5D553ce83Fed6Cd1b"
},
"WegaRandomizerController": {
"address": "0xcd44090c1BC8DC05298540488ca6FA058d27Ac70",
"address": "0xC757438A9eF34020FEBB7E25336e4eC20dE55fD1",
"legacyAddresses": [],
"implementation": "0x24F9E5E74976661E3784E258986Ee9ee6AAe8132"
"implementation": "0x24F9E5E74976661E3784E258986Ee9ee6AAe8132",
"deploymentBlock": null
},
"WegaDiceGame": {
"address": "0x5581147651B29D44d4eD95099F1a53aAE052f797",
"legacyAddresses": [],
"deploymentBlock": "263116f",
"implementation": "0x4f2Fe30D48961581d65C0a486AE5e83A9b8356b0"
"address": "0xd806555f94769bEeAF1d60858f3963C095434aA1",
"legacyAddresses": [
"0x4f2Fe30D48961581d65C0a486AE5e83A9b8356b0"
],
"deploymentBlock": null,
"implementation": "0x3C119E7148071Ea0e7B2abBa63eae2f097a4cEdf"
},
"WegaCoinFlipGame": {
"address": "0x24133b29067AC3858B4F58112bCAC243941538c8",
"legacyAddresses": [],
"deploymentBlock": "2631158",
"implementation": "0x0C438E3C3B7b629044573e7cc3B0FBe55DB1b8b6"
"address": "0x57aB2987CBa91f08Db532c57Cfa7478cd5D009b2",
"legacyAddresses": [
"0x0C438E3C3B7b629044573e7cc3B0FBe55DB1b8b6"
],
"deploymentBlock": null,
"implementation": "0x1fC17Ca1b3e702E0D93D3BA5FEA2573079e60Af0"
},
"FeeManager": {
"address": "0xe2cDC641b8AF26a208402a3e218EE022E954Afd0",
"address": "0xc392D90803D462Ac5395A76d59AB942a8d9DCe69",
"legacyAddresses": [],
"implementation": "0x30D1C9b043014820cC878ea023bd9Ae53238B395"
"implementation": "0x30D1C9b043014820cC878ea023bd9Ae53238B395",
"deploymentBlock": null
},
"WegaRandomizer": {
"address": "0x0000000000000000000000000000000000000000"
},
"WegaChanceGame": {
"address": "0x85c5165800E4f43489912beEc115a77E312142ca",
"legacyAddresses": [],
"deploymentBlock": "25e6a43",
"implementation": "0x945Fbb4138040e2ab766CB59A7Aa6D882AfBCcF4"
},
"WegaRandomNumberController": {
"address": "0xaBC8837A5756aF9a915a8cC77b80b06c1997e17e",
"legacyAddresses": [],
"deploymentBlock": "2631148",
"implementation": "0xCC6e334201974DF201EBb4bd84b97ac232fE7380"
}
}
},
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"scripts": {
"app": "export GSAP_TOKEN=$(grep 'GSAP_TOKEN=' .env | cut -d'=' -f2) && vite --mode",
"export:env": "export GSAP_TOKEN=$(grep 'GSAP_TOKEN=' .env | cut -d'=' -f2)",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"lint:fix": "eslint \"src/**/*.{ts,tsx}\" --fix",
Expand Down
2 changes: 0 additions & 2 deletions src/app/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ import walletConnectionReducer from '../components/RainBowConnectButton/connecti
import { blockchainApiSlice } from './blockchainApiSlice';
import { appApiSlice } from './apiSlice';
import intlReducer from '../containers/LanguageProvider/intlSlice'
import blockchainReducer from '../api/blockchain/blockchainSlice'

export const store = configureStore({
reducer: {
connection: walletConnectionReducer,
[appApiSlice.reducerPath]: appApiSlice.reducer,
[blockchainApiSlice.reducerPath]: blockchainApiSlice.reducer,
blockchain: blockchainReducer,
language: intlReducer,
},
middleware: (getDefaultMiddleware) => getDefaultMiddleware({
Expand Down
2 changes: 1 addition & 1 deletion src/assets/icons/ArrowDownIconV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const SvgComponent = (props: SVGProps<SVGSVGElement>) => (
<svg
xmlns="http://www.w3.org/2000/svg"
width={20}
height={21}
height={20}
fill="none"
{...props}
>
Expand Down
Binary file added src/assets/icons/arrow-down-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 45 additions & 18 deletions src/common/modals/ClaimModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ import { formatEther } from 'ethers';
import tw, { styled } from 'twin.macro';
import { WinnerDeclarationContainer } from './types';
import { NormalText, SmallText } from '../../components/CreateGameCard/types';
import { ArrowDownIconV2, DownloadIcon } from '../../assets/icons';
import { DownloadIcon } from '../../assets/icons';
import arrowDown from '../../assets/icons/arrow-down-icon.png';
import { BadgeIcon, renderWagerBadge } from "../GameBar";
import { HexishString, Wega } from '../../models';
import { useBlockchainApiHooks, useTokenUSDValue } from '../../hooks';
import { miniWalletAddress, capitalize } from '../../utils';
import { HexishString, Wega, WegaState} from '../../models';
import { useTokenUSDValue } from '../../hooks';
import { useWithdrawMutation, useGetClaimAmountQuery } from './blockchainApiSlice';
import { useUpdateGameMutation } from '../../components/PlayGameSection/apiSlice';
import { miniWalletAddress, capitalize, toastSettings } from '../../utils';
import Button from '../Button';
import WalletAvatar from "../../common/WalletAvatar";

import toast from 'react-hot-toast';

// TODO add gas costs

Expand All @@ -19,15 +22,25 @@ export interface ClaimModalProps {
wallet: any;
}


export const ClaimModal = ({ hide, game, wallet
}: ClaimModalProps) => {
const {useClaimMutation} = useBlockchainApiHooks;
const {claim, isLoading: isClaimingLoading} = useClaimMutation();
const [feeAmountIndex, sendAmountIndex] = [0, 1]
const [claim, claimQuery] = useWithdrawMutation();
const [updateGame, ] = useUpdateGameMutation();

const calculateFeesQuery = useGetClaimAmountQuery({
escrowHash: game.wager.wagerHash as HexishString,
account: wallet.address
});
const handleClaimClick = async () => {
await claim(game.wager.wagerHash as HexishString).unwrap();
hide();
await claim({ escrowHash: game.wager.wagerHash as HexishString }).unwrap();
await updateGame({ uuid: game.uuid, state: WegaState.SETTLED }).unwrap();
toast.success('Withdraw success', { ...toastSettings('success', 'top-center') as any });
return hide();
};
const wagerUSDValue = useTokenUSDValue(game.wager.wagerCurrency, Number(formatEther(game.wager.wagerAmount)));
// console.log(feeTaker)
// console.log(game.wager)
return (
<WinnerDeclarationContainer tw="items-start p-[24px] gap-y-[16px] min-w-[340px]">
Expand Down Expand Up @@ -58,9 +71,7 @@ export const ClaimModal = ({ hide, game, wallet
</div>

<div tw="w-full flex justify-center">
<div tw="rounded-[100%] dark:bg-[#414141] flex justify-center">
<ArrowDownIconV2 />
</div>
<img src={arrowDown} alt="arrow" />
</div>

{/* bottom */}
Expand Down Expand Up @@ -94,7 +105,11 @@ export const ClaimModal = ({ hide, game, wallet
</div>
<div tw="flex flex-row items-end justify-between w-full">
<NormalText tw="dark:text-shinishi">Total claim before fees</NormalText>
<NormalText>{formatEther(game.wager.wagerAmount)} {game.wager.wagerCurrency}</NormalText>
{
!calculateFeesQuery.data ? 'calculating...' : <NormalText>{
Number(formatEther(calculateFeesQuery.data[feeAmountIndex])) + Number(formatEther(calculateFeesQuery.data[sendAmountIndex]))
} {game.wager.wagerCurrency}</NormalText>
}
</div>

{/* <div tw="flex flex-row items-end justify-between w-full">
Expand All @@ -107,23 +122,35 @@ export const ClaimModal = ({ hide, game, wallet
<div tw="w-full rounded-[4px] border border-[1px] border-shinishi p-[12px]">
<div tw="flex flex-row items-end justify-between w-full">
<NormalText tw="dark:text-shinishi">Platform fee (5%)</NormalText>
<NormalText>00.00 {game.wager.wagerCurrency}</NormalText>
{
!calculateFeesQuery.data ? 'calculating...' : <NormalText>{
formatEther(calculateFeesQuery.data[feeAmountIndex])
} {game.wager.wagerCurrency}</NormalText>
}
</div>
</div>
</div>

<div tw="self-start flex flex-row items-center gap-[10px] py-[8px] px-[5px]">
<div tw="w-full self-start flex flex-row items-center justify-between gap-[10px] py-[8px] px-[5px]">
<NormalText tw="dark:text-shinishi">You pay</NormalText>
<NormalText>{formatEther(game.wager.wagerAmount)} {game.wager.wagerCurrency}</NormalText>
{
!calculateFeesQuery.data ? 'calculating...' : <NormalText>{
formatEther(calculateFeesQuery.data[feeAmountIndex])
} {game.wager.wagerCurrency}</NormalText>
}
</div>

<div tw="self-start flex flex-row items-center justify-between gap-[10px] rounded-[5px] dark:bg-[#414141] py-[8px] px-[5px] w-full">
<NormalText tw="dark:text-shinishi">You receive</NormalText>
<NormalText>{formatEther(game.wager.wagerAmount)} {game.wager.wagerCurrency}</NormalText>
{
!calculateFeesQuery.data ? 'calculating...' : <NormalText>{
formatEther(calculateFeesQuery.data[sendAmountIndex])
} {game.wager.wagerCurrency}</NormalText>
}
</div>

<Button buttonType="primary" className="flex items-center justify-center w-full" onClick={() => handleClaimClick()} >
{ isClaimingLoading ? "Loading..." : "Claim" }
{ claimQuery.isLoading ? "Loading..." : "Claim" }
<DownloadIcon tw="h-[16px] w-[16px] ms-[5px] dark:stroke-blanc" />
</Button>
</WinnerDeclarationContainer>
Expand Down
Empty file removed src/common/modals/apiSlice.ts
Empty file.
39 changes: 39 additions & 0 deletions src/common/modals/blockchainApiSlice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { blockchainApiSlice } from '../../app/blockchainApiSlice';
import { HexishString } from '../../models';
import { ContractTypes } from '../../libs/wagmi';


// Todo
// write function names with type safety
export const modalsBlockchainApiSlice = blockchainApiSlice.injectEndpoints({
endpoints: (builder) => ({
calculateFeesForTransfer: builder.query<any, { feeApplier: HexishString, transferAmount: bigint }>({
query: ({ feeApplier, transferAmount }) => ({
functionName: 'calculateFeesForTransfer',
contract: ContractTypes.FEE_MANAGER,
method: 'READ',
args: [feeApplier, transferAmount]
})
}),
withdraw: builder.mutation<any, { escrowHash: HexishString }>({
query: ({ escrowHash }) => ({
functionName: 'withdraw',
contract: ContractTypes.ERC20ESCROW,
method: 'WRITE',
args: [escrowHash]
})
}),
getClaimAmount: builder.query<any, { escrowHash: HexishString, account: HexishString }>({
query: ({ escrowHash, account }) => ({
functionName: 'getClaimAmount',
contract: ContractTypes.ERC20ESCROW,
method: 'READ',
args: [escrowHash, account]
})
})
})
});

export const { useCalculateFeesForTransferQuery, useWithdrawMutation, useGetClaimAmountQuery } = modalsBlockchainApiSlice;


6 changes: 3 additions & 3 deletions src/components/CoinFlip/animations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function useRoll(coinRef: any, gameOver: boolean) {
}
const tl = gsap.timeline({ repeatDelay: 0, onComplete: callb })
tl.to("g#all-sides", {
repeat: 10,
repeat: 5,
ease: "none",
y: "300",
})
Expand All @@ -36,14 +36,14 @@ export function useRoll(coinRef: any, gameOver: boolean) {
roll(animationTarget);
}
if(gameOver) {
setTimeout(() => setRolled(true), 2000);
setTimeout(() => setRolled(true), 4000);
}
}, coinRef);
return () => ctx.revert();
}, [trigger, gameOver]);
return {
triggerRoll,
rolled
rolled,
}
}

1 change: 0 additions & 1 deletion src/components/Dice/animations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export function useRoll(diceRef: any, onBegin?: Callback, onEnd?: Callback) {


function roll(to: string) {
console.log('ROLLING TO', to);
if(onBegin) onBegin();
const callb = () => {
gsap.fromTo("g#all-sides", {
Expand Down
2 changes: 1 addition & 1 deletion src/containers/Navigation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const Navigation = () => {

return (
<NavigationBar tw="font-primary">
<div tw="relative z-[9950] container dark:text-blanc flex w-full py-[20px] px-[20px] justify-center items-end">
<div tw="relative z-[950] container dark:text-blanc flex w-full py-[20px] px-[20px] justify-center items-end">
<NavigationLinksContainer tw="box-border flex w-full gap-x-[30px]">
<BrandContainer tw="mb-[4px]">
<div tw="mr-5">
Expand Down
6 changes: 3 additions & 3 deletions src/containers/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const NavigationBar = styled.nav`
right: 0;
left: 0;
transition: transform 500ms ease-out 100ms;
z-index: 10000;
z-index: 1000;
&.nav-show {
transform: initial;
&::after {
Expand All @@ -76,7 +76,7 @@ export const NavigationBar = styled.nav`
right: 0;
width: 100%;
height: 100%;
${tw`bg-pretu bg-opacity-90 z-[7500] shadow-wega-nav`}
${tw`bg-pretu bg-opacity-90 z-[750] shadow-wega-nav`}
// filter: blur(1rem);
// -webkit-filter: blur(1rem);
opacity: 0;
Expand All @@ -93,7 +93,7 @@ export const NavigationBar = styled.nav`
opacity: 0;
// filter: blur(1rem);
// -webkit-filter: blur(1rem);
${tw`z-[7450] bg-pretu bg-opacity-95`}
${tw`z-[745] bg-pretu bg-opacity-95`}
transition: all 500ms ease-out 60ms;
}
&.nav-hide {
Expand Down
5 changes: 3 additions & 2 deletions src/containers/WinsPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const WinsPage = () => {
<MainContainer tw="min-h-[100vh] w-[50vw]">
<Section
direction='col'
tw="w-full"
hdr={
<SectionHeaderContainer tw="flex-col items-center">
<SectionHeaderTitle>Claim wins</SectionHeaderTitle>
Expand All @@ -39,14 +40,14 @@ const WinsPage = () => {
</Section>
{
wallet && wallet?.isConnected && network && network.id ?
(<div tw="flex flex-col gap-y-[80px]">
(<div tw="flex flex-col gap-y-[80px] w-full">
<ClaimWinsTokenSection networkId={network.id} userWalletAddress={wallet?.address} gamesCount={gamesCount ?? 0} tw="w-full"/>
<ClaimNFTWinsSection gameIds={[]} tw="w-full" />
<ClaimOnOtherNetworkSection tw="w-full"/>
</div>)
: (
<>
<ClaimWinsDisconnectedUserSection gameIds={[]}/>
<ClaimWinsDisconnectedUserSection gameIds={[]} tw="w-full"/>
<ClaimNFTWinsSection gameIds={[]} tw="mt-[80px] w-full" />
</>
)
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useCreateGameParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export function useCreateGameParams({
useEffect(() => {
if(wallet && wallet.isConnected && user && network) {
if(!(getTokenAddress() && getPlayerAddress() && getUserUuid())) {
setTokenAddress(SupportedWagerTokenAddresses(network?.id as number)[currencyType]);
setTokenAddress(SupportedWagerTokenAddresses[currencyType][network?.id as number] as HexishString);
setPlayerAddress(wallet.address as HexishString);
setUserUuid(user.uuid as string);
}
} else {
if(getTokenAddress() && getPlayerAddress() && getUserUuid()) {
setTokenAddress(SupportedWagerTokenAddresses(network?.id as number)[currencyType]);
setTokenAddress(SupportedWagerTokenAddresses[currencyType][network?.id as number] as HexishString);
setPlayerAddress(undefined);
setUserUuid(undefined);
}
Expand Down
Loading

0 comments on commit 04f4899

Please sign in to comment.