From 126f7a0e7673db4e082ece9aae8f5b36e52b0d5d Mon Sep 17 00:00:00 2001 From: Sergej Date: Thu, 11 Apr 2024 10:30:02 +0200 Subject: [PATCH 1/3] Wallet connect fix --- src/components/Modals/WalletConnect/index.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/Modals/WalletConnect/index.tsx b/src/components/Modals/WalletConnect/index.tsx index 7338f680..b7ec4764 100644 --- a/src/components/Modals/WalletConnect/index.tsx +++ b/src/components/Modals/WalletConnect/index.tsx @@ -26,7 +26,11 @@ interface WalletModalProps { } export const WalletModal = (props: WalletModalProps) => { - const { connect: connectContract, activeChain, isConnected } = useInkathon(); + const { + connect: connectContract, + activeChain, + isInitialized, + } = useInkathon(); const { connectRelay } = useRelayApi(); const { connectCoretime } = useCoretimeApi(); @@ -45,7 +49,7 @@ export const WalletModal = (props: WalletModalProps) => { if (wallet) { onConnect(wallet); } - }, [isConnected]); + }, [isInitialized]); return ( From 2d8c926465100910499a2bf9d32fa43299e15cc1 Mon Sep 17 00:00:00 2001 From: Sergej Date: Thu, 11 Apr 2024 11:50:38 +0200 Subject: [PATCH 2/3] Connect to apis without wallet connect --- src/components/Header/index.tsx | 14 +++++--- src/components/Modals/WalletConnect/index.tsx | 35 +++---------------- src/contexts/common/index.tsx | 4 +-- 3 files changed, 16 insertions(+), 37 deletions(-) diff --git a/src/components/Header/index.tsx b/src/components/Header/index.tsx index cd2dde75..1dc5737d 100644 --- a/src/components/Header/index.tsx +++ b/src/components/Header/index.tsx @@ -9,7 +9,7 @@ import { } from '@mui/material'; import { useInkathon } from '@scio-labs/use-inkathon'; import Image from 'next/image'; -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import Logo from '@/assets/logo.png'; import { useCoretimeApi, useRelayApi } from '@/contexts/apis'; @@ -20,16 +20,20 @@ import { WalletModal } from '../Modals/WalletConnect'; export const Header = () => { const { activeAccount, disconnect, accounts, setActiveAccount } = useInkathon(); - const { disconnectRelay } = useRelayApi(); - const { disconnectCoretime } = useCoretimeApi(); const [accountsOpen, openAccounts] = useState(false); const [walletModalOpen, openWalletModal] = useState(false); + const { connectRelay } = useRelayApi(); + const { connectCoretime } = useCoretimeApi(); + + useEffect(() => { + connectRelay(); + connectCoretime(); + }, []); + const onDisconnect = () => { openAccounts(false); disconnect && disconnect(); - disconnectRelay(); - disconnectCoretime(); }; return ( diff --git a/src/components/Modals/WalletConnect/index.tsx b/src/components/Modals/WalletConnect/index.tsx index b7ec4764..e0556907 100644 --- a/src/components/Modals/WalletConnect/index.tsx +++ b/src/components/Modals/WalletConnect/index.tsx @@ -7,16 +7,9 @@ import { List, ListItemButton, } from '@mui/material'; -import { isWalletInstalled } from '@scio-labs/use-inkathon'; -import { - allSubstrateWallets, - SubstrateWallet, - useInkathon, -} from '@scio-labs/use-inkathon'; +import { SubstrateWallet, isWalletInstalled } from '@scio-labs/use-inkathon'; +import { allSubstrateWallets, useInkathon } from '@scio-labs/use-inkathon'; import Image from 'next/image'; -import { useEffect, useState } from 'react'; - -import { useCoretimeApi, useRelayApi } from '@/contexts/apis'; import styles from './index.module.scss'; @@ -26,31 +19,13 @@ interface WalletModalProps { } export const WalletModal = (props: WalletModalProps) => { - const { - connect: connectContract, - activeChain, - isInitialized, - } = useInkathon(); - const { connectRelay } = useRelayApi(); - const { connectCoretime } = useCoretimeApi(); + const { connect } = useInkathon(); - const [wallet, setWallet] = useState(null); - - const onConnect = async (wallet: SubstrateWallet) => { - setWallet(wallet); - if (!connectContract) return; - connectRelay(); - connectCoretime(); - connectContract(activeChain, wallet); + const onConnect = (wallet: SubstrateWallet) => { + connect?.(undefined, wallet); props.onClose(); }; - useEffect(() => { - if (wallet) { - onConnect(wallet); - } - }, [isInitialized]); - return ( Choose your wallet extension diff --git a/src/contexts/common/index.tsx b/src/contexts/common/index.tsx index efc8ed03..e7f6c660 100644 --- a/src/contexts/common/index.tsx +++ b/src/contexts/common/index.tsx @@ -33,13 +33,13 @@ const ContextDataProvider = ({ children }: Props) => { useEffect(() => { const collectContextData = async () => { - if (!relayConnected) return; + if (!relayConnected || !relayApi.query.system) return; const currentBlockHeight = parseHNString( (await relayApi.query.system.number()).toString() ); setRelayBlockNumber(currentBlockHeight); - if (!coretimeConnected) return; + if (!coretimeConnected || !coretimeApi.consts.broker) return; const timeslicePeriod = parseHNString( coretimeApi.consts.broker.timeslicePeriod.toString() From 7c79ecd5a615cc81d2e65a831a1368ee4a55c33e Mon Sep 17 00:00:00 2001 From: Sergej Date: Thu, 11 Apr 2024 11:52:46 +0200 Subject: [PATCH 3/3] lint fix --- src/components/Header/index.tsx | 2 +- src/components/Modals/WalletConnect/index.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Header/index.tsx b/src/components/Header/index.tsx index 1dc5737d..5fa34d57 100644 --- a/src/components/Header/index.tsx +++ b/src/components/Header/index.tsx @@ -29,7 +29,7 @@ export const Header = () => { useEffect(() => { connectRelay(); connectCoretime(); - }, []); + }, [connectRelay, connectCoretime]); const onDisconnect = () => { openAccounts(false); diff --git a/src/components/Modals/WalletConnect/index.tsx b/src/components/Modals/WalletConnect/index.tsx index e0556907..92a4153f 100644 --- a/src/components/Modals/WalletConnect/index.tsx +++ b/src/components/Modals/WalletConnect/index.tsx @@ -7,7 +7,7 @@ import { List, ListItemButton, } from '@mui/material'; -import { SubstrateWallet, isWalletInstalled } from '@scio-labs/use-inkathon'; +import { isWalletInstalled,SubstrateWallet } from '@scio-labs/use-inkathon'; import { allSubstrateWallets, useInkathon } from '@scio-labs/use-inkathon'; import Image from 'next/image';