Skip to content
This repository has been archived by the owner on Jun 10, 2022. It is now read-only.

Commit

Permalink
Merge f714918 into e739292
Browse files Browse the repository at this point in the history
  • Loading branch information
dgarcia360 committed Oct 5, 2019
2 parents e739292 + f714918 commit 4dfc6a8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 28 deletions.
37 changes: 17 additions & 20 deletions src/commands/namespace/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import chalk from 'chalk';
import * as Table from 'cli-table3';
import {HorizontalTable} from 'cli-table3';
import {command, metadata, option} from 'clime';
import {Namespace, NamespaceHttp, NamespaceId, NamespaceService, UInt64} from 'nem2-sdk';
import {NamespaceHttp, NamespaceId, NamespaceInfo, UInt64} from 'nem2-sdk';
import {OptionsResolver} from '../../options-resolver';
import {ProfileCommand, ProfileOptions} from '../../profile.command';
import {NamespaceIdValidator} from '../../validators/namespaceId.validator';
Expand All @@ -41,34 +41,33 @@ export class CommandOptions extends ProfileOptions {

export class NamespaceInfoTable {
private readonly table: HorizontalTable;
constructor(public readonly namespace: Namespace) {
constructor(public readonly namespaceInfo: NamespaceInfo) {
this.table = new Table({
style: {head: ['cyan']},
head: ['Property', 'Value'],
}) as HorizontalTable;
this.table.push(
['Id', namespace.id.toHex()],
['Name', namespace.name],
['Registration Type', namespace.isRoot() ? 'Root Namespace' : 'Sub Namespace'],
['Owner', namespace.owner.address.pretty()],
['Start Height', namespace.startHeight.compact()],
['End Height', namespace.endHeight.compact()],
['Id', namespaceInfo.id.toHex()],
['Registration Type', namespaceInfo.isRoot() ? 'Root Namespace' : 'Sub Namespace'],
['Owner', namespaceInfo.owner.address.pretty()],
['Start Height', namespaceInfo.startHeight.compact()],
['End Height', namespaceInfo.endHeight.compact()],
);
if (namespace.isSubnamespace()) {
if (namespaceInfo.isSubnamespace()) {
this.table.push(
['Parent Id', namespace.parentNamespaceId().toHex()],
['Parent Id', namespaceInfo.parentNamespaceId().toHex()],
);
}
if (namespace.hasAlias()) {
if (namespace.alias.address) {
if (namespaceInfo.hasAlias()) {
if (namespaceInfo.alias.address) {
this.table.push(
['Alias Type', 'Address'],
['Alias Address', namespace.alias.address.pretty()],
['Alias Address', namespaceInfo.alias.address.pretty()],
);
} else if (namespace.alias.mosaicId) {
} else if (namespaceInfo.alias.mosaicId) {
this.table.push(
['Alias Type', 'MosaicId'],
['Alias MosaicId', namespace.alias.mosaicId.toHex()],
['Alias MosaicId', namespaceInfo.alias.mosaicId.toString()],
);
}
}
Expand Down Expand Up @@ -113,17 +112,15 @@ export default class extends ProfileCommand {
}

const namespaceHttp = new NamespaceHttp(profile.url);
const namespaceService = new NamespaceService(namespaceHttp);
namespaceService.namespace(namespaceId)
.subscribe((namespace) => {
namespaceHttp.getNamespace(namespaceId)
.subscribe((namespaceInfo) => {
this.spinner.stop(true);
console.log(new NamespaceInfoTable(namespace).toString());
console.log(new NamespaceInfoTable(namespaceInfo).toString());
}, (err) => {
this.spinner.stop(true);
let text = '';
text += chalk.red('Error');
console.log(text, err.response !== undefined ? err.response.text : err);
});
}

}
9 changes: 1 addition & 8 deletions src/commands/namespace/owned.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
*/
import chalk from 'chalk';
import {command, metadata, option} from 'clime';
import {Address, NamespaceHttp, NamespaceInfo, NamespaceService} from 'nem2-sdk';
import {mergeMap, toArray} from 'rxjs/operators';
import {Address, NamespaceHttp} from 'nem2-sdk';
import {OptionsResolver} from '../../options-resolver';
import {ProfileCommand, ProfileOptions} from '../../profile.command';
import {AddressValidator} from '../../validators/address.validator';
Expand Down Expand Up @@ -53,14 +52,8 @@ export default class extends ProfileCommand {
() => this.getProfile(options).account.address.plain(),
'Introduce the address: '));
const namespaceHttp = new NamespaceHttp(profile.url);
const namespaceService = new NamespaceService(namespaceHttp);
this.spinner.start();
namespaceHttp.getNamespacesFromAccount(address)
.pipe(
mergeMap((_) => _),
mergeMap((namespaceInfo: NamespaceInfo) => namespaceService.namespace(namespaceInfo.id)),
toArray(),
)
.subscribe((namespaces) => {
this.spinner.stop(true);

Expand Down

0 comments on commit 4dfc6a8

Please sign in to comment.