Skip to content
This repository was archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
#207/login improvements (#208)
Browse files Browse the repository at this point in the history
* updated action

* Feat/merge (#161)

* docs

* update version (#109)

* Revert "update version (#109)" (#110)

This reverts commit 72efce3.

* Fix docs (#105)

* Fix @link to correct class name

`EthersModalConnect` does not exist, I suppose you meant `EthersModalConnector`

* Fix incorrect markdown links

* Fix some confusing wording (probably copy paste leftovers)

Co-authored-by: Shravan Sunder <[email protected]>

* updated docs

* Feature/#96 eth-hook v4 initial dev (#103)

* #96 #94 #93 working on ContractContext.  Started eth context override

* #94 ethersContext overrides for hooks

* #94 ethersContext overrides for hooks.  enable secondary/alternate web3context

* #94 v3.4 will not have getters and setters

* #96 added comments

* fixing merge conflicts, disabled some tests temporarily, changed command name

* Update useGetUserFromSigners.ts

* Additionally #94 #102 Merge branch 'develop' into feature/#96

# Conflicts:
#	package.json
#	src/context/EthersAppContext.tsx
#	src/hooks/useBalance.ts
#	src/hooks/useContractExistsAtAddress.ts
#	src/hooks/useContractLoader.ts
#	src/hooks/useContractReader.ts
#	src/hooks/useGetUserFromProviders.ts
#	src/hooks/useGetUserFromSigners.ts

* update version (#111)

* #101 #94 updates for contracts context changes

* #101 #94 updates for contracts context changes

- created an contract context factory

* #101 #94 some work on generics for definitions

* #101 #94 typing for contracts and factory seems to be working

issues with app contract definition types

* #101 #94 moved some files around

* #101 #94 Finally go the contract typeing to work.  Now i need to work on the reducer

* #101 #94 moved logic from class into reducer

* #101 #94 checkpoint

* #101 #94 organization and refactoring of names and contractAppContext related files.

also renamed harness to wrapper

* #101 #94 more refactoring of types

* #101 #94 fixing types for the contract actions

* #101 #94 fixing types for the contract actions

* #101 #94 created hook and system to load contracts

* #95 added update tuples (getters).  Additionally updated useContractReader to be typed.

- left the old contractReader with untyped postfix
- removed useOnRepetition and updated useBlockNumber
- updated optional provider for many hooks
- removed useWeb3Modal

* #95 added update tuples (getters).

* #95 updated packages and fixed some bugs

* #95 updated yarn and set node version

* #95 refactoring and fixes

* #95 fixes for compatability of eht-hooks and components

* #95 #101 #94 bug fixes and manual testing

* #95 #101 #94 bug fixes and manual testing.  fixing issues with loading contracts in multiple networks

* #95 #101 #94 converted the context back into a reducer

* #95 #101 #94 changes to hook options.  found invariant-ts

* #95 #101 #94 fixed issues with loading contracts

* #95 #101 #94 fixed logs

* #95 #101 #94 fixed  bugs and removed async hook

Co-authored-by: Jaxcoder <[email protected]>

* Feature/#114 (#119)

* #114 integrated react-query and a caching layer for ethereum calls.  in useContractReader and useBalance

- Now ethereum data will be cached and reused based on
- you can now poll, or get data based on new blocks, or block number interval

* #114 updates to query namespace and query invalidation on contract connector load.  updated many hooks to new cached paradigm

* #114 bug fixes to new caching changes

* #114 event based updates.  changes to default options.  all hooks are up to date

* #114 minor bug fix

* #114 context changes.  TODO split apart options

* #114 seperated override from options

* #114 minor workaround for typechain array issue

* #114 better console logs

* #114 imporvements to keys and some hooks.  finished useGasPrice

* #114 new version

* #114 fixes to keys and connectors.  also auto connect for burner options

* #120 #119 created useBalance which accepts single or multiple addresses

- updated contract func key for better caching and invalidation

* updated yarn

* Features/#116 (#121)

* #116 fixed test for useBalance #117 modified wrapper for ContractContext

- removed old json way sof doing things, will be adding local contracts for testing
- updating hardhat mocks

* #116 lots of changes to tests

- cleaned up tests
- fixed old tests
- test wrapper changes to types
- fixed how mocks are loaded
- new mocks for external and hardhat contracts
- updated useContractLoader to be more simple

* #116 bug fixes and updates to contract context

- invalidation of old contract isntances
- key updates
- updates to validate adaptor
- fixes to sorting

* #116 bug fixes and updates to contract context.  Fix to EthersConnector signer bug

- signer should invalidate when chain is changed
- invalidation of old contract isntances
- key updates
- updates to validate adaptor
- fixes to sorting

* #116 changed order of invalidation of cache

* #116 package updates

* #116 package updates

* #116 package updates

* updated actions

* #124 updated docs

* #124 updated readme in docs

* Create CNAME

* Delete CNAME

* Set theme jekyll-theme-minimal

* Set theme jekyll-theme-architect

* Set theme jekyll-theme-midnight

* Set theme jekyll-theme-modernist

* Set theme jekyll-theme-hacker

* Set theme jekyll-theme-architect

* #124 updated docs headers

* #124 added emoji

* chore apply prettier to all files (#128)

biggest changes are just the newlines from windows computers

* Features/#126 (#129)

* #126 added status return type.  made react query options available.  better options typeing

* update packages

* updated tests #126

* Features/#125 (#130)

* updated docs

* #124 updated docs

* #124 updated readme in docs

* Create CNAME

* Delete CNAME

* Set theme jekyll-theme-minimal

* Set theme jekyll-theme-architect

* Set theme jekyll-theme-midnight

* Set theme jekyll-theme-modernist

* Set theme jekyll-theme-hacker

* Set theme jekyll-theme-architect

* #124 updated docs headers

* #124 added emoji

* #125 improved typing and updated to #125.  waiting for eth-sdk to update to v7

* #125 better comments

* #125 some type changes

* #125 some type changes for simplicity

* #126 added status return type.  made react query options available.  better options typeing

* update packages

* updated tests #126

* #125 merged with #126

* added examples and comments and minor changes #126

* comments and readme

* updated README

* updated README

* update package for docs

* updated docs

* #76 Tests for useTokenBalance (#131)

Additionally adds some docs to useTokenBalance and useBalance

* #127 comments and readme

* #124 comments and readme

* Bugs/#133 (#135)

* #133 fixes for contractConnects bugs found in collating contracts for the connectors

* #133 fixes for contractConnects bugs found in collating contracts for the connectors

* #133 nuked lock file

* updated package

* update packages and readme

Co-authored-by: Jaxcoder <[email protected]>
Co-authored-by: omnifient <[email protected]>
Co-authored-by: Sean Paterson <[email protected]>

* exclude sol (#170)

* #207 login improvements

* #207 update packages

* #207 better login error handling

Co-authored-by: Jaxcoder <[email protected]>
Co-authored-by: omnifient <[email protected]>
Co-authored-by: Sean Paterson <[email protected]>
  • Loading branch information
4 people authored May 2, 2022
1 parent da0e44f commit 1e6e26f
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 60 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eth-hooks",
"version": "4.2.6",
"version": "4.2.14",
"description": "A set of hooks to turbocharge buidling",
"author": "Shravan Sunder<[email protected]>",
"repository": "https://github.com/scaffold-eth/eth-hooks.git",
Expand Down Expand Up @@ -70,10 +70,10 @@
"ethers": "^5.6.4",
"lodash.isequal": "^4.5.0",
"merge-anything": "^5.0.2",
"react-query": "^3.38.0",
"react-query": "^3.38.*",
"ts-invariant": "^0.9.4",
"use-debounce": "^7.0.1",
"usehooks-ts": "^2.5.1",
"use-debounce": "^8.0.0",
"usehooks-ts": "^2.5.2",
"web3modal": "^1.9.7"
},
"peerDependencies": {
Expand All @@ -97,7 +97,7 @@
"@types/chai": "^4.3.1",
"@types/lodash.isequal": "^4.5.6",
"@types/mocha": "^9.1.1",
"@types/node": "^16.11.32",
"@types/node": "^16.11.33",
"@types/pretty-time": "^1.1.2",
"@types/qrcode.react": "^1.0.2",
"@types/react": "^18.0.8",
Expand Down Expand Up @@ -134,7 +134,7 @@
"husky": "^7.0.4",
"jsdom": "^19.0.0",
"lint-staged": "^12.4.1",
"mocha": "^9.2.2",
"mocha": "^10.0.0",
"mocha-github-actions-reporter": "^0.2.4",
"mocha-junit-reporter": "^2.0.2",
"pinst": "^3.0.0",
Expand Down
29 changes: 17 additions & 12 deletions src/context/ethers/EthersAppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export const useEthersContext = (contextKey?: string): IEthersContext => {
}
const ethersConnector = connector as EthersModalConnector;

const openWeb3Modal = useCallback(
(ethersModalConnector: TEthersModalConnector | undefined) => {
const openModal = useCallback<IEthersContext['openModal']>(
(ethersModalConnector: TEthersModalConnector | undefined, onError?: (error: Error) => void) => {
if (context.active) {
deactivate();
}
Expand All @@ -54,22 +54,27 @@ export const useEthersContext = (contextKey?: string): IEthersContext => {
invariant.error('A valid ethersModalConnector was not provided');
}
if (ethersModalConnector != null) {
const onError = (error: Error): void => {
const onActivateError = (error: Error): void => {
try {
connector?.deactivate?.();
console.warn(error);
onError?.(error);
} catch {}
};
void activate(ethersModalConnector, onError).catch(onError);
void activate(ethersModalConnector, onActivateError);
}
},
[context.active, deactivate, activate, connector]
);

const disconnectModal = useCallback(() => {
ethersConnector.resetModal();
deactivate();
}, [deactivate, ethersConnector]);
const disconnectModal = useCallback<IEthersContext['disconnectModal']>(
(onSuccess?: () => void) => {
ethersConnector.resetModal();
deactivate();
onSuccess?.();
},
[deactivate, ethersConnector]
);

const result: IEthersContext = {
connector: ethersConnector,
Expand All @@ -81,8 +86,8 @@ export const useEthersContext = (contextKey?: string): IEthersContext => {
signer: ethersConnector?.getSigner(),
chainId,
changeSigner: ethersConnector?.changeSigner.bind(ethersConnector),
openModal: openWeb3Modal,
disconnectModal: disconnectModal,
openModal,
disconnectModal,
setModalTheme: ethersConnector?.setModalTheme.bind(ethersConnector),
...context,
};
Expand Down Expand Up @@ -197,7 +202,7 @@ export const EthersAppContext: FC<TEthersAppContextProps> = (props) => {

if (props.disableQueryClientRoot) {
return element;
} else {
return <QueryClientProvider client={ethersAppQueryClient}>{element}</QueryClientProvider>;
}

return <QueryClientProvider client={ethersAppQueryClient}>{element}</QueryClientProvider>;
};
23 changes: 19 additions & 4 deletions src/context/ethers/connectors/EthersModalConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ import { Web3Provider } from '@ethersproject/providers';
import { AbstractConnector } from '@web3-react/abstract-connector';
import { ConnectorUpdate } from '@web3-react/types';
import { BigNumber, Signer, utils } from 'ethers';
import { invariant } from 'ts-invariant';
import { default as Web3Modal, ICoreOptions, ThemeColors } from 'web3modal';

import { UserClosedModalError, CouldNotActivateError } from './connectorErrors';

import { isEthersProvider } from '~~/functions/ethersHelpers';
import {
connectorErrorText,
NoEthereumProviderFoundError,
NoStaticJsonRPCProviderFoundError,
} from '~~/helpers/typedoc/context.docs';
import { TEthersProvider } from '~~/models';
import { const_web3DialogClosedByUser } from '~~/models/constants/common';
import { const_web3DialogClosedByUser, const_web3DialogUserRejected } from '~~/models/constants/common';

type TEthersModalConfig = {
/**
Expand Down Expand Up @@ -217,12 +223,21 @@ export class EthersModalConnector extends AbstractConnector implements ICommonMo
/* eslint-enable */
} catch (error) {
this.resetModal();
if (typeof error === 'string' && error?.includes(const_web3DialogClosedByUser)) {
console.log(error);
if (
typeof error === 'string' &&
(error?.includes(const_web3DialogClosedByUser) || error?.includes(const_web3DialogUserRejected))
) {
invariant.log(error);
this.deactivate();
throw new UserClosedModalError();
} else if (error instanceof NoStaticJsonRPCProviderFoundError) {
invariant.warn(`EthersModalConnector: ${connectorErrorText.NoStaticJsonRPCProviderFoundError}`);
throw error;
} else if (error instanceof NoEthereumProviderFoundError) {
invariant.warn(`EthersModalConnector: ${connectorErrorText.NoEthereumProviderFoundError}`);
throw error;
} else {
console.error('EthersModalConnector: Could not activate provider', error, this._providerBase);
invariant.warn(`EthersModalConnector: ${connectorErrorText.CouldNotActivateError}`, error, this._providerBase);
throw new CouldNotActivateError(error);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { StaticJsonRpcProvider } from '@ethersproject/providers';
import { IAbstractConnectorOptions } from 'web3modal';

import { NoStaticJsonRPCProviderFoundError } from '~~/context/ethers/connectors/connectorErrors';

/**
* #### Summary
* A web3modal CustomProvider Options
Expand Down Expand Up @@ -42,6 +44,6 @@ export const ConnectToStaticJsonRpcProvider = async (
}
return provider;
} catch (e) {
throw new Error('No StaticJsonRpcProvider found');
throw new NoStaticJsonRPCProviderFoundError(e);
}
};
26 changes: 23 additions & 3 deletions src/context/ethers/connectors/connectorErrors.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
export const connectorErrorText = {
NoStaticJsonRPCProviderFoundError: 'Could not find a static json-rpc provider. Is it running?',
NoEthereumProviderFoundError: 'No web3 provider found',
CouldNotActivateError: 'Could not activate the web3 provider',
UserClosedModalError: 'Did not log in, the user did not select a web3 provider',
} as const;

/**
* @category EthersContext
*/
export class UserClosedModalError extends Error {
public constructor() {
super();
this.name = this.constructor.name;
this.message = 'EthersModalConnector: The user closed the modal with selecting a provider.';
this.message = `EthersModalConnector: ${connectorErrorText.UserClosedModalError}.`;
}
}

Expand All @@ -16,7 +23,7 @@ export class CouldNotActivateError extends Error {
public constructor(error: unknown) {
super();
this.name = this.constructor.name;
this.message = `EthersModalConnector: Could not activate provider. ${(error as string) ?? ''}`;
this.message = `EthersModalConnector: ${connectorErrorText.CouldNotActivateError}. ${(error as string) ?? ''}`;
}
}

Expand All @@ -27,6 +34,19 @@ export class NoEthereumProviderFoundError extends Error {
public constructor() {
super();
this.name = this.constructor.name;
this.message = `EthersModalConnector: No ethereum provider Found.`;
this.message = `EthersModalConnector: ${connectorErrorText.NoEthereumProviderFoundError}.`;
}
}

/**
* @category EthersContext
*/
export class NoStaticJsonRPCProviderFoundError extends Error {
public constructor(error: unknown) {
super();
this.name = this.constructor.name;
this.message = `EthersModalConnector: ${connectorErrorText.NoStaticJsonRPCProviderFoundError}. ${
(error as string) ?? ''
}`;
}
}
1 change: 1 addition & 0 deletions src/models/constants/common.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const const_web3DialogClosedByUser = 'Modal closed by user';
export const const_web3DialogUserRejected = 'Error: User Rejected';
7 changes: 5 additions & 2 deletions src/models/ethersAppContextTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ export interface IEthersContext extends Web3ReactContextInterface<TEthersProvide
account: string | undefined;
chainId: number | undefined;
changeSigner: ((signer: Signer) => Promise<void>) | undefined;
openModal: (ethersModalConnector: TEthersModalConnector) => void;
disconnectModal: () => void;
/**
* Open web3 modal for login
*/
openModal: (ethersModalConnector: TEthersModalConnector, onError?: (error: Error) => void) => void;
disconnectModal: (onSuccess?: () => void) => void;
setModalTheme: ((theme: 'light' | 'dark') => void) | undefined;
}

Expand Down
Loading

0 comments on commit 1e6e26f

Please sign in to comment.