mirror of https://github.com/BTCPrivate/copay.git
Adds bitcoin unit provider. Settings
This commit is contained in:
parent
c3df40862c
commit
c0919ac99b
|
@ -15,29 +15,28 @@ export class CopayApp {
|
|||
rootPage: any = TabsPage;
|
||||
|
||||
constructor(
|
||||
platform: Platform,
|
||||
statusBar: StatusBar,
|
||||
splashScreen: SplashScreen,
|
||||
log: Logger,
|
||||
app: AppProvider
|
||||
private platform: Platform,
|
||||
private statusBar: StatusBar,
|
||||
private splashScreen: SplashScreen,
|
||||
private logger: Logger,
|
||||
private app: AppProvider
|
||||
) {
|
||||
platform.ready().then(() => {
|
||||
app.getName().subscribe((name) => {
|
||||
log.info('Name: ' + name);
|
||||
});
|
||||
app.getVersion().subscribe((version) => {
|
||||
log.info('Version: ' + version);
|
||||
});
|
||||
app.getCommitHash().subscribe((commit) => {
|
||||
log.info('Commit Hash: #' + commit);
|
||||
});
|
||||
log.info('Platform: ' + platform.platforms());
|
||||
log.info('Language: ' + platform.lang());
|
||||
if (platform.is('cordova')) {
|
||||
statusBar.styleDefault();
|
||||
splashScreen.hide();
|
||||
|
||||
this.initializeApp();
|
||||
}
|
||||
|
||||
initializeApp() {
|
||||
this.platform.ready().then((readySource) => {
|
||||
this.logger.info(
|
||||
'Platform ready (' + readySource + '): ' +
|
||||
this.app.info.nameCase +
|
||||
' - v' + this.app.info.version +
|
||||
' #' + this.app.info.commitHash);
|
||||
|
||||
if (this.platform.is('cordova')) {
|
||||
this.statusBar.styleLightContent();
|
||||
this.splashScreen.hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,9 +36,10 @@ import { AppProvider } from '../providers/app/app';
|
|||
import { PlatformProvider } from '../providers/platform/platform';
|
||||
import { ConfigProvider } from '../providers/config/config';
|
||||
import { LanguageProvider } from '../providers/language/language';
|
||||
import { UnitProvider } from '../providers/unit/unit';
|
||||
|
||||
export function createTranslateLoader(http: Http) {
|
||||
return new TranslatePoHttpLoader(http, './assets/i18n/', '.po');
|
||||
return new TranslatePoHttpLoader(http, 'assets/i18n', '.po');
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
|
@ -89,8 +90,8 @@ export function createTranslateLoader(http: Http) {
|
|||
},
|
||||
{
|
||||
provide: APP_INITIALIZER,
|
||||
useFactory: (language: LanguageProvider) => () => language.load(),
|
||||
deps: [LanguageProvider],
|
||||
useFactory: (app: AppProvider) => () => app.load(),
|
||||
deps: [AppProvider],
|
||||
multi: true
|
||||
},
|
||||
{
|
||||
|
@ -103,7 +104,8 @@ export function createTranslateLoader(http: Http) {
|
|||
AppProvider,
|
||||
PlatformProvider,
|
||||
ConfigProvider,
|
||||
LanguageProvider
|
||||
LanguageProvider,
|
||||
UnitProvider
|
||||
]
|
||||
})
|
||||
export class AppModule { }
|
||||
|
|
|
@ -24,12 +24,8 @@ export class AboutPage {
|
|||
|
||||
ionViewDidLoad() {
|
||||
this.log.log('ionViewDidLoad AboutPage');
|
||||
this.app.getCommitHash().subscribe((data) => {
|
||||
this.commitHash = data;
|
||||
});
|
||||
this.app.getVersion().subscribe((data) => {
|
||||
this.version = data;
|
||||
});
|
||||
this.commitHash = this.app.info.commitHash;
|
||||
this.version = this.app.info.version;
|
||||
}
|
||||
|
||||
openTermsOfUse() {
|
||||
|
|
|
@ -10,11 +10,23 @@
|
|||
<ion-content>
|
||||
|
||||
<ion-list>
|
||||
<ion-item-divider color="light"> </ion-item-divider>
|
||||
<ion-item (click)="openAddressBookPage()">
|
||||
<ion-icon name="contacts" item-start></ion-icon>
|
||||
Address book
|
||||
</ion-item>
|
||||
<ion-item (click)="help()">
|
||||
<ion-icon name="help-circle" item-start></ion-icon>
|
||||
Help & support
|
||||
</ion-item>
|
||||
<ion-item (click)="feedback()">
|
||||
<ion-icon name="mail" item-start></ion-icon>
|
||||
Send feedback
|
||||
</ion-item>
|
||||
<ion-item (click)="share()">
|
||||
<ion-icon name="heart" item-start></ion-icon>
|
||||
Share {{ appName }}
|
||||
</ion-item>
|
||||
|
||||
<ion-item-divider color="light">Preferences</ion-item-divider>
|
||||
<ion-item (click)="openNotificationPage()">
|
||||
<ion-icon name="notifications" item-start></ion-icon>
|
||||
|
@ -25,12 +37,62 @@
|
|||
<ion-label>
|
||||
Language
|
||||
</ion-label>
|
||||
<ion-select [(ngModel)]="language">
|
||||
<ion-option value="en">English</ion-option>
|
||||
<ion-option value="es">Spanish</ion-option>
|
||||
<ion-select [(ngModel)]="currentLanguage" (ionChange)="setLanguage(currentLanguage)">
|
||||
<ion-option *ngFor="let lang of languages" [value]="lang.isoCode">{{ lang.name }}</ion-option>
|
||||
</ion-select>
|
||||
</ion-item>
|
||||
<ion-item-divider color="light"> </ion-item-divider>
|
||||
<ion-item>
|
||||
<ion-icon name="calculator" item-start></ion-icon>
|
||||
<ion-label>
|
||||
Bitcoin unit
|
||||
</ion-label>
|
||||
<ion-select [(ngModel)]="currentUnitCode" (ionChange)="setUnit(currentUnitCode)">
|
||||
<ion-option *ngFor="let unit of unitList" [value]="unit.code">{{ unit.shortName }}</ion-option>
|
||||
</ion-select>
|
||||
</ion-item>
|
||||
<ion-item>
|
||||
<ion-icon name="cash" item-start></ion-icon>
|
||||
<ion-label>
|
||||
Alternative currency
|
||||
</ion-label>
|
||||
<ion-select>
|
||||
<ion-option>USD</ion-option>
|
||||
<ion-option>ARS</ion-option>
|
||||
</ion-select>
|
||||
</ion-item>
|
||||
<ion-item>
|
||||
<ion-icon name="git-merge" item-start></ion-icon>
|
||||
<ion-label>
|
||||
Bitcoin network fee policy
|
||||
</ion-label>
|
||||
<ion-select>
|
||||
<ion-option>Normal</ion-option>
|
||||
<ion-option>Urgent</ion-option>
|
||||
</ion-select>
|
||||
</ion-item>
|
||||
<ion-item>
|
||||
<ion-icon name="lock" item-start></ion-icon>
|
||||
<ion-label>
|
||||
Lock
|
||||
</ion-label>
|
||||
<ion-select>
|
||||
<ion-option value="">Disabled</ion-option>
|
||||
<ion-option value="pin">Lock by PIN</ion-option>
|
||||
<ion-option value="finger">Lock by fingerprint</ion-option>
|
||||
</ion-select>
|
||||
</ion-item>
|
||||
|
||||
<ion-item-divider color="light">Wallets & integrations</ion-item-divider>
|
||||
<ion-item>
|
||||
<ion-icon name="folder" item-start></ion-icon>
|
||||
Wallet 1
|
||||
</ion-item>
|
||||
<ion-item>
|
||||
<ion-icon name="folder" item-start></ion-icon>
|
||||
Wallet 2
|
||||
</ion-item>
|
||||
|
||||
<ion-item-divider color="light">More</ion-item-divider>
|
||||
<ion-item (click)="openAboutPage()">
|
||||
<ion-icon name="apps" item-start></ion-icon>
|
||||
About {{appName}}
|
||||
|
|
|
@ -2,7 +2,8 @@ import { Component } from '@angular/core';
|
|||
import { NavController, NavParams } from 'ionic-angular';
|
||||
|
||||
import { AppProvider } from '../../providers/app/app';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { LanguageProvider } from '../../providers/language/language';
|
||||
import { UnitProvider } from '../../providers/unit/unit';
|
||||
|
||||
import { AboutPage } from '../about/about';
|
||||
|
||||
|
@ -11,25 +12,42 @@ import { AboutPage } from '../about/about';
|
|||
templateUrl: 'setting.html',
|
||||
})
|
||||
export class SettingPage {
|
||||
language: string;
|
||||
appName: string;
|
||||
currentLanguage: string;
|
||||
currentUnitCode: string;
|
||||
unitList: Array<any>;
|
||||
languages: Array<any>;
|
||||
bitcoinUnit: Array<string>
|
||||
|
||||
constructor(
|
||||
public navCtrl: NavController,
|
||||
public navParams: NavParams,
|
||||
public app: AppProvider,
|
||||
public i18n: TranslateService,
|
||||
private app: AppProvider,
|
||||
private language: LanguageProvider,
|
||||
private unit: UnitProvider
|
||||
) {
|
||||
app.getName().subscribe((data) => {
|
||||
this.appName = data;
|
||||
this.language = i18n.currentLang;
|
||||
});
|
||||
this.appName = this.app.info.nameCase;
|
||||
|
||||
this.currentUnitCode = this.unit.getCode();
|
||||
this.unitList = this.unit.getList();
|
||||
|
||||
this.currentLanguage = this.language.getCurrent();
|
||||
this.languages = this.language.getAvailables();
|
||||
}
|
||||
|
||||
ionViewDidLoad() {
|
||||
console.log('ionViewDidLoad SettingPage');
|
||||
}
|
||||
|
||||
setLanguage(lang: string) {
|
||||
this.currentLanguage = lang;
|
||||
this.language.set(lang);
|
||||
}
|
||||
|
||||
setUnit(code: string) {
|
||||
this.unit.setUnit(code);
|
||||
}
|
||||
|
||||
openAboutPage() {
|
||||
this.navCtrl.push(AboutPage);
|
||||
}
|
||||
|
|
|
@ -1,31 +1,83 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { Http, Response } from '@angular/http';
|
||||
import { Logger } from '@nsalaun/ng-logger';
|
||||
import 'rxjs/add/operator/map';
|
||||
|
||||
import { LanguageProvider } from '../../providers/language/language';
|
||||
import { UnitProvider } from '../../providers/unit/unit';
|
||||
import { ConfigProvider } from '../../providers/config/config';
|
||||
|
||||
interface App {
|
||||
WindowsStoreDisplayName: string;
|
||||
WindowsStoreIdentityName: string;
|
||||
androidVersion: string;
|
||||
appDescription: string;
|
||||
appUri: string;
|
||||
bundleName: string;
|
||||
commitHash: string;
|
||||
description: string;
|
||||
disclaimerUrl: string;
|
||||
gitHubRepoBugs: string;
|
||||
gitHubRepoName: string;
|
||||
gitHubRepoUrl: string;
|
||||
name: string;
|
||||
nameCase: string;
|
||||
nameCaseNoSpace: string;
|
||||
nameNoSpace: string;
|
||||
packageDescription: string;
|
||||
packageName: string;
|
||||
packageNameId: string;
|
||||
purposeLine: string;
|
||||
pushSenderId: string;
|
||||
statusBarColor: string;
|
||||
url: string;
|
||||
userVisibleName: string;
|
||||
version: string;
|
||||
winAppName: string;
|
||||
windowsAppId: string;
|
||||
_enabledExtensions: {
|
||||
amazon: boolean;
|
||||
coinbase: boolean;
|
||||
glidera: boolean;
|
||||
}
|
||||
_extraCSS: string;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class AppProvider {
|
||||
private jsonPath: string = '../assets/appConfig.json';
|
||||
public info: App;
|
||||
private jsonPath: string = 'assets/appConfig.json';
|
||||
|
||||
constructor(public http: Http) {}
|
||||
|
||||
getCommitHash() {
|
||||
return this.http.get(this.jsonPath)
|
||||
.map((res:Response) => res.json().commitHash);
|
||||
constructor(
|
||||
public http: Http,
|
||||
private logger: Logger,
|
||||
private language: LanguageProvider,
|
||||
private unit: UnitProvider,
|
||||
private config: ConfigProvider
|
||||
) {
|
||||
this.logger.info('AppProvider initialized.');
|
||||
}
|
||||
|
||||
getName() {
|
||||
return this.http.get(this.jsonPath)
|
||||
.map((res:Response) => res.json().nameCase);
|
||||
public load() {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.config.load().then((config) => {
|
||||
// storage -> config -> language -> unit -> app
|
||||
// Everything ok
|
||||
this.language.init(config);
|
||||
this.unit.init(config);
|
||||
this.getInfo().subscribe((info) => {
|
||||
this.info = info;
|
||||
resolve(true);
|
||||
});
|
||||
}).catch((err) => {
|
||||
// Something may be wrong
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getDescription() {
|
||||
getInfo() {
|
||||
return this.http.get(this.jsonPath)
|
||||
.map((res:Response) => res.json().description);
|
||||
.map((res:Response) => res.json());
|
||||
}
|
||||
|
||||
getVersion() {
|
||||
return this.http.get(this.jsonPath)
|
||||
.map((res:Response) => res.json().version);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import * as _ from "lodash";
|
|||
|
||||
@Injectable()
|
||||
export class LanguageProvider {
|
||||
public availables: Array<any> = [
|
||||
private languages: Array<any> = [
|
||||
{
|
||||
name: 'English',
|
||||
isoCode: 'en'
|
||||
|
@ -43,7 +43,7 @@ export class LanguageProvider {
|
|||
isoCode: 'pt',
|
||||
}
|
||||
];
|
||||
public current: string;
|
||||
private current: string;
|
||||
|
||||
constructor(
|
||||
private logger: Logger,
|
||||
|
@ -51,49 +51,57 @@ export class LanguageProvider {
|
|||
private config: ConfigProvider
|
||||
) {
|
||||
this.logger.info('LanguageProvider initialized.');
|
||||
this.translate.onLangChange.subscribe((event) => {
|
||||
this.logger.info('Setting language changed to: ' + event.lang);
|
||||
});
|
||||
}
|
||||
|
||||
load() {
|
||||
return new Promise((resolve, reject) => {
|
||||
init(config: object) {
|
||||
// Get from browser
|
||||
let browserLang = this.translate.getBrowserLang();
|
||||
let validBrowserLang = this.getName(browserLang) ? true : false;
|
||||
|
||||
this.config.load().then((config) => {
|
||||
let configLanguage = config['wallet']['settings']['defaultLanguage'];
|
||||
let configLanguage = config['wallet']['settings']['defaultLanguage']; // TODO
|
||||
if (configLanguage) this.current = configLanguage;
|
||||
else {
|
||||
if (validBrowserLang) this.current = browserLang;
|
||||
else this.current = this.getDefaultLanguage(); // default
|
||||
else this.current = this.getDefault();
|
||||
}
|
||||
this.translate.setDefaultLang(this.current);
|
||||
resolve(true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
set(lang: string) {
|
||||
this.current = lang;
|
||||
this.translate.use(lang);
|
||||
this.config.set({language: lang});
|
||||
this.config.set({wallet: { settings: { defaultLanguage: lang } } });
|
||||
}
|
||||
|
||||
getName(lang: string) {
|
||||
return _.result(_.find(this.availables, {
|
||||
return _.result(_.find(this.languages, {
|
||||
'isoCode': lang
|
||||
}), 'name');
|
||||
}
|
||||
|
||||
getDefaultLanguage() {
|
||||
return this.availables[0]['isoCode'];
|
||||
getDefault() {
|
||||
return this.languages[0]['isoCode'];
|
||||
}
|
||||
|
||||
getCurrentLanguage() {
|
||||
getCurrent() {
|
||||
return this.current;
|
||||
}
|
||||
|
||||
getLanguages() {
|
||||
return this.availables;
|
||||
getCurrentName() {
|
||||
return this.getName(this.current);
|
||||
}
|
||||
|
||||
getCurrentInfo() {
|
||||
return _.find(this.languages, {
|
||||
'isoCode': this.current
|
||||
});
|
||||
}
|
||||
|
||||
getAvailables() {
|
||||
return this.languages;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { Logger } from '@nsalaun/ng-logger';
|
||||
|
||||
import { ConfigProvider } from '../../providers/config/config';
|
||||
|
||||
import * as _ from 'lodash';
|
||||
|
||||
interface Unit {
|
||||
name: string;
|
||||
shortName: string;
|
||||
value: number;
|
||||
decimals: number;
|
||||
code: string;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class UnitProvider {
|
||||
public info: Unit;
|
||||
private unitList: Array<Unit> = [{
|
||||
name: 'bits (1,000,000 bits = 1BTC)',
|
||||
shortName: 'bits',
|
||||
value: 100,
|
||||
decimals: 2,
|
||||
code: 'bit',
|
||||
}, {
|
||||
name: 'BTC',
|
||||
shortName: 'BTC',
|
||||
value: 100000000,
|
||||
decimals: 8,
|
||||
code: 'btc',
|
||||
}];
|
||||
|
||||
constructor(
|
||||
private config: ConfigProvider,
|
||||
private logger: Logger
|
||||
) {
|
||||
this.logger.info('UnitProvider initialized.');
|
||||
}
|
||||
|
||||
private getItem(code: string) {
|
||||
return _.find(this.unitList, {
|
||||
'code': code
|
||||
});
|
||||
}
|
||||
|
||||
init(config: object) {
|
||||
let code = config['wallet']['settings']['unitCode']; // TODO
|
||||
this.info = this.getItem(code);
|
||||
}
|
||||
|
||||
getList() {
|
||||
return this.unitList;
|
||||
}
|
||||
|
||||
getCode() {
|
||||
return this.info.code;
|
||||
}
|
||||
|
||||
setUnit(code: string) {
|
||||
this.info = this.getItem(code);
|
||||
this.config.set({ wallet: { settings: this.info } });
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue