Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_unlinkAccount(name) {
if (!ChainValidation.is_account_name(name, true))
throw new Error("Invalid account name: " + name);
// Unlink
iDB.remove_from_store("linked_accounts", name);
// this.state.myActiveAccounts = this.state.myActiveAccounts.delete(name);
// Update current account if no accounts are linked
// if (this.state.myActiveAccounts.size === 0) {
// this.setCurrentAccount(null);
// }
}
function accountNameChecker(props, propName, componentName) {
componentName = componentName || "ANONYMOUS";
if (props[propName]) {
let value = props[propName];
if (ChainValidation.is_account_name(value)) {
return null;
} else {
return new Error(
`${propName} value of ${value} in ${componentName} is not a valid account name`
);
}
}
// assume all ok
return null;
}
getInputType(value) {
// OK
if (!value) return null;
if (value[0] === "#" && utils.is_object_id("1.2." + value.substring(1)))
return "id";
if (ChainValidation.is_account_name(value, true)) return "name";
if (this.props.allowPubKey && PublicKey.fromPublicKeyString(value))
return "pubkey";
return null;
}
_linkAccount(name) {
if (!ChainValidation.is_account_name(name, true))
throw new Error("Invalid account name: " + name);
// Link
const linkedEntry = {
name,
chainId: Apis.instance().chain_id
};
try {
iDB.add_to_store("linked_accounts", linkedEntry);
this.state.linkedAccounts = this.state.linkedAccounts.add(
Immutable.fromJS(linkedEntry)
);
// Keep the local linkedAccounts in sync with the db
if (!this.state.myHiddenAccounts.has(name))
this.state.myActiveAccounts = this.state.myActiveAccounts.add(
name
getInputType(value) {
// OK
if (!value) return null;
if (value[0] === "#" && utils.is_object_id("1.2." + value.substring(1)))
return "id";
if (ChainValidation.is_account_name(value, true)) return "name";
if (this.props.allowPubKey && PublicKey.fromPublicKeyString(value))
return "pubkey";
return null;
}
onCreateAccount(name_or_account) {
let account = name_or_account;
if (typeof account === "string") {
account = {
name: account
};
}
if (account["toJS"]) account = account.toJS();
if (account.name == "" || this.state.myActiveAccounts.get(account.name))
return Promise.resolve();
if (!ChainValidation.is_account_name(account.name))
throw new Error("Invalid account name: " + account.name);
return iDB
.add_to_store("linked_accounts", {
name: account.name,
chainId: Apis.instance().chain_id
})
.then(() => {
console.log(
"[AccountStore.js] ----- Added account to store: ----->",
account.name
);
this.state.myActiveAccounts = this.state.myActiveAccounts.add(
account.name
);
if (this.state.myActiveAccounts.size === 1) {
getNameType(value) {
if (!value) return null;
if (value[0] === "#" && utils.is_object_id("1.2." + value.substring(1))) return "id";
if (ChainValidation.is_account_name(value, true)) return "name";
if (this.props.allowPubKey && PublicKey.fromPublicKeyString(value)) return "pubkey";
return null;
}
onRemoveAccountContact(name) {
if (!ChainValidation.is_account_name(name, true))
throw new Error("Invalid account name: " + name);
if (this.state.accountContacts.has(name)) {
const accountContacts = this.state.accountContacts.remove(name);
ss.set(this._getStorageKey("accountContacts"), accountContacts);
this.setState({
accountContacts: accountContacts
});
}
}
onAddAccountContact(name) {
if (!ChainValidation.is_account_name(name, true))
throw new Error("Invalid account name: " + name);
if (!this.state.accountContacts.has(name)) {
const accountContacts = this.state.accountContacts.add(name);
ss.set(
this._getStorageKey("accountContacts"),
accountContacts.toArray()
);
this.setState({
accountContacts: accountContacts
});
}
}