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-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>
|
||||
|
|
|
@ -1,16 +1,23 @@
|
|||
import { Component } from '@angular/core';
|
||||
import { NavController } from 'ionic-angular';
|
||||
import { ProfileProvider } from '../../providers/profile/profile';
|
||||
|
||||
@Component({
|
||||
selector: 'page-home',
|
||||
templateUrl: 'home.html'
|
||||
})
|
||||
export class HomePage {
|
||||
public wallets;
|
||||
|
||||
constructor(public navCtrl: NavController) {
|
||||
constructor(
|
||||
public navCtrl: NavController,
|
||||
private profile: ProfileProvider
|
||||
) {
|
||||
}
|
||||
|
||||
ionViewDidLoad() {
|
||||
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 * as BWC from 'bitcore-wallet-client';
|
||||
import * as BWC from 'bitcore-wallet-client';
|
||||
|
||||
@Injectable()
|
||||
export class BwcProvider {
|
||||
/*
|
||||
public buildTx = BWC.buildTx;
|
||||
public parseSecret = BWC.parseSecret;
|
||||
public Client = BWC;
|
||||
*/
|
||||
constructor() {
|
||||
console.log('Hello BwcProvider Provider');
|
||||
}
|
||||
/*
|
||||
getBitcore() {
|
||||
return BWC.Bitcore;
|
||||
}
|
||||
|
@ -43,6 +40,5 @@ export class BwcProvider {
|
|||
bwc.import(walletData, opts);
|
||||
return bwc;
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { Events } from 'ionic-angular';
|
||||
import * as moment from 'moment';
|
||||
import * as _ from 'lodash';
|
||||
import { PersistenceProvider } from '../persistence/persistence';
|
||||
import { ConfigProvider } from '../config/config';
|
||||
import { BwcProvider } from '../bwc/bwc';
|
||||
import { WalletProvider } from '../wallet/wallet';
|
||||
|
||||
interface Profile {
|
||||
version: string;
|
||||
|
@ -32,6 +34,8 @@ export class ProfileProvider {
|
|||
public profile: Profile;
|
||||
|
||||
constructor(
|
||||
public events: Events,
|
||||
private wallet: WalletProvider,
|
||||
private persistence: PersistenceProvider,
|
||||
private config: ConfigProvider,
|
||||
private bwc: BwcProvider
|
||||
|
@ -42,6 +46,7 @@ export class ProfileProvider {
|
|||
get() {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.persistence.getProfile().then((profile: any) => {
|
||||
this.profile = profile;
|
||||
resolve(profile);
|
||||
}, (error) => {
|
||||
reject(error);
|
||||
|
@ -52,42 +57,24 @@ export class ProfileProvider {
|
|||
create() {
|
||||
this.profile = new Profile();
|
||||
|
||||
console.log('[profile.ts:33]', this.profile); //TODO
|
||||
|
||||
this.persistence.storeNewProfile(this.profile).then(() => {
|
||||
// bindProfile (this.profile)
|
||||
// TODO: bind?
|
||||
}, (error) => {
|
||||
// Todo: error?
|
||||
// TODO: error?
|
||||
});
|
||||
}
|
||||
|
||||
bind(profile: Profile) {
|
||||
let l = profile.credentials.length;
|
||||
let i = 0;
|
||||
let totalBound = 0;
|
||||
bind() {
|
||||
let l = this.profile.credentials.length;
|
||||
let wallets = new Array();
|
||||
|
||||
if (!l) return;
|
||||
if (!l) return wallets;
|
||||
let credentials = this.profile.credentials;
|
||||
|
||||
_.each(profile.credentials, function(credentials) {
|
||||
this.bindWallet(credentials, function(err, bound) {
|
||||
i++;
|
||||
totalBound += bound;
|
||||
if (i == l) {
|
||||
console.log('Bound ' + totalBound + ' out of ' + l + ' wallets');
|
||||
return;
|
||||
}
|
||||
_.each(credentials, (credential) => {
|
||||
wallets.push(this.wallet.bind(credential));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
bindWallet(credentials) {
|
||||
let defaults = this.config.get();
|
||||
|
||||
/*
|
||||
let client = this.bwc.getClient(JSON.stringify(credentials), {
|
||||
bwsurl: defaults['bws']['url'],
|
||||
});
|
||||
*/
|
||||
return wallets;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,83 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable()
|
||||
export class WalletProvider {
|
||||
import { PlatformProvider } from '../platform/platform';
|
||||
import { ConfigProvider } from '../config/config';
|
||||
import { BwcProvider } from '../bwc/bwc';
|
||||
|
||||
constructor() {
|
||||
console.log('Hello WalletService Provider');
|
||||
// TODO: create interface
|
||||
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