Skip to content

Commit c20ba5c

Browse files
authored
Merge pull request #675 from PolymathNetwork/feat/metamask-changes
remove deprecated functions
2 parents 48578c0 + 7ddc947 commit c20ba5c

2 files changed

Lines changed: 7 additions & 10 deletions

File tree

packages/new-polymath-sdk/src/browserUtils.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ interface Ethereum extends HttpProvider {
1414
networkVersion: string;
1515
_metamask?: {
1616
isApproved: () => Promise<boolean>;
17+
isUnlocked: () => Promise<boolean>;
1718
};
1819
enable(): Promise<any>;
1920
}
@@ -117,14 +118,10 @@ export async function getCurrentAddress() {
117118
const support = getBrowserSupport();
118119

119120
if (isModern(win)) {
120-
// Special check for Metamask to know if it is locked or not
121121
if (win.ethereum._metamask) {
122-
const isApproved = await win.ethereum._metamask.isApproved();
123-
if (isApproved) {
124-
accounts = await web3.eth.getAccounts();
125-
if (!accounts.length) {
126-
throw new PolymathError({ code: ErrorCodes.WalletIsLocked });
127-
}
122+
const isUnlocked = await win.ethereum._metamask.isUnlocked();
123+
if (!isUnlocked) {
124+
throw new PolymathError({ code: ErrorCodes.WalletIsLocked });
128125
}
129126
}
130127
await enableWallet();

packages/polymath-ui/src/components/EthNetworkWrapper/actions.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,11 @@ export const init = (networks: Array<string>) => async (dispatch: Function) => {
149149
if (
150150
!accounts.length &&
151151
newProviderInjected &&
152-
window.ethereum._metamask.isApproved
152+
window.ethereum._metamask.isUnlocked // compatibility check on the MM version
153153
) {
154-
const isMetamaskApproved = await window.ethereum._metamask.isApproved();
154+
const isMetamaskUnlocked = await window.ethereum._metamask.isUnlocked();
155155

156-
if (!isMetamaskApproved) {
156+
if (isMetamaskUnlocked) {
157157
dispatch(requestAuthorization());
158158
return dispatch(fail(ERROR_ACCESS_REQUESTED));
159159
}

0 commit comments

Comments
 (0)