@metamask-institutional/custody-controller
Advanced tools
Comparing version 0.1.15 to 0.2.0
@@ -18,2 +18,9 @@ # Change Log | ||
## [0.2.0](https://github.com/consensys-vertical-apps/metamask-institutional/compare/custody-controller-v0.1.15...custody-controller-v0.2.0) (2023-02-14) | ||
### Features | ||
* **custody-controller:** added handleMmiCheckIfTokenIsPresent method ([#121](https://github.com/consensys-vertical-apps/metamask-institutional/issues/121)) ([3523e1d](https://github.com/consensys-vertical-apps/metamask-institutional/commit/3523e1d395f5082f396e70cb12f9f2e0ba617aa1)) | ||
## [0.1.13](https://github.com/consensys-vertical-apps/metamask-institutional/compare/@metamask-institutional/custody-controller@0.1.8...@metamask-institutional/custody-controller@0.1.13) (2023-02-02) | ||
@@ -20,0 +27,0 @@ |
@@ -32,3 +32,9 @@ import { ITransactionStatusMap } from "@metamask-institutional/types"; | ||
}): boolean; | ||
handleMmiCheckIfTokenIsPresent({ token, apiUrl, getUnlockPromise, addKeyringIfNotExists, }: { | ||
token: string; | ||
apiUrl: string; | ||
getUnlockPromise: (arg0: boolean) => Promise<boolean>; | ||
addKeyringIfNotExists: (arg0: string) => any; | ||
}): Promise<boolean>; | ||
} | ||
//# sourceMappingURL=custody.d.ts.map |
@@ -117,4 +117,17 @@ "use strict"; | ||
} | ||
async handleMmiCheckIfTokenIsPresent({ token, apiUrl, getUnlockPromise, addKeyringIfNotExists, }) { | ||
await getUnlockPromise(true); | ||
const custodyType = "Custody - JSONRPC"; | ||
const keyring = await addKeyringIfNotExists(custodyType); | ||
const accounts = await keyring.getAccounts(); | ||
for (const address of accounts) { | ||
const accountDetails = keyring.getAccountDetails(address); | ||
if (accountDetails.apiUrl === apiUrl && accountDetails.authDetails.refreshToken === token) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} | ||
exports.CustodyController = CustodyController; | ||
//# sourceMappingURL=custody.js.map |
{ | ||
"name": "@metamask-institutional/custody-controller", | ||
"version": "0.1.15", | ||
"version": "0.2.0", | ||
"description": "Custody controller is a background controller responsible for maintaining a cache of custody data in local storage", | ||
@@ -30,3 +30,3 @@ "author": "Albert Olive <albertolivecorbella@gmail.com>", | ||
}, | ||
"gitHead": "6d0d21860abe71c782d4967ff8a1c6adde611cb6", | ||
"gitHead": "80ecc683fb2e2b9483a80faf79969e2784afdb79", | ||
"dependencies": { | ||
@@ -33,0 +33,0 @@ "@ethereumjs/util": "^8.0.3", |
{ | ||
"name": "@metamask-institutional/custody-controller", | ||
"version": "0.1.15", | ||
"version": "0.2.0", | ||
"description": "Custody controller is a background controller responsible for maintaining a cache of custody data in local storage", | ||
@@ -30,3 +30,3 @@ "author": "Albert Olive <albertolivecorbella@gmail.com>", | ||
}, | ||
"gitHead": "6d0d21860abe71c782d4967ff8a1c6adde611cb6", | ||
"gitHead": "80ecc683fb2e2b9483a80faf79969e2784afdb79", | ||
"dependencies": { | ||
@@ -33,0 +33,0 @@ "@ethereumjs/util": "^8.0.3", |
@@ -135,2 +135,3 @@ import { CUSTODIAN_TYPES } from "@metamask-institutional/custody-keyring"; | ||
} | ||
handleMmiCustodianInUse(req: { | ||
@@ -172,2 +173,38 @@ origin: string; | ||
} | ||
async handleMmiCheckIfTokenIsPresent({ | ||
token, | ||
apiUrl, | ||
getUnlockPromise, | ||
addKeyringIfNotExists, | ||
}: { | ||
token: string; | ||
apiUrl: string; | ||
getUnlockPromise: (arg0: boolean) => Promise<boolean>; | ||
addKeyringIfNotExists: (arg0: string) => any; | ||
}): Promise<boolean> { | ||
// FIXME: we are not currently storing environment (aka custodian name) in the keyring accountsDetails | ||
// We should be doing this and comparing environment instead of apiUrl | ||
// But this would require migrations | ||
// See MMI-2119 | ||
// This can only work if the extension is unlocked | ||
await getUnlockPromise(true); | ||
const custodyType = "Custody - JSONRPC"; // Only JSONRPC is supported for now | ||
const keyring = await addKeyringIfNotExists(custodyType); | ||
const accounts = await keyring.getAccounts(); | ||
for (const address of accounts) { | ||
const accountDetails = keyring.getAccountDetails(address); | ||
// TODO: Change to rely on environment instead of apiUrl when MMI-2119 is done | ||
if (accountDetails.apiUrl === apiUrl && accountDetails.authDetails.refreshToken === token) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
56182
886