Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken Master Ticket process with WalletConnect on L1 #1129

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions src/lib/useWalletConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ import { isGoerli } from './flags';
import { ITxData } from './types/ITxData';
import { mayCreateHexString } from './utils/hex';

type PeerMeta = {
description: string;
icons?: string[];
name: string;
url: string;
};

type PersonalSign = {
message: string;
address: string;
Expand All @@ -42,20 +35,17 @@ export const useWalletConnect = () => {

const [connector, setConnector] = useState<SignClient | null>(null);
const [address, setAddress] = useState<string | null>(null);
const [peerMeta, setPeerMeta] = useState<PeerMeta | null>(null);
const [session, setSession] = useState<SessionTypes.Struct | null>(null);
const [modal, setModal] = useState<Web3Modal | null>(null);

const resetSession = () => {
setSession(null);
setAddress(null);
setPeerMeta(null);
};

const updateSession = (_session: SessionTypes.Struct) => {
setSession(_session);
setAddress(_session.namespaces.eip155.accounts[0].slice(9));
setPeerMeta(_session.peer.metadata);
};

const initConnector = async () => {
Expand Down Expand Up @@ -195,15 +185,17 @@ export const useWalletConnect = () => {
};

const peerIcon = useMemo(() => {
if (!peerMeta?.icons) {
if (!session?.peer?.metadata?.icons) {
return null;
}

// Some peers return a list of empty string(s) :)
const iconCandidates = peerMeta.icons.filter(pm => pm !== '');
const iconCandidates = session?.peer?.metadata?.icons.filter(
pm => pm !== ''
);

return iconCandidates.length > 0 ? iconCandidates[0] : null;
}, [peerMeta]);
}, [session]);

const signTransaction = async ({
from,
Expand All @@ -221,7 +213,7 @@ export const useWalletConnect = () => {
}

// Ledger Live needs to use fakeSign instead since it sends the txn upon signing
if (peerMeta?.name === 'Ledger Wallet') {
if (session?.peer?.metadata?.name === 'Ledger Wallet') {
reject(new Error('METHOD_NOT_SUPPORTED'));
return;
}
Expand Down Expand Up @@ -315,8 +307,7 @@ export const useWalletConnect = () => {
// Event handlers

const onSessionDelete = () => {
setAddress(null);
setPeerMeta(null);
resetSession();
resetWallet();
};

Expand Down Expand Up @@ -348,10 +339,10 @@ export const useWalletConnect = () => {
authenticate,
connect,
connector,
session,
disconnect,
isConnected,
peerIcon,
peerMeta,
initConnector,
signTransaction,
sendTransaction,
Expand Down
128 changes: 0 additions & 128 deletions src/views/Login/Metamask.jsx

This file was deleted.

4 changes: 0 additions & 4 deletions src/views/Login/Other.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import React, { useState } from 'react';
import { Icon } from '@tlon/indigo-react';

import Metamask from './Metamask';
import Ticket from './Ticket';
import Mnemonic from './Mnemonic';
import WalletConnect from './WalletConnect';
import LoginSelector from './LoginSelector';
import { ReactComponent as MetamaskIcon } from 'assets/metamask.svg';
import { ReactComponent as WalletConnectIcon } from 'assets/wallet-connect.svg';
Expand All @@ -17,9 +15,7 @@ export const NAMES = {
};

const VIEWS = {
[NAMES.METAMASK]: Metamask,
[NAMES.MNEMONIC]: Mnemonic,
[NAMES.WALLET_CONNECT]: WalletConnect,
[NAMES.MASTER_TICKET]: Ticket,
};

Expand Down
123 changes: 0 additions & 123 deletions src/views/Login/WalletConnect.tsx

This file was deleted.

Loading