Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order the address book by date #72

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/app/core/rpc/rpc-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,17 @@ export class TransactionInfo {
category: string;
outputs: TransactionOutput[];
}

export enum AddressPurpose {
ANY = 0,
RECEIVE = 1,
SEND = 2,
}

// Address, as returned by `filteraddresses`
export class Address {
address: string;
label: string;
owned: boolean;
timestamp: number;
}
15 changes: 10 additions & 5 deletions src/app/core/rpc/rpc.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ import { IpcService } from '../ipc/ipc.service';
import { environment } from '../../../environments/environment';
import { Commands } from './commands';
import {
Address,
BumpFeeResult,
CoinControl,
Outputs,
ProposerStatus,
UnspentOutput,
TransactionInfo,
WalletInfo,
AddressPurpose,
} from './rpc-types';
import { Amount } from '../util/amount';
import { amountConverter } from './rpc-conversions';
Expand Down Expand Up @@ -161,15 +163,18 @@ export class RpcService implements OnDestroy {
return this.call(Commands.BUMPFEE, [txid, options, testFee]);
}

filterAddresses(offset?: number, count?: number, sort_code?: 0 | 1, search?: string, match_owned?: 0 | 1 | 2) {
filterAddresses(offset?: number, count?: number, match_owned?: AddressPurpose): Observable<Address[]> {
offset = offset || 0;
count = count || null;
sort_code = sort_code || 0;
search = search || '';
match_owned = match_owned || 0;
match_owned = match_owned || AddressPurpose.ANY;

// Always return the newest addresses first
const sort_code = 1;
const search = '';
const sort_key = 'timestamp';

return this.call(Commands.FILTERADDRESSES, [
offset, count, sort_code, search, match_owned
offset, count, sort_key, sort_code, search, match_owned
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { RpcService, Commands } from '../../../core/core.module';
import { AddressHelper } from '../../../core/util/utils';
import { AddressLookUpCopy } from '../models/address-look-up-copy';
import { Contact } from './contact.model';
import { AddressPurpose } from 'app/core/rpc/rpc-types';

@Component({
selector: 'app-addresslookup',
Expand Down Expand Up @@ -110,17 +111,17 @@ export class AddressLookupComponent implements OnInit {
this._rpc.addressBookInfo()
.subscribe(
(response: any) => {
let typeInt: 0 | 1 | 2 = 0;
let purpose: AddressPurpose = AddressPurpose.ANY;
if (this.type === 'send') {
typeInt = 2;
purpose = AddressPurpose.SEND;
this._addressCount = response.num_send;
} else {
this.filter = 'Private';
typeInt = 1;
purpose = AddressPurpose.RECEIVE;
this._addressCount = response.num_receive;
}
if (this._addressCount > 0) {
this._rpc.filterAddresses(0, this._addressCount, 0, '', typeInt)
this._rpc.filterAddresses(0, this._addressCount, purpose)
.subscribe(
(success: any) => {
this.addressLookups = [];
Expand Down
13 changes: 6 additions & 7 deletions src/app/wallet/wallet/receive/receive.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { Log } from 'ng2-logger';

import { RpcService, RpcStateService, Commands } from '../../../core/core.module';
import { ModalsHelperService } from 'app/modals/modals.module';
import { Address, AddressPurpose } from 'app/core/rpc/rpc-types';

import { AddAddressLabelComponent } from './modals/add-address-label/add-address-label.component';
import { SignatureAddressModalComponent } from '../shared/signature-address-modal/signature-address-modal.component';
Expand Down Expand Up @@ -247,17 +248,16 @@ export class ReceiveComponent implements OnInit {
return;
}
*/
this.rpc.filterAddresses(0, count, 0, '', 1)
this.rpc.filterAddresses(0, count, AddressPurpose.RECEIVE)
.subscribe(
(resp: Array<any>) => this.rpc_loadAddresses_success(resp),
(resp: Array<Address>) => this.rpc_loadAddresses_success(resp),
error => this.log.er('error', error));
}

/**
* Used to get the addresses.
* @TODO: Create interface Array<AddressInterface?>
*/
rpc_loadAddresses_success(response: Array<any>): void {
rpc_loadAddresses_success(response: Array<Address>): void {
const pub = response;

if (pub.length > 0) {
Expand All @@ -267,8 +267,6 @@ export class ReceiveComponent implements OnInit {
pub .forEach((val) => this.addAddress(val, 'public'));

if (!!response[0]) {
this.sortArrays();

this.selectAddress(this.addresses[this.type][0]);
}

Expand Down Expand Up @@ -304,7 +302,8 @@ export class ReceiveComponent implements OnInit {
if (!!response.path) {
tempAddress.id = response.path.replace('m/0/', '');
}
this.addresses.public.unshift(tempAddress);
// Preserve the order in which we received the addresses
this.addresses.public.push(tempAddress);
}

/** Sorts the address by id (= HD wallet path m/0/0 < m/0/1) */
Expand Down
7 changes: 4 additions & 3 deletions src/app/wallet/wallet/shared/address.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { Observable, Observer } from 'rxjs'; // use this for testing atm

import { Address, deserialize } from './address.model';
import { RpcService, Commands } from '../../../core/core.module';
import { AddressPurpose } from 'app/core/rpc/rpc-types';


@Injectable()
Expand Down Expand Up @@ -96,11 +97,11 @@ export class AddressService {

private rpc_filterAddresses() {
if (this.typeOfAddresses === 'send') {
return this._rpc.filterAddresses(0, this.addressCount, 0, '', 2);
return this._rpc.filterAddresses(0, this.addressCount, AddressPurpose.SEND);
} else if (this.typeOfAddresses === 'receive') {
return this._rpc.filterAddresses(0, this.addressCount, 0, '', 1);
return this._rpc.filterAddresses(0, this.addressCount, AddressPurpose.RECEIVE);
} else {
return this._rpc.filterAddresses(0, this.addressCount, 0, '');
return this._rpc.filterAddresses(0, this.addressCount);
}
}

Expand Down