Skip to content

Commit

Permalink
APIs connect (#65)
Browse files Browse the repository at this point in the history
* Wallet connect fix

* Connect to apis without wallet connect

* lint fix
  • Loading branch information
Szegoo authored Apr 11, 2024
1 parent cfe1509 commit b08d6aa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 37 deletions.
14 changes: 9 additions & 5 deletions src/components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();
}, [connectRelay, connectCoretime]);

const onDisconnect = () => {
openAccounts(false);
disconnect && disconnect();
disconnectRelay();
disconnectCoretime();
};

return (
Expand Down
35 changes: 5 additions & 30 deletions src/components/Modals/WalletConnect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 { isWalletInstalled,SubstrateWallet } 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';

Expand All @@ -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<SubstrateWallet | null>(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 (
<Dialog {...props} fullWidth maxWidth='sm'>
<DialogTitle>Choose your wallet extension</DialogTitle>
Expand Down
4 changes: 2 additions & 2 deletions src/contexts/common/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit b08d6aa

Please sign in to comment.