mirror of https://github.com/BTCPrivate/copay.git
Adds BWC. Get profile and wallets
This commit is contained in:
parent
7c0343b4bf
commit
f2d8d208a0
|
@ -5,4 +5,12 @@
|
||||||
</ion-header>
|
</ion-header>
|
||||||
|
|
||||||
<ion-content padding>
|
<ion-content padding>
|
||||||
|
<ion-card *ngFor="let wallet of wallets">
|
||||||
|
<ion-card-header>
|
||||||
|
{{wallet.credentials.walletName}} {{wallet.credentials.m}}-{{wallet.credentials.n}}
|
||||||
|
</ion-card-header>
|
||||||
|
<ion-card-content>
|
||||||
|
{{wallet.credentials.coin}} - {{wallet.credentials.walletId}}
|
||||||
|
</ion-card-content>
|
||||||
|
</ion-card>
|
||||||
</ion-content>
|
</ion-content>
|
||||||
|
|
|
@ -1,16 +1,23 @@
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { NavController } from 'ionic-angular';
|
import { NavController } from 'ionic-angular';
|
||||||
|
import { ProfileProvider } from '../../providers/profile/profile';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'page-home',
|
selector: 'page-home',
|
||||||
templateUrl: 'home.html'
|
templateUrl: 'home.html'
|
||||||
})
|
})
|
||||||
export class HomePage {
|
export class HomePage {
|
||||||
|
public wallets;
|
||||||
|
|
||||||
constructor(public navCtrl: NavController) {
|
constructor(
|
||||||
|
public navCtrl: NavController,
|
||||||
|
private profile: ProfileProvider
|
||||||
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ionViewDidLoad() {
|
ionViewDidLoad() {
|
||||||
console.log('ionViewDidLoad HomePage');
|
console.log('ionViewDidLoad HomePage');
|
||||||
|
this.wallets = this.profile.bind();
|
||||||
|
console.log('[home.ts:20]',this.wallets); //TODO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,15 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
//import * as BWC from 'bitcore-wallet-client';
|
import * as BWC from 'bitcore-wallet-client';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class BwcProvider {
|
export class BwcProvider {
|
||||||
/*
|
|
||||||
public buildTx = BWC.buildTx;
|
public buildTx = BWC.buildTx;
|
||||||
public parseSecret = BWC.parseSecret;
|
public parseSecret = BWC.parseSecret;
|
||||||
public Client = BWC;
|
public Client = BWC;
|
||||||
*/
|
|
||||||
constructor() {
|
constructor() {
|
||||||
console.log('Hello BwcProvider Provider');
|
console.log('Hello BwcProvider Provider');
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
getBitcore() {
|
getBitcore() {
|
||||||
return BWC.Bitcore;
|
return BWC.Bitcore;
|
||||||
}
|
}
|
||||||
|
@ -43,6 +40,5 @@ export class BwcProvider {
|
||||||
bwc.import(walletData, opts);
|
bwc.import(walletData, opts);
|
||||||
return bwc;
|
return bwc;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Events } from 'ionic-angular';
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
import { PersistenceProvider } from '../persistence/persistence';
|
import { PersistenceProvider } from '../persistence/persistence';
|
||||||
import { ConfigProvider } from '../config/config';
|
import { ConfigProvider } from '../config/config';
|
||||||
import { BwcProvider } from '../bwc/bwc';
|
import { BwcProvider } from '../bwc/bwc';
|
||||||
|
import { WalletProvider } from '../wallet/wallet';
|
||||||
|
|
||||||
interface Profile {
|
interface Profile {
|
||||||
version: string;
|
version: string;
|
||||||
|
@ -32,6 +34,8 @@ export class ProfileProvider {
|
||||||
public profile: Profile;
|
public profile: Profile;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
public events: Events,
|
||||||
|
private wallet: WalletProvider,
|
||||||
private persistence: PersistenceProvider,
|
private persistence: PersistenceProvider,
|
||||||
private config: ConfigProvider,
|
private config: ConfigProvider,
|
||||||
private bwc: BwcProvider
|
private bwc: BwcProvider
|
||||||
|
@ -42,6 +46,7 @@ export class ProfileProvider {
|
||||||
get() {
|
get() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.persistence.getProfile().then((profile: any) => {
|
this.persistence.getProfile().then((profile: any) => {
|
||||||
|
this.profile = profile;
|
||||||
resolve(profile);
|
resolve(profile);
|
||||||
}, (error) => {
|
}, (error) => {
|
||||||
reject(error);
|
reject(error);
|
||||||
|
@ -52,42 +57,24 @@ export class ProfileProvider {
|
||||||
create() {
|
create() {
|
||||||
this.profile = new Profile();
|
this.profile = new Profile();
|
||||||
|
|
||||||
console.log('[profile.ts:33]', this.profile); //TODO
|
|
||||||
|
|
||||||
this.persistence.storeNewProfile(this.profile).then(() => {
|
this.persistence.storeNewProfile(this.profile).then(() => {
|
||||||
// bindProfile (this.profile)
|
// TODO: bind?
|
||||||
}, (error) => {
|
}, (error) => {
|
||||||
// Todo: error?
|
// TODO: error?
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bind(profile: Profile) {
|
bind() {
|
||||||
let l = profile.credentials.length;
|
let l = this.profile.credentials.length;
|
||||||
let i = 0;
|
let wallets = new Array();
|
||||||
let totalBound = 0;
|
|
||||||
|
|
||||||
if (!l) return;
|
if (!l) return wallets;
|
||||||
|
let credentials = this.profile.credentials;
|
||||||
|
|
||||||
_.each(profile.credentials, function(credentials) {
|
_.each(credentials, (credential) => {
|
||||||
this.bindWallet(credentials, function(err, bound) {
|
wallets.push(this.wallet.bind(credential));
|
||||||
i++;
|
|
||||||
totalBound += bound;
|
|
||||||
if (i == l) {
|
|
||||||
console.log('Bound ' + totalBound + ' out of ' + l + ' wallets');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
return wallets;
|
||||||
}
|
|
||||||
|
|
||||||
bindWallet(credentials) {
|
|
||||||
let defaults = this.config.get();
|
|
||||||
|
|
||||||
/*
|
|
||||||
let client = this.bwc.getClient(JSON.stringify(credentials), {
|
|
||||||
bwsurl: defaults['bws']['url'],
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,83 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
@Injectable()
|
import { PlatformProvider } from '../platform/platform';
|
||||||
export class WalletProvider {
|
import { ConfigProvider } from '../config/config';
|
||||||
|
import { BwcProvider } from '../bwc/bwc';
|
||||||
|
|
||||||
constructor() {
|
// TODO: create interface
|
||||||
console.log('Hello WalletService Provider');
|
interface Wallet {
|
||||||
|
baseUrl: string;
|
||||||
|
credentials: Object;
|
||||||
|
doNotVerifyPayPro: boolean;
|
||||||
|
logLevel: string;
|
||||||
|
payProHttp: string;
|
||||||
|
request: Function;
|
||||||
|
supportStaffWalletId: string;
|
||||||
|
timeout: Number;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Wallet implements Wallet {
|
||||||
|
constructor(
|
||||||
|
public baseUrl: string = '1.0.0',
|
||||||
|
) {
|
||||||
|
// Nothing to do
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const UPDATE_PERIOD = 15;
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class WalletProvider {
|
||||||
|
public wallet: Object = new Object();
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private platform: PlatformProvider,
|
||||||
|
private config: ConfigProvider,
|
||||||
|
private bwc: BwcProvider
|
||||||
|
) {
|
||||||
|
console.log('Hello WalletService Provider');
|
||||||
|
}
|
||||||
|
|
||||||
|
bind(credential) {
|
||||||
|
let defaults = this.config.get();
|
||||||
|
|
||||||
|
let wallet = this.bwc.getClient(JSON.stringify(credential), {
|
||||||
|
bwsurl: defaults['bws']['url'],
|
||||||
|
});
|
||||||
|
return wallet;
|
||||||
|
}
|
||||||
|
|
||||||
|
bindClient(wallet, opts?) {
|
||||||
|
opts = opts || {};
|
||||||
|
let walletId = wallet.credentials.walletId;
|
||||||
|
|
||||||
|
//root.updateWalletSettings(wallet);
|
||||||
|
this.wallet[walletId] = wallet;
|
||||||
|
|
||||||
|
/*
|
||||||
|
_needsBackup(wallet, function(val) {
|
||||||
|
wallet.needsBackup = val;
|
||||||
|
});
|
||||||
|
|
||||||
|
_balanceIsHidden(wallet, function(val) {
|
||||||
|
wallet.balanceHidden = val;
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.wallet[walletId].initialize({
|
||||||
|
notificationIncludeOwn: true,
|
||||||
|
}, function(err) {
|
||||||
|
if (err) {
|
||||||
|
console.log('Could not init notifications err:', err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.wallet[walletId].setNotificationsInterval(UPDATE_PERIOD);
|
||||||
|
this.wallet[walletId].openWallet(function(err) {
|
||||||
|
if (wallet.status !== true)
|
||||||
|
console.log('Wallet + ' + walletId + ' status:' + wallet.status)
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue