Wager
- {formatLowerDecimalTokenValue(wagerAmount, tokenDecimals)}
+ {Number(parseFloat(formatUnits(BigInt(wagerAmount), tokenDecimals)).toFixed(0))}
<>{renderWagerBadge(currentWagerType, currentCurrencyType)}>
{currencyType}
diff --git a/src/components/JoinGameCard/JoinDiceGamecard.tsx b/src/components/JoinGameCard/JoinDiceGamecard.tsx
index 79d6fa6..5ccdb32 100644
--- a/src/components/JoinGameCard/JoinDiceGamecard.tsx
+++ b/src/components/JoinGameCard/JoinDiceGamecard.tsx
@@ -38,16 +38,16 @@ import toast from 'react-hot-toast';
import {
toastSettings,
escrowConfig,
- formatLowerDecimalTokenValue,
convertBytesToNumber,
- parseError,
- exponentialToBigintInWei
+ parseError
} from '../../utils';
import Button from '../../common/Button';
import { useFormReveal } from '../CreateGameCard/animations';
import { useJoinGameMutation, useUpdateGameMutation } from './apiSlice';
import { JoinGameCardProps } from './'
import { ComponentLoader } from '../../common/loaders'
+import { formatUnits, toBigInt } from 'ethers';
+
export interface JoinDiceGameCardProps extends JoinGameCardProps, React.Attributes, React.AllHTMLAttributes
{};
@@ -71,27 +71,24 @@ const JoinGameDiceCard: React.FC = ({
const detailsBlock = useRef(null)
const [currentWagerType] = useState(wagerType);
const [currentCurrencyType] = useState(currencyType);
- const {tokenAddress, playerAddress, playerUuid, tokenDecimals } = useCreateGameParams({ wallet, user, network, currencyType: currentCurrencyType }); // TODO change to generic name
+ const {tokenAddress, playerAddress, playerUuid, tokenDecimals } = useCreateGameParams({ wallet, user, network, currencyType: currentCurrencyType });
const {revealed, triggerRevealAnimation} = useFormReveal(false, formRef, detailsBlock);
// should go into blockchain api slice
const { formState: { errors }, handleSubmit, setValue, register } = useForm({
mode: 'onChange',
- resolver: joiResolver(createGameSchema('wager', formatLowerDecimalTokenValue(wagerAmount, tokenDecimals))) ,
+ resolver: joiResolver(createGameSchema('wager', Number(parseFloat(formatUnits(BigInt(wagerAmount), tokenDecimals)).toFixed(0)))) ,
reValidateMode: 'onChange',
defaultValues: {
- wager: tokenDecimals && formatLowerDecimalTokenValue(wagerAmount, tokenDecimals),
+ wager: tokenDecimals && Number(parseFloat(formatUnits(BigInt(wagerAmount), tokenDecimals)).toFixed(0)),
}
});
- const wagerUSDValue = useTokenUSDValue(currentCurrencyType, tokenDecimals && formatLowerDecimalTokenValue(wagerAmount, tokenDecimals));
+ const wagerUSDValue = useTokenUSDValue(currentCurrencyType, tokenDecimals && Number(parseFloat(formatUnits(BigInt(wagerAmount), tokenDecimals)).toFixed(0)));
// approval for allowance
- const isWagerApproved = (allowance: string | number, wagerAmount: number) => {
- return exponentialToBigintInWei(Number(allowance)) >= exponentialToBigintInWei(wagerAmount); // if decimals then the correct wei amount will be returned
- };
-
+ const isWagerApproved = (allowance: bigint, wagerAmount: bigint) => allowance >= wagerAmount;
const allowanceQuery = useAllowanceQuery({
spender: escrowConfig.address[network?.id as keyof typeof escrowConfig.address],
owner: playerAddress,
@@ -110,10 +107,10 @@ const JoinGameDiceCard: React.FC = ({
const [approveERC20, approveERC20Query] = useApproveERC20Mutation();
const handleDepositWagerClick = async () => {
try {
- if(!isWagerApproved(allowanceQuery.data, wagerAmount)) {
+ if(!isWagerApproved(allowanceQuery?.data, toBigInt(wagerAmount))) {
await approveERC20({
spender: escrowConfig.address[network?.id as keyof typeof escrowConfig.address],
- wagerAsBigint: exponentialToBigintInWei(wagerAmount),
+ wagerAsBigint: toBigInt(wagerAmount),
tokenAddress
}).unwrap();
}
@@ -135,7 +132,7 @@ const JoinGameDiceCard: React.FC = ({
const navigateToGameUi = useNavigateTo()
useEffect(() => {
allowanceQuery.refetch();
- if(tokenDecimals) setValue('wager', formatLowerDecimalTokenValue(wagerAmount, tokenDecimals))
+ if(tokenDecimals) setValue('wager', Number(parseFloat(formatUnits(BigInt(wagerAmount), tokenDecimals)).toFixed(0)))
}, [
tokenAddress,
playerAddress,
@@ -159,7 +156,7 @@ const JoinGameDiceCard: React.FC = ({
{/* wager */}
-
+
= ({
Wager
- {formatLowerDecimalTokenValue(wagerAmount, tokenDecimals)}
+ {Number(parseFloat(formatUnits(BigInt(wagerAmount), tokenDecimals)).toFixed(0))}
<>{renderWagerBadge(currentWagerType, currentCurrencyType)}>
{currencyType}
diff --git a/src/components/JoinGameCard/index.tsx b/src/components/JoinGameCard/index.tsx
index ebf3397..8748147 100644
--- a/src/components/JoinGameCard/index.tsx
+++ b/src/components/JoinGameCard/index.tsx
@@ -9,12 +9,13 @@ import {
} from "../../models";
import JoinDiceGameCard from './JoinDiceGamecard';
import JoinCoinFlipGameCard from './JoinCoinFlipGameCard';
+import { BigNumberish } from "ethers";
export interface JoinGameCardProps extends React.Attributes, React.AllHTMLAttributes
{
wagerType: AllPossibleWagerTypes;
currencyType: AllPossibleCurrencyTypes;
gameType: AllPossibleWegaTypes;
- wagerAmount: number;
+ wagerAmount: BigNumberish;
gameUuid: string;
escrowId: HexishString;
gameId: number;
diff --git a/src/components/PlayGamePlayerCard/index.tsx b/src/components/PlayGamePlayerCard/index.tsx
index 09607dc..b64ad25 100644
--- a/src/components/PlayGamePlayerCard/index.tsx
+++ b/src/components/PlayGamePlayerCard/index.tsx
@@ -111,7 +111,7 @@ const DicePlayerCard: React.FC = ({
Wager:
- {format(wager.wagerAmount, tokenDecimals as number)}
+ {parseFloat(format(wager.wagerAmount, tokenDecimals as number)).toFixed(0)}
{renderWagerBadge(wager.wagerType, wager.wagerCurrency)}
{wager.wagerCurrency}
@@ -179,7 +179,7 @@ const CoinFlipPlayerCard: React.FC
= ({
Wager:
- {format(wager.wagerAmount, tokenDecimals as number)}
+ {parseFloat(format(wager.wagerAmount, tokenDecimals as number)).toFixed(0)}
{renderWagerBadge(wager.wagerType, wager.wagerCurrency)}
{wager.wagerCurrency}
diff --git a/src/components/PlayGameSection/PlayCoinFlipGameSection.tsx b/src/components/PlayGameSection/PlayCoinFlipGameSection.tsx
index c8248ca..2adf53e 100644
--- a/src/components/PlayGameSection/PlayCoinFlipGameSection.tsx
+++ b/src/components/PlayGameSection/PlayCoinFlipGameSection.tsx
@@ -74,6 +74,7 @@ const PlayCoinFlipGameSection: React.FC
= ({
wagerType: game.wager.wagerType,
wagerAmount: game.wager.wagerAmount,
gameType: game.gameType,
+ networkId: game.networkId,
playerFlipChoices,
hide: hideModal
})
@@ -84,6 +85,7 @@ const PlayCoinFlipGameSection: React.FC = ({
wagerType: game.wager.wagerType,
wagerAmount: game.wager.wagerAmount,
gameType: game.gameType,
+ networkId: game.networkId,
winnerFlipChoice: [playerFlipChoices.playerOne as AllPossibleCoinSides, playerFlipChoices.playerTwo as AllPossibleCoinSides][indexOfMaxValue],
loserFlipChoice: [playerFlipChoices.playerOne as AllPossibleCoinSides, playerFlipChoices.playerTwo as AllPossibleCoinSides][indexOfMaxValue === 1 ? 0 : 1],
hide: hideModal
@@ -91,6 +93,7 @@ const PlayCoinFlipGameSection: React.FC = ({
} else {
showModal(MODAL_TYPES.COINFLIP_LOSER_MODAL, {
gameType: game.gameType,
+ networkId: game.networkId,
winnerFlipChoice: [playerFlipChoices.playerOne as AllPossibleCoinSides, playerFlipChoices.playerTwo as AllPossibleCoinSides][indexOfMaxValue],
loserFlipChoice: [playerFlipChoices.playerOne as AllPossibleCoinSides, playerFlipChoices.playerTwo as AllPossibleCoinSides][indexOfMaxValue === 1 ? 0 : 1],
hide: hideModal
diff --git a/src/components/PlayGameSection/PlayDiceGameSection.tsx b/src/components/PlayGameSection/PlayDiceGameSection.tsx
index 9e44b92..78eecc3 100644
--- a/src/components/PlayGameSection/PlayDiceGameSection.tsx
+++ b/src/components/PlayGameSection/PlayDiceGameSection.tsx
@@ -97,6 +97,7 @@ const PlayDiceGameSection: React.FC= ({
wagerType: game.wager.wagerType,
wagerAmount: game.wager.wagerAmount,
gameType: game.gameType,
+ networkId: game.networkId,
results: getWinnerAndLoserResults(),
hide: hideModal,
});
@@ -107,6 +108,7 @@ const PlayDiceGameSection: React.FC= ({
wagerType: game.wager.wagerType,
wagerAmount: game.wager.wagerAmount,
gameType: game.gameType,
+ networkId: game.networkId,
results: getWinnerAndLoserResults(),
hide: hideModal,
});
@@ -114,6 +116,7 @@ const PlayDiceGameSection: React.FC= ({
showModal(MODAL_TYPES.DICE_LOSER_MODAL, {
gameType: game.gameType,
results: getWinnerAndLoserResults(),
+ networkId: game.networkId,
hide: hideModal,
});
}
diff --git a/src/components/PlayGameSection/index.tsx b/src/components/PlayGameSection/index.tsx
index 71a5bfa..37638f9 100644
--- a/src/components/PlayGameSection/index.tsx
+++ b/src/components/PlayGameSection/index.tsx
@@ -64,6 +64,7 @@ const PlayGameSection: React.FC = ({
escrowHash: escrowHash as HexishString,
},);
useEffect(() => {
+ console.log(players)
gameResultsQuery.refetch();
refetchGameWinners()
}, [players.length]);
diff --git a/src/components/WegaGames/index.tsx b/src/components/WegaGames/index.tsx
index d9a9ae5..e9b626e 100644
--- a/src/components/WegaGames/index.tsx
+++ b/src/components/WegaGames/index.tsx
@@ -84,6 +84,7 @@ export const PlayableGames: React.FC = ({ gamesCo
setGameIds(sortedGameIds ?? []);
}
}, [data, gamesCount, isSuccess, defaultNetwork?.id]);
+
return !isLoading ? (
Date created
@@ -102,7 +103,7 @@ export interface ClaimableGamesProps extends React.Attributes, React.HTMLAttribu
userWalletAddress: HexishString;
gamesCount: number;
networkId: number;
- }
+}
export const ClaimableGames: React.FC = ({ gamesCount, userWalletAddress, networkId, ...rest }: ClaimableGamesProps) => {
const { data, isLoading, isSuccess } = useGetGamesQuery({ state: WegaState.COMPLETED, winners: userWalletAddress, networkId: networkId ?? defaultNetwork?.id });
const [sortedGames, setSortedGames] = useState();
diff --git a/src/containers/JoinGamePage/index.tsx b/src/containers/JoinGamePage/index.tsx
index aa76073..071f6ed 100644
--- a/src/containers/JoinGamePage/index.tsx
+++ b/src/containers/JoinGamePage/index.tsx
@@ -9,7 +9,6 @@ import { useParams } from 'react-router-dom';
import MainContainer from '../../components/MainContainer';
import { BADGE_TEXTS } from "../../common/JoinableGameBar";
import { FloatingOrbs } from "../../common/FloatingOrbs"
-import { formatEther } from 'ethers';
import 'twin.macro';
const JoinGamePage = () => {
@@ -33,7 +32,7 @@ const JoinGamePage = () => {
wagerType={game.wager.wagerType}
currencyType={game.wager.wagerCurrency}
gameType={game.gameType.toUpperCase() as AllPossibleWegaTypes}
- wagerAmount={Number(formatEther(game.wager.wagerAmount))}
+ wagerAmount={game.wager.wagerAmount}
gameUuid={game.uuid}
escrowId={game.wager.wagerHash as HexishString}
gameId={game.id}
diff --git a/src/utils/abis.ts b/src/utils/abis.ts
index 85a090e..800a696 100644
--- a/src/utils/abis.ts
+++ b/src/utils/abis.ts
@@ -1,4 +1,4 @@
-// Generated by @wagmi/cli@1.3.0 on 12/5/2023 at 3:08:33 PM
+// Generated by @wagmi/cli@1.3.0 on 12/6/2023 at 5:46:37 PM
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// AccessControlUpgradeable
@@ -521,7 +521,7 @@ export const enumerableMapABI = [
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
- * - [__View Contract on Polygon Polygon Scan__](https://polygonscan.com/address/0xE38d4530337a45C6D0C061f108e5AF040FCC175c)
+ * - [__View Contract on Polygon Polygon Scan__](https://polygonscan.com/address/0x679e91BAb4fA83c5d0543c460A41CEc52E6A6fd1)
* -
* - [__View Contract on Polygon Mumbai Polygon Scan__](https://mumbai.polygonscan.com/address/0xc392D90803D462Ac5395A76d59AB942a8d9DCe69)
* - [__View Contract on Skale Calypso Nft Hub Testnet Skale Explorer__](https://staging-utter-unripe-menkar.explorer.staging-v3.skalenodes.com/address/0x0000000000000000000000000000000000000000)
@@ -860,20 +860,20 @@ export const feeManagerABI = [
] as const
/**
- * - [__View Contract on Polygon Polygon Scan__](https://polygonscan.com/address/0xE38d4530337a45C6D0C061f108e5AF040FCC175c)
+ * - [__View Contract on Polygon Polygon Scan__](https://polygonscan.com/address/0x679e91BAb4fA83c5d0543c460A41CEc52E6A6fd1)
* -
* - [__View Contract on Polygon Mumbai Polygon Scan__](https://mumbai.polygonscan.com/address/0xc392D90803D462Ac5395A76d59AB942a8d9DCe69)
* - [__View Contract on Skale Calypso Nft Hub Testnet Skale Explorer__](https://staging-utter-unripe-menkar.explorer.staging-v3.skalenodes.com/address/0x0000000000000000000000000000000000000000)
*/
export const feeManagerAddress = {
- 137: "0xE38d4530337a45C6D0C061f108e5AF040FCC175c",
+ 137: "0x679e91BAb4fA83c5d0543c460A41CEc52E6A6fd1",
1337: "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0",
80001: "0xc392D90803D462Ac5395A76d59AB942a8d9DCe69",
344106930: "0x0000000000000000000000000000000000000000"
} as const
/**
- * - [__View Contract on Polygon Polygon Scan__](https://polygonscan.com/address/0xE38d4530337a45C6D0C061f108e5AF040FCC175c)
+ * - [__View Contract on Polygon Polygon Scan__](https://polygonscan.com/address/0x679e91BAb4fA83c5d0543c460A41CEc52E6A6fd1)
* -
* - [__View Contract on Polygon Mumbai Polygon Scan__](https://mumbai.polygonscan.com/address/0xc392D90803D462Ac5395A76d59AB942a8d9DCe69)
* - [__View Contract on Skale Calypso Nft Hub Testnet Skale Explorer__](https://staging-utter-unripe-menkar.explorer.staging-v3.skalenodes.com/address/0x0000000000000000000000000000000000000000)
diff --git a/src/utils/ethers-helpers.ts b/src/utils/ethers-helpers.ts
index 0a1c214..80a328d 100644
--- a/src/utils/ethers-helpers.ts
+++ b/src/utils/ethers-helpers.ts
@@ -15,8 +15,12 @@ export function parseIntFromBigNumber(val: BigNumberish | number) {
}
return val;
}
-export function exponentialToBigintInWei(val: number): bigint {
- return toBigIntInWei(Number.parseFloat(String(val)).toFixed(18) as string);
+export function exponentialToBigintInWei(val: number, decimals?: number): bigint {
+ if(decimals && decimals !== 18) {
+ return toBigIntInWei(Number.parseFloat(String(val)).toFixed(18) as string);
+ } else {
+ return toBigIntInWei(Number.parseFloat(String(val)).toString());
+ }
}
export function formatLowerDecimalTokenValue(value: number, tokenDecimals: number) {
@@ -46,6 +50,16 @@ export function parseTopicDataFromEventLog(txLog: { data: string, topics: Array<
return interfaceIdFromAbi(eventAbi).parseLog({ data: txLog.data, topics: txLog.topics })?.args.toObject();
}
+export function parseTopicDataFromEventLogs(txLogs: ({ data: string, topics: Array })[], eventAbi: string[]){
+ let parsedData: any | undefined = undefined;
+ let i = 0;
+ while(!parsedData?.escrowHash) {
+ parsedData = interfaceIdFromAbi(eventAbi).parseLog({ data: txLogs[i].data, topics: txLogs[i].topics })?.args.toObject();
+ i++;
+ }
+ return parsedData
+}
+
export function isGameCreator(
connectedPlayerUUid: string | undefined,
players: Player | any,
diff --git a/src/utils/index.ts b/src/utils/index.ts
index 52589d6..fe244e9 100644
--- a/src/utils/index.ts
+++ b/src/utils/index.ts
@@ -5,6 +5,7 @@ export {
miniWalletAddress,
toBigIntInWei,
parseTopicDataFromEventLog,
+ parseTopicDataFromEventLogs,
interfaceIdFromAbi,
convertBytesToNumber,
format,