Allow removal of multi-accounts via account registry, add docs

Signed-off-by: Marquis Kurt <software@marquiskurt.net>
This commit is contained in:
Marquis Kurt 2019-10-02 16:54:24 -04:00
parent e52ae2e332
commit 359f18a6ce
No known key found for this signature in database
GPG Key ID: 725636D259F5402D
1 changed files with 17 additions and 5 deletions

View File

@ -82,12 +82,24 @@ export function addAccountToRegistry(
localStorage.setItem("registry", JSON.stringify(accountRegistry));
}
export function removeAccountFromRegistry(index: number) {
/**
* Remove an account from the multi-account registry, if possible
* @param accountIdentifier The index of the account from the registry or the MultiAccount object itself
*/
export function removeAccountFromRegistry(
accountIdentifier: number | MultiAccount
) {
let accountRegistry = getAccountRegistry();
if (accountRegistry.length > index) {
accountRegistry.splice(index);
if (typeof accountIdentifier === "number") {
if (accountRegistry.length > accountIdentifier) {
accountRegistry.splice(accountIdentifier);
} else {
console.log("Multi account index may be out of range");
}
} else {
console.warn("Index of multi-account registry may be out of range.");
if (accountRegistry.includes(accountIdentifier)) {
accountRegistry.splice(accountRegistry.indexOf(accountIdentifier));
}
}
localStorage.setItem("registry", JSON.stringify(accountRegistry));
}