Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Commit

Permalink
Fix wallet Login
Browse files Browse the repository at this point in the history
  • Loading branch information
danielailie committed Sep 21, 2021
1 parent 5ae99c0 commit d41a4e7
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ const Header = () => {
};

const fetchWalletConnect = () => {
console.log('fetchWalletConnect');
if (getItem('walletConnectLogin') && !walletConnectAccount) {
console.log('isWalletConnect');
dispatch({
type: 'setWalletConnectAccount',
walletConnectAccount: address,
Expand Down
2 changes: 1 addition & 1 deletion react-delegationdashboard/src/context/reducer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export function reducer(state: StateType, action: ActionType): StateType {
}

default: {
throw new Error(`Unhandled action type: ${action!.type}`);
throw new Error(`Unhandled action type: ${action}`);
}
}
}
2 changes: 1 addition & 1 deletion react-delegationdashboard/src/context/state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,6 @@ export const initialState = (): {
}
: undefined,

walletConnectAccount: getItem('address'),
walletConnectAccount: getItem('walletConnectLogin') ? getItem('address') : undefined,
};
};
2 changes: 1 addition & 1 deletion react-delegationdashboard/src/helpers/useDelegation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function useDelegation({
if (e.message === 'cancel') {
setTransactionError('Transaction Cancelled');
}

console.error(`${transactionArguments.type}`, e);
});
};
Expand Down
48 changes: 23 additions & 25 deletions react-delegationdashboard/src/pages/Home/Login/Wallet.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Address } from '@elrondnetwork/erdjs';
import { Address, WalletProvider } from '@elrondnetwork/erdjs';
import React, { useEffect } from 'react';
import { useContext, useDispatch } from 'context';
import { getItem, removeItem, setItem } from 'storage/session';
import { AccountType } from 'helpers/contractDataDefinitions';
import { useLocation } from 'react-router-dom';
import { network } from 'config';

const WalletLogin = () => {
const dispatch = useDispatch();
Expand Down Expand Up @@ -39,31 +40,28 @@ const WalletLogin = () => {
dispatch({ type: 'loading', loading: false });
return;
}

if (getItem('wallet_login')) {
console.log('wallet');
const urlSearchParams = new URLSearchParams(search);
const params = Object.fromEntries(urlSearchParams as any);
const address = params?.address;
if (address !== undefined && new Address(params.address)) {
removeItem('wallet_login');
dispatch({ type: 'login', address });
dapp.proxy
.getAccount(new Address(address))
.then(account =>
dispatch({
type: 'setAccount',
account: new AccountType(account.balance.toString(), account.nonce),
})
)
.catch(err => {
console.log({ err });
dispatch({ type: 'loading', loading: false });
});
}
dispatch({ type: 'loading', loading: false });
return;
const urlSearchParams = new URLSearchParams(search);
const params = Object.fromEntries(urlSearchParams as any);
const address = params?.address;
if (address !== undefined && new Address(params.address)) {
removeItem('wallet_login');
dispatch({ type: 'login', address });
dapp.proxy
.getAccount(new Address(address))
.then(account =>
dispatch({
type: 'setAccount',
account: new AccountType(account.balance.toString(), account.nonce),
})
)
.catch(err => {
console.log({ err });
dispatch({ type: 'loading', loading: false });
});
}
removeItem('wallet_login');
dispatch({ type: 'loading', loading: false });
return;
});
}
};
Expand Down

0 comments on commit d41a4e7

Please sign in to comment.