Skip to content

Instantly share code, notes, and snippets.

@acastellana
Created January 27, 2017 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acastellana/0742d2221c2ab0f25d78e2f49891e881 to your computer and use it in GitHub Desktop.
Save acastellana/0742d2221c2ab0f25d78e2f49891e881 to your computer and use it in GitHub Desktop.
ownsMosaic(address,namespace, mosaic)
/*
* REQUIRES:
* - https://gist.github.com/acastellana/995326e3a41b5f690db50a17153af312
* - https://gist.github.com/acastellana/607a47838e842417d80622568543eb74
*/
/**
* ownsMosaic(address,namespace, mosaic) Checks if address owns any mosaics from namespace:mosaic
*
* @param {string} address - NEM Address to check for the mosaic
* @param {string} namespaceId - Mosaic's namespace name
* @param {string} mosaic - Mosaic's name
*
* @return {promise} - A promise of the NetworkRequests service that returns wether if address owns any mosaics from namespace:mosaic or not
*/
ownsMosaic(address,namespace, mosaic){
var deferred = this._q.defer();
var promise = deferred.promise;
this._NetworkRequests.getMosaicsDefinitions(helpers.getHostname(this._Wallet.node), address).then((result)=>{
let owns = false;
if(result.data.length) {
for (let i = 0; i < result.data.length; ++i) {
let rNamespace = result.data[i].id.namespaceId;
let rMosaic = result.data[i].id.name;
if(namespace == rNamespace && mosaic == rMosaic){
owns = true;
}
}
}
deferred.resolve(owns);
},
(err) => {
if(err.status === -1) {
this._Alert.connectionError();
} else {
this._Alert.errorGetMosaicsDefintions(err.data.message);
}
});
return deferred.promise;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment