Skip to content

Commit

Permalink
#245: add network check sepolia
Browse files Browse the repository at this point in the history
  • Loading branch information
lauchaves authored and lauchaves committed Jul 25, 2024
1 parent 63b9ef2 commit eb625d1
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions JoyboyCommunity/src/modules/TipModal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {NDKEvent} from '@nostr-dev-kit/ndk';
import {useAccount} from '@starknet-react/core';
import {forwardRef, useState} from 'react';
import {forwardRef, useState, useEffect} from 'react';
import {View} from 'react-native';
import {CallData, uint256} from 'starknet';

import {Avatar, Button, Input, Modalize, Picker, Text} from '../../components';
import {ESCROW_ADDRESSES} from '../../constants/contracts';
import {CHAIN_ID} from '../../constants/env';
import {CHAIN_ID, NETWORK_NAME} from '../../constants/env';
import {DEFAULT_TIMELOCK, Entrypoint} from '../../constants/misc';
import {TOKENS, TokenSymbol} from '../../constants/tokens';
import {useProfile, useStyles, useWaitConnection} from '../../hooks';
Expand All @@ -16,6 +16,7 @@ import {useTransaction} from '../../hooks/modals/useTransaction';
import {useWalletModal} from '../../hooks/modals/useWalletModal';
import {TipSuccessModalProps} from '../TipSuccessModal';
import stylesheet from './styles';
import {sepolia, mainnet} from '@starknet-react/chains';

export type TipModal = Modalize;

Expand Down Expand Up @@ -45,6 +46,26 @@ export const TipModal = forwardRef<Modalize, TipModalProps>(

const {showDialog, hideDialog} = useDialog();

useEffect(() => {
const handleChainIdChange = () => {
const chainId = account.chainId;
const currentChainId = NETWORK_NAME === 'SN_MAIN' ? mainnet.id : sepolia.id;

if (chainId === currentChainId) {
hideDialog();
} else if (chainId) {
showDialog({
title: 'Wrong Network',
description:
'Joyboy currently only supports the Starknet Sepolia network. Please switch to the Sepolia network to continue.',
buttons: [],
});
}
};

handleChainIdChange();
}, [account.chainId, hideDialog, showDialog]);

const isActive = !!amount && !!token;

const onTipPress = async () => {
Expand All @@ -55,6 +76,7 @@ export const TipModal = forwardRef<Modalize, TipModalProps>(
if (!result) return;
}


const amountUint256 = uint256.bnToUint256(
Math.ceil(Number(amount) * 10 ** TOKENS[token][CHAIN_ID].decimals),
);
Expand Down

0 comments on commit eb625d1

Please sign in to comment.