Skip to content
Permalink
Browse files

Currency Provider refactor rebased on master

  • Loading branch information...
justinkook committed Oct 22, 2019
1 parent c836b7d commit d55d03a69307b642f9baa3e161d7adfb2f5e4ef6
Showing with 829 additions and 709 deletions.
  1. +7 −9 src/components/incoming-data-menu/incoming-data-menu.ts
  2. +26 −30 src/components/price-card/price-card.ts
  3. +18 −46 src/components/wallet-selector/wallet-selector.html
  4. +17 −11 src/components/wallet-selector/wallet-selector.ts
  5. +2 −5 src/environments/prod.ts
  6. +2 −5 src/environments/schema.ts
  7. +2 −2 src/pages/add/create-wallet/create-wallet.html
  8. +12 −11 src/pages/add/create-wallet/create-wallet.ts
  9. +3 −3 src/pages/add/import-wallet/import-wallet.html
  10. +11 −12 src/pages/add/import-wallet/import-wallet.ts
  11. +1 −1 src/pages/add/join-wallet/join-wallet.ts
  12. +17 −39 src/pages/add/select-currency/select-currency.html
  13. +25 −14 src/pages/add/select-currency/select-currency.ts
  14. +5 −5 src/pages/home/home.ts
  15. +8 −18 src/pages/includes/coin-selector/coin-selector.html
  16. +9 −1 src/pages/includes/coin-selector/coin-selector.ts
  17. +2 −1 src/pages/includes/multiple-outputs/multiple-outputs.ts
  18. +9 −7 src/pages/integrations/bitpay-card/bitpay-card-topup/bitpay-card-topup.ts
  19. +2 −1 src/pages/integrations/coinbase/buy-coinbase/buy-coinbase.ts
  20. +2 −1 src/pages/integrations/coinbase/sell-coinbase/sell-coinbase.ts
  21. +9 −8 src/pages/integrations/gift-cards/confirm-card-purchase/confirm-card-purchase.ts
  22. +4 −4 src/pages/integrations/invoice/confirm-invoice/confirm-invoice.html
  23. +22 −26 src/pages/integrations/invoice/confirm-invoice/confirm-invoice.ts
  24. +8 −3 src/pages/integrations/shapeshift/shapeshift-confirm/shapeshift-confirm.ts
  25. +15 −7 src/pages/integrations/shapeshift/shapeshift-details/shapeshift-details.ts
  26. +8 −10 src/pages/paper-wallet/paper-wallet.ts
  27. +4 −6 src/pages/receive/custom-amount/custom-amount.ts
  28. +1 −1 src/pages/send/amount/amount.html
  29. +1 −1 src/pages/send/amount/amount.spec.ts
  30. +23 −36 src/pages/send/amount/amount.ts
  31. +16 −15 src/pages/send/choose-fee-level/choose-fee-level.ts
  32. +16 −23 src/pages/send/confirm/confirm.ts
  33. +8 −7 src/pages/send/multi-send/multi-send.ts
  34. +3 −3 src/pages/send/send.html
  35. +1 −2 src/pages/send/send.spec.ts
  36. +20 −22 src/pages/send/send.ts
  37. +21 −67 src/pages/send/transfer-to/transfer-to.html
  38. +60 −11 src/pages/send/transfer-to/transfer-to.spec.ts
  39. +34 −41 src/pages/send/transfer-to/transfer-to.ts
  40. +2 −2 src/pages/settings/wallet-settings/wallet-settings-advanced/wallet-duplicate/wallet-duplicate.ts
  41. +1 −1 ...ages/settings/wallet-settings/wallet-settings-advanced/wallet-information/wallet-information.html
  42. +6 −7 src/pages/settings/wallet-settings/wallet-settings-advanced/wallet-information/wallet-information.ts
  43. +6 −7 ...wallet-settings/wallet-settings-advanced/wallet-transaction-history/wallet-transaction-history.ts
  44. +3 −1 src/pages/txp-details/txp-details.ts
  45. +1 −1 src/pages/wallet-details/wallet-details.html
  46. +6 −4 src/pages/wallet-details/wallet-details.ts
  47. +1 −1 src/pages/wallet-tabs/wallet-tabs.provider.ts
  48. +6 −11 src/pipes/fiatToUnit.ts
  49. +4 −4 src/pipes/satToUnit.ts
  50. +2 −0 src/providers/app/app.spec.ts
  51. +8 −41 src/providers/config/config.ts
  52. +150 −0 src/providers/currency/coin.ts
  53. +106 −0 src/providers/currency/currency.ts
  54. +1 −1 src/providers/incoming-data/incoming-data.ts
  55. +1 −0 src/providers/index.ts
  56. +0 −1 src/providers/on-going-process/on-going-process.ts
  57. +5 −2 src/providers/paypro/paypro.ts
  58. +3 −7 src/providers/profile/profile.ts
  59. +2 −0 src/providers/providers.module.ts
  60. +16 −40 src/providers/rate/rate.ts
  61. +17 −11 src/providers/tx-format/tx-format.spec.ts
  62. +10 −13 src/providers/tx-format/tx-format.ts
  63. +7 −6 src/providers/wallet/wallet.spec.ts
  64. +9 −31 src/providers/wallet/wallet.ts
  65. +1 −1 test/tsconfig.ng-cli.json
  66. +1 −1 tsconfig.json
@@ -1,13 +1,8 @@
import { Component } from '@angular/core';
import { Coin, CurrencyProvider } from '../../providers/currency/currency';
import { PlatformProvider } from '../../providers/platform/platform';
import { ActionSheetParent } from '../action-sheet/action-sheet-parent';

enum CoinName {
BTC = 'Bitcoin',
BCH = 'Bitcoin Cash',
ETH = 'Ethereum'
}

@Component({
selector: 'incoming-data-menu',
templateUrl: 'incoming-data-menu.html'
@@ -16,12 +11,15 @@ export class IncomingDataMenuComponent extends ActionSheetParent {
public https: boolean;
public data: string;
public type: string;
public coin: string;
public coin: Coin;
public coinName: string;
public fromHomeCard: boolean;
public isCordova: boolean;

constructor(private platformProvider: PlatformProvider) {
constructor(
private currencyProvider: CurrencyProvider,
private platformProvider: PlatformProvider
) {
super();
this.isCordova = this.platformProvider.isCordova;
}
@@ -31,7 +29,7 @@ export class IncomingDataMenuComponent extends ActionSheetParent {
this.data = this.params.data.data;
this.type = this.params.data.type;
this.coin = this.params.data.coin;
this.coinName = CoinName[this.coin.toUpperCase()];
this.coinName = this.currencyProvider.getCoinName(this.coin);
this.fromHomeCard = this.params.data.fromHomeCard;
if (this.type === 'url') {
this.https = this.data.indexOf('https://') === 0 ? true : false;
@@ -1,7 +1,13 @@
import { Component, QueryList, ViewChildren } from '@angular/core';
import * as _ from 'lodash';
import * as moment from 'moment';
import { ConfigProvider, Logger, PriceProvider } from '../../providers';
import {
ConfigProvider,
CurrencyProvider,
Logger,
PriceProvider
} from '../../providers';
import { Coin } from '../../providers/currency/currency';
import { PriceChart } from './price-chart/price-chart';

@Component({
@@ -14,35 +20,7 @@ export class PriceCard {
public lineChart: any;
public isoCode: string;
public lastDates = 6;
public coins = [
{
unitCode: 'btc',
historicalRates: [],
currentPrice: 0,
averagePrice: 0,
backgroundColor: 'rgba(247,146,26,1)',
gradientBackgroundColor: 'rgba(247,146,26, 0.2)',
name: 'Bitcoin'
},
{
unitCode: 'bch',
historicalRates: [],
currentPrice: 0,
averagePrice: 0,
backgroundColor: 'rgba(47,207,110,1)',
gradientBackgroundColor: 'rgba(47,207,110, 0.2)',
name: 'Bitcoin Cash'
},
{
unitCode: 'eth',
historicalRates: [],
currentPrice: 0,
averagePrice: 0,
backgroundColor: 'rgba(135,206,250,1)',
gradientBackgroundColor: 'rgba(30,144,255, 0.2)',
name: 'Ethereum'
}
];
public coins = [];
public fiatCodes = [
'USD',
'INR',
@@ -57,10 +35,28 @@ export class PriceCard {
];

constructor(
private currencyProvider: CurrencyProvider,
private priceProvider: PriceProvider,
private configProvider: ConfigProvider,
private logger: Logger
) {
const availableChains = this.currencyProvider.getAvailableChains();
for (const coin of availableChains) {
const {
backgroundColor,
gradientBackgroundColor
} = this.currencyProvider.getTheme(coin as Coin);
const card = {
unitCode: coin,
historicalRates: [],
currentPrice: 0,
averagePrice: 0,
backgroundColor,
gradientBackgroundColor,
name: this.currencyProvider.getCoinName(coin as Coin)
};
this.coins.push(card);
}
this.getPrices();
}

@@ -7,54 +7,26 @@
</ion-col>
<ion-col col-4 text-center class="destination-title">{{ title }}</ion-col>
</ion-row>
<!--<div *ngFor="let wallet of wallets" (click)="selectWallet(wallet)">{{wallet.name}}</div>-->
<div class="no-wallets" *ngIf="(!walletsBtc || !walletsBtc[0]) && (!walletsBch || !walletsBch[0]) && (!walletsEth || !walletsEth[0])" translate>
No wallets available
</div>
<div *ngIf="walletsBtc && walletsBtc[0]">
<ion-item-divider>
<div class="title">
<span translate>Bitcoin Wallets</span>
</div>
</ion-item-divider>

<ion-list>
<button ion-item detail-none *ngFor="let wallet of walletsBtc" (click)="optionClicked(wallet)">
<wallet-item-content [wallet]="wallet"></wallet-item-content>
</button>
</ion-list>
</div>

<div *ngIf="walletsBch && walletsBch[0]">
<ion-item-divider>
<div class="title">
<span translate>Bitcoin Cash Wallets</span>
</div>
</ion-item-divider>

<ion-list>
<div>
<button ion-item detail-none *ngFor="let wallet of walletsBch" (click)="optionClicked(wallet)">
<wallet-item-content [wallet]="wallet"></wallet-item-content>
</button>
</div>
</ion-list>
</div>
<div *ngFor="let coin of availableCoins">
<div class="no-wallets" *ngIf="(!wallets[coin] && !wallets[coin][0])" translate>
No wallets available
</div>

<div *ngIf="walletsEth && walletsEth[0]">
<ion-item-divider>
<div class="title">
<span translate>Ethereum Wallets</span>
</div>
</ion-item-divider>
<div *ngIf="wallets && wallets[coin][0]">
<ion-item-divider>
<div class="title">
<span translate>{{ getCoinName(coin) }} Wallets</span>
</div>
</ion-item-divider>

<ion-list>
<div>
<button ion-item detail-none *ngFor="let wallet of walletsEth" (click)="optionClicked(wallet)">
<wallet-item-content [wallet]="wallet"></wallet-item-content>
</button>
</div>
</ion-list>
<ion-list>
<div>
<button ion-item detail-none *ngFor="let wallet of wallets[coin]" (click)="optionClicked(wallet)">
<wallet-item-content [wallet]="wallet"></wallet-item-content>
</button>
</div>
</ion-list>
</div>
</div>
<ion-item-divider></ion-item-divider>
</action-sheet>
@@ -1,33 +1,39 @@
import { Component } from '@angular/core';
import {
Coin,
CoinsMap,
CurrencyProvider
} from '../../providers/currency/currency';
import { ActionSheetParent } from '../action-sheet/action-sheet-parent';

@Component({
selector: 'wallet-selector',
templateUrl: 'wallet-selector.html'
})
export class WalletSelectorComponent extends ActionSheetParent {
public wallets;
public walletsBtc;
public walletsBch;
public walletsEth;
public wallets = {} as CoinsMap<any>;
public availableCoins: Coin[];
public title: string;
public selectedWalletId: string;

constructor() {
constructor(private currencyProvider: CurrencyProvider) {
super();
this.availableCoins = this.currencyProvider.getAvailableCoins();
}

ngOnInit() {
this.wallets = this.params.wallets;
this.title = this.params.title;
this.selectedWalletId = this.params.selectedWalletId;
this.separateWallets();
}

public getCoinName(coin: Coin) {
return this.currencyProvider.getCoinName(coin);
}

private separateWallets(): void {
this.walletsBtc = this.wallets.filter(wallet => wallet.coin === 'btc');
this.walletsBch = this.wallets.filter(wallet => wallet.coin === 'bch');
this.walletsEth = this.wallets.filter(wallet => wallet.coin === 'eth');
const wallets = this.params.wallets;
for (const coin of this.availableCoins) {
this.wallets[coin] = wallets.filter(wallet => wallet.coin === coin);
}
}

public optionClicked(option): void {
@@ -1,3 +1,4 @@
import { CurrencyProvider } from '../providers/currency/currency';
import { EnvironmentSchema } from './schema';

/**
@@ -6,11 +7,7 @@ import { EnvironmentSchema } from './schema';
const env: EnvironmentSchema = {
name: 'production',
enableAnimations: true,
ratesAPI: {
btc: 'https://bitpay.com/api/rates',
bch: 'https://bitpay.com/api/rates/bch',
eth: 'https://bitpay.com/api/rates/eth'
},
ratesAPI: new CurrencyProvider().getRatesApi(),
activateScanner: true
};

@@ -1,14 +1,11 @@
import { CoinsMap } from '../providers/currency/currency';
/**
* Copay does not yet build with Angular CLI, but our environment system works
* the same way.
*/
export interface EnvironmentSchema {
name: 'production' | 'development';
enableAnimations: boolean;
ratesAPI: {
btc: string;
bch: string;
eth: string;
};
ratesAPI: CoinsMap<string>;
activateScanner: boolean;
}
@@ -59,7 +59,7 @@
<ion-input type="text" formControlName="recoveryPhrase"></ion-input>
</ion-item>

<ion-item [ngClass]="{'with-label': createForm.value.testnetEnabled}" *ngIf="checkIfUtxoCoin() && createForm.value.selectedSeed == 'new'">
<ion-item [ngClass]="{'with-label': createForm.value.testnetEnabled}" *ngIf="createForm.value.selectedSeed == 'new'">
<ion-label>Testnet</ion-label>
<ion-toggle formControlName="testnetEnabled" (ionChange)="setDerivationPath()"></ion-toggle>
</ion-item>
@@ -76,7 +76,7 @@
<ion-input type="text" formControlName="derivationPath"></ion-input>
</ion-item>

<ion-item *ngIf="checkIfUtxoCoin()" [ngClass]="{'with-label': createForm.value.singleAddress}">
<ion-item *ngIf="!isSingleAddress()" [ngClass]="{'with-label': createForm.value.singleAddress}">
<ion-label>{{'Single address' | translate}}</ion-label>
<ion-toggle formControlName="singleAddress"></ion-toggle>
</ion-item>
@@ -13,6 +13,7 @@ import * as _ from 'lodash';
import { BwcErrorProvider } from '../../../providers/bwc-error/bwc-error';
import { BwcProvider } from '../../../providers/bwc/bwc';
import { ConfigProvider } from '../../../providers/config/config';
import { Coin, CurrencyProvider } from '../../../providers/currency/currency';
import { DerivationPathHelperProvider } from '../../../providers/derivation-path-helper/derivation-path-helper';
import { ExternalLinkProvider } from '../../../providers/external-link/external-link';
import { Logger } from '../../../providers/logger/logger';
@@ -22,7 +23,6 @@ import { PopupProvider } from '../../../providers/popup/popup';
import { ProfileProvider } from '../../../providers/profile/profile';
import { PushNotificationsProvider } from '../../../providers/push-notifications/push-notifications';
import {
UTXO_COINS,
WalletOptions,
WalletProvider
} from '../../../providers/wallet/wallet';
@@ -63,14 +63,14 @@ export class CreateWalletPage implements OnInit {
public showAdvOpts: boolean;
public seedOptions;
public isShared: boolean;
public coin: string;
public coin: Coin;
public okText: string;
public cancelText: string;
public createForm: FormGroup;
public createLabel: string;
public UTXO_COINS;

constructor(
private currencyProvider: CurrencyProvider,
private navCtrl: NavController,
private navParams: NavParams,
private fb: FormBuilder,
@@ -94,7 +94,6 @@ export class CreateWalletPage implements OnInit {
this.cancelText = this.translate.instant('Cancel');
this.isShared = this.navParams.get('isShared');
this.coin = this.navParams.get('coin');
this.UTXO_COINS = UTXO_COINS;
this.keyId = this.navParams.get('keyId');
this.defaults = this.configProvider.getDefaults();
this.tc = this.isShared ? this.defaults.wallet.totalCopayers : 1;
@@ -108,9 +107,9 @@ export class CreateWalletPage implements OnInit {
.getCore()
.Deriver.pathFor(this.coin, 'testnet');
this.showAdvOpts = false;

const walletName = this.currencyProvider.getCoinName(this.coin);
this.createForm = this.fb.group({
walletName: [null, Validators.required],
walletName: [walletName, Validators.required],
myName: [null],
totalCopayers: [1],
requiredCopayers: [1],
@@ -151,8 +150,8 @@ export class CreateWalletPage implements OnInit {
);
}

public checkIfUtxoCoin() {
return !!this.UTXO_COINS[this.coin.toUpperCase()];
public isSingleAddress() {
return this.currencyProvider.isSingleAddress(this.coin);
}

private updateSeedSourceSelect(): void {
@@ -207,9 +206,11 @@ export class CreateWalletPage implements OnInit {
: null,
networkName: this.createForm.value.testnetEnabled ? 'testnet' : 'livenet',
bwsurl: this.createForm.value.bwsURL,
singleAddress: this.checkIfUtxoCoin()
? this.createForm.value.singleAddress
: true,
singleAddress: this.currencyProvider.isSingleAddress(
this.createForm.value.coin
)
? true
: this.createForm.value.singleAddress,
coin: this.createForm.value.coin
};

@@ -69,9 +69,9 @@
<ion-item *ngIf="importForm.value.derivationPathEnabled">
<ion-label floating>{{'Coin' | translate}}</ion-label>
<ion-select okText="{{okText}}" cancelText="{{cancelText}}" formControlName="coin" (ionChange)="setDerivationPath($event)">
<ion-option value="btc">Bitcoin (BTC)</ion-option>
<ion-option value="bch">Bitcoin Cash (BCH)</ion-option>
<ion-option value="eth">Ethereum (ETH)</ion-option>
<div *ngFor="let coin of availableCoins">
<ion-option value="{{coin}}"> {{ getCoinName(coin) }} ({{ coin.toUpperCase() }})</ion-option>
</div>
</ion-select>
</ion-item>

0 comments on commit d55d03a

Please sign in to comment.
You can’t perform that action at this time.