Skip to content

Instantly share code, notes, and snippets.

@acastellana
Created January 27, 2017 16:04
Show Gist options
  • Save acastellana/cb1526dfbbd0b088e8a55d102e4142be to your computer and use it in GitHub Desktop.
Save acastellana/cb1526dfbbd0b088e8a55d102e4142be to your computer and use it in GitHub Desktop.
isAvaliableForMS(address)
/**
* isAvaliableForMS(address) Checks if address can be obtained and transformed to a MultiSig account.
*
* @param {string} address - Address to check
*
* @return {promise} - A promise of the NetworkRequests service that returns true if the account is not another account's cosignatory nor already has cosignaroties.
*/
isAvaliableForMS(address){
var deferred = this._q.defer();
var promise = deferred.promise;
return this._NetworkRequests.getAccountData(helpers.getHostname(this._Wallet.node), address).then((data) => {
var result = true;
// This account should not own any other account
if (data.meta.cosignatoryOf.length > 0) {
this._Alert.cosignatoryCannotBeMultisig();
result = false;
// This account should not be owned already
} else if (data.meta.cosignatories.length > 0) {
this._Alert.alreadyMultisig();
result = false;
}
deferred.resolve(result);
},
(err) => {
if(err.status === -1) {
this._Alert.connectionError();
} else {
this._Alert.getAccountDataError(err.data.message);
}
return;
});
return deferred.promise;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment