Handle migration from old all-accounts (#1110)

This commit is contained in:
Jaco
2022-07-14 11:31:39 +03:00
committed by GitHub
parent d69d391753
commit 3956bd5cb3
4 changed files with 21 additions and 13 deletions
@@ -35,6 +35,8 @@ export type AuthorizedAccountsDiff = [url: string, authorizedAccounts: AuthUrlIn
export interface AuthUrlInfo {
count: number;
id: string;
// this is from pre-0.44.1
isAllowed?: boolean;
origin: string;
url: string;
authorizedAccounts: string[];
@@ -355,9 +357,6 @@ export default class State {
public updateAuthorizedAccounts (authorizedAccountDiff: AuthorizedAccountsDiff): void {
authorizedAccountDiff.forEach(([url, authorizedAccountDiff]) => {
// this url was never seen in the past
assert(this.#authUrls[url].authorizedAccounts, `The source ${url} has never been authorized to interact with this extension`);
this.#authUrls[url].authorizedAccounts = authorizedAccountDiff;
});
@@ -368,19 +367,20 @@ export default class State {
const idStr = this.stripUrl(url);
// Do not enqueue duplicate authorization requests.
const isDuplicate = Object.values(this.#authRequests)
const isDuplicate = Object
.values(this.#authRequests)
.some((request) => request.idStr === idStr);
assert(!isDuplicate, `The source ${url} has a pending authorization request`);
if (this.#authUrls[idStr]) {
// this url was seen in the past
assert(this.#authUrls[idStr].authorizedAccounts, `The source ${url} is not allowed to interact with this extension`);
assert(this.#authUrls[idStr].authorizedAccounts || this.#authUrls[idStr].isAllowed, `The source ${url} is not allowed to interact with this extension`);
return ({
return {
authorizedAccounts: [],
result: false
});
};
}
return new Promise((resolve, reject): void => {
@@ -43,10 +43,15 @@ export default class Tabs {
}
private filterForAuthorizedAccounts (accounts: InjectedAccount[], url: string): InjectedAccount[] {
const auth = this.#state.authUrls[this.#state.stripUrl(url)];
return accounts.filter(
(allAcc) => this.#state.authUrls[this.#state.stripUrl(url)]
.authorizedAccounts
.includes(allAcc.address)
(allAcc) =>
auth.authorizedAccounts
// we have a list, use it
? auth.authorizedAccounts.includes(allAcc.address)
// if no authorizedAccounts and isAllowed return all - these are old converted urls
: auth.isAllowed
);
}
@@ -18,7 +18,7 @@ interface Props extends ThemeProps {
url: string;
}
function WebsiteEntry ({ className = '', info: { authorizedAccounts }, removeAuth, url }: Props): React.ReactElement<Props> {
function WebsiteEntry ({ className = '', info: { authorizedAccounts, isAllowed }, removeAuth, url }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const _removeAuth = useCallback(
@@ -42,7 +42,9 @@ function WebsiteEntry ({ className = '', info: { authorizedAccounts }, removeAut
total: authorizedAccounts.length
}
})
: t('no accounts')
: isAllowed
? t('all accounts')
: t('no accounts')
}</Link>
</div>
);
@@ -172,5 +172,6 @@
"Account connection request": "",
"Understood": "",
"Ask again later": "",
"no accounts": ""
"no accounts": "",
"all accounts": ""
}