Skip to content

Commit b08d6aa

Browse files
authored
APIs connect (#65)
* Wallet connect fix * Connect to apis without wallet connect * lint fix
1 parent cfe1509 commit b08d6aa

File tree

3 files changed

+16
-37
lines changed

3 files changed

+16
-37
lines changed

src/components/Header/index.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from '@mui/material';
1010
import { useInkathon } from '@scio-labs/use-inkathon';
1111
import Image from 'next/image';
12-
import React, { useState } from 'react';
12+
import React, { useEffect, useState } from 'react';
1313

1414
import Logo from '@/assets/logo.png';
1515
import { useCoretimeApi, useRelayApi } from '@/contexts/apis';
@@ -20,16 +20,20 @@ import { WalletModal } from '../Modals/WalletConnect';
2020
export const Header = () => {
2121
const { activeAccount, disconnect, accounts, setActiveAccount } =
2222
useInkathon();
23-
const { disconnectRelay } = useRelayApi();
24-
const { disconnectCoretime } = useCoretimeApi();
2523
const [accountsOpen, openAccounts] = useState(false);
2624
const [walletModalOpen, openWalletModal] = useState(false);
2725

26+
const { connectRelay } = useRelayApi();
27+
const { connectCoretime } = useCoretimeApi();
28+
29+
useEffect(() => {
30+
connectRelay();
31+
connectCoretime();
32+
}, [connectRelay, connectCoretime]);
33+
2834
const onDisconnect = () => {
2935
openAccounts(false);
3036
disconnect && disconnect();
31-
disconnectRelay();
32-
disconnectCoretime();
3337
};
3438

3539
return (

src/components/Modals/WalletConnect/index.tsx

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,9 @@ import {
77
List,
88
ListItemButton,
99
} from '@mui/material';
10-
import { isWalletInstalled } from '@scio-labs/use-inkathon';
11-
import {
12-
allSubstrateWallets,
13-
SubstrateWallet,
14-
useInkathon,
15-
} from '@scio-labs/use-inkathon';
10+
import { isWalletInstalled,SubstrateWallet } from '@scio-labs/use-inkathon';
11+
import { allSubstrateWallets, useInkathon } from '@scio-labs/use-inkathon';
1612
import Image from 'next/image';
17-
import { useEffect, useState } from 'react';
18-
19-
import { useCoretimeApi, useRelayApi } from '@/contexts/apis';
2013

2114
import styles from './index.module.scss';
2215

@@ -26,31 +19,13 @@ interface WalletModalProps {
2619
}
2720

2821
export const WalletModal = (props: WalletModalProps) => {
29-
const {
30-
connect: connectContract,
31-
activeChain,
32-
isInitialized,
33-
} = useInkathon();
34-
const { connectRelay } = useRelayApi();
35-
const { connectCoretime } = useCoretimeApi();
22+
const { connect } = useInkathon();
3623

37-
const [wallet, setWallet] = useState<SubstrateWallet | null>(null);
38-
39-
const onConnect = async (wallet: SubstrateWallet) => {
40-
setWallet(wallet);
41-
if (!connectContract) return;
42-
connectRelay();
43-
connectCoretime();
44-
connectContract(activeChain, wallet);
24+
const onConnect = (wallet: SubstrateWallet) => {
25+
connect?.(undefined, wallet);
4526
props.onClose();
4627
};
4728

48-
useEffect(() => {
49-
if (wallet) {
50-
onConnect(wallet);
51-
}
52-
}, [isInitialized]);
53-
5429
return (
5530
<Dialog {...props} fullWidth maxWidth='sm'>
5631
<DialogTitle>Choose your wallet extension</DialogTitle>

src/contexts/common/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ const ContextDataProvider = ({ children }: Props) => {
3333

3434
useEffect(() => {
3535
const collectContextData = async () => {
36-
if (!relayConnected) return;
36+
if (!relayConnected || !relayApi.query.system) return;
3737
const currentBlockHeight = parseHNString(
3838
(await relayApi.query.system.number()).toString()
3939
);
4040
setRelayBlockNumber(currentBlockHeight);
4141

42-
if (!coretimeConnected) return;
42+
if (!coretimeConnected || !coretimeApi.consts.broker) return;
4343

4444
const timeslicePeriod = parseHNString(
4545
coretimeApi.consts.broker.timeslicePeriod.toString()

0 commit comments

Comments
 (0)