Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
Develop

See merge request papers/tezblock/tezblock-frontend!496
  • Loading branch information
godenzim committed Apr 16, 2020
2 parents cc7f567 + 8b92b4f commit 543470b
Show file tree
Hide file tree
Showing 61 changed files with 1,079 additions and 411 deletions.
53 changes: 26 additions & 27 deletions scripts/add-environment-variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,30 @@ env_file="./src/environments/environment.ts"
npmrc="./.npmrc"

replace_main_rpc_url_pattern="s~'MAINNET_RPC_URL'\(,\)\{0,1\}~'${MAINNET_RPC_URL}'\1~g"
replace_babylon_rpc_url_pattern="s~'BABYLONNET_RPC_URL'\(,\)\{0,1\}~'${BABYLONNET_RPC_URL}'\1~g"
replace_carthage_rpc_url_pattern="s~'CARTHAGENET_RPC_URL'\(,\)\{0,1\}~'${CARTHAGENET_RPC_URL}'\1~g"

replace_main_conseil_url_pattern="s~'MAINNET_CONSEIL_URL'\(,\)\{0,1\}~'${MAINNET_CONSEIL_URL}'\1~g"
replace_babylon_conseil_url_pattern="s~'BABYLONNET_CONSEIL_URL'\(,\)\{0,1\}~'${BABYLONNET_CONSEIL_URL}'\1~g"
replace_carthage_conseil_url_pattern="s~'CARTHAGENET_CONSEIL_URL'\(,\)\{0,1\}~'${CARTHAGENET_CONSEIL_URL}'\1~g"

replace_main_conseil_api_pattern="s/'MAINNET_CONSEIL_API_KEY'\(,\)\{0,1\}/'${MAINNET_CONSEIL_API_KEY}'\1/g"
replace_babylon_conseil_api_pattern="s/'BABYLONNET_CONSEIL_API_KEY'\(,\)\{0,1\}/'${BABYLONNET_CONSEIL_API_KEY}'\1/g"
replace_carthage_conseil_api_pattern="s/'CARTHAGENET_CONSEIL_API_KEY'\(,\)\{0,1\}/'${CARTHAGENET_CONSEIL_API_KEY}'\1/g"

replace_main_target_url_pattern="s~'MAINNET_TARGET_URL'\(,\)\{0,1\}~'${MAINNET_TARGET_URL}'\1~g"
replace_babylon_target_url_pattern="s~'BABYLONNET_TARGET_URL'\(,\)\{0,1\}~'${BABYLONNET_TARGET_URL}'\1~g"
replace_carthage_target_url_pattern="s~'CARTHAGENET_TARGET_URL'\(,\)\{0,1\}~'${CARTHAGENET_TARGET_URL}'\1~g"

# replace_ga_pattern="s/'GA_KEY'\(,\)\{0,1\}/'${GA_KEY}'\1/g"
replace_ga_pattern="s/googleAnalyticsKey: undefined\(,\)\{0,1\}/googleAnalyticsKey: '${GA_KEY}'\1/g"
replace_fa_pattern="s/proFontAwesomeAvailable: false\(,\)\{0,1\}$/proFontAwesomeAvailable: true\1/g"

free_fa_add_file="./src/app/fa-add.ts"
pro_fa_add_file="./src/app/fa-add.excluded.ts"

needs_env_backup () {
[[ ! -z "${MAINNET_RPC_URL}" ]] || [[ ! -z "${BABYLONNET_RPC_URL}" ]] || [[ ! -z "${CARTHAGENET_RPC_URL}" ]] ||
[[ ! -z "${MAINNET_CONSEIL_URL}" ]] || [[ ! -z "${BABYLONNET_CONSEIL_URL}" ]] || [[ ! -z "${CARTHAGENET_CONSEIL_URL}" ]] ||
[[ ! -z "${MAINNET_CONSEIL_API_KEY}" ]] || [[ ! -z "${BABYLONNET_CONSEIL_API_KEY}" ]] || [[ ! -z "${CARTHAGENET_CONSEIL_API_KEY}" ]] ||
[[ ! -z "${MAINNET_TARGET_URL}" ]] || [[ ! -z "${BABYLONNET_TARGET_URL}" ]] || [[ ! -z "${CARTHAGENET_TARGET_URL}" ]] ||
[[ ! -z "${MAINNET_RPC_URL}" ]] || [[ ! -z "${CARTHAGENET_RPC_URL}" ]] ||
[[ ! -z "${MAINNET_CONSEIL_URL}" ]] || [[ ! -z "${CARTHAGENET_CONSEIL_URL}" ]] ||
[[ ! -z "${MAINNET_CONSEIL_API_KEY}" ]] || [[ ! -z "${CARTHAGENET_CONSEIL_API_KEY}" ]] ||
[[ ! -z "${MAINNET_TARGET_URL}" ]] || [[ ! -z "${CARTHAGENET_TARGET_URL}" ]] ||
[[ ! -z "${GA_KEY}" ]] ||
[[ ! -z "${FONTAWESOME_NPM_AUTH_TOKEN}" ]]
}

Expand All @@ -53,9 +54,6 @@ replace_rpc_url () {
if [[ ! -z "${MAINNET_RPC_URL}" ]]; then
replace_in_env_files "${replace_main_rpc_url_pattern}"
fi
if [[ ! -z "${BABYLONNET_RPC_URL}" ]]; then
replace_in_env_files "${replace_babylon_rpc_url_pattern}"
fi
if [[ ! -z "${CARTHAGENET_RPC_URL}" ]]; then
replace_in_env_files "${replace_carthage_rpc_url_pattern}"
fi
Expand All @@ -65,9 +63,6 @@ replace_conseil_url () {
if [[ ! -z "${MAINNET_CONSEIL_URL}" ]]; then
replace_in_env_files "${replace_main_conseil_url_pattern}"
fi
if [[ ! -z "${BABYLONNET_CONSEIL_URL}" ]]; then
replace_in_env_files "${replace_babylon_conseil_url_pattern}"
fi
if [[ ! -z "${CARTHAGENET_CONSEIL_URL}" ]]; then
replace_in_env_files "${replace_carthage_conseil_url_pattern}"
fi
Expand All @@ -77,9 +72,6 @@ replace_conseil_api_key () {
if [[ ! -z "${MAINNET_CONSEIL_API_KEY}" ]]; then
replace_in_env_files "${replace_main_conseil_api_pattern}"
fi
if [[ ! -z "${BABYLONNET_CONSEIL_API_KEY}" ]]; then
replace_in_env_files "${replace_babylon_conseil_api_pattern}"
fi
if [[ ! -z "${CARTHAGENET_CONSEIL_API_KEY}" ]]; then
replace_in_env_files "${replace_carthage_conseil_api_pattern}"
fi
Expand All @@ -89,35 +81,42 @@ replace_target_url () {
if [[ ! -z "${MAINNET_TARGET_URL}" ]]; then
replace_in_env_files "${replace_main_target_url_pattern}"
fi
if [[ ! -z "${BABYLONNET_TARGET_URL}" ]]; then
replace_in_env_files "${replace_babylon_target_url_pattern}"
fi
if [[ ! -z "${CARTHAGENET_TARGET_URL}" ]]; then
replace_in_env_files "${replace_carthage_target_url_pattern}"
fi
}

if needs_env_backup; then
if [[ -f "$prod_env_file" ]] && [[ -f "$env_file" ]] && [[ ! -f "${prod_env_file}.tmp" ]] && [[ ! -f "${env_file}.tmp" ]]; then
cp "${prod_env_file}" "${prod_env_file}.tmp"
cp "${env_file}" "${env_file}.tmp"
replace_ga_key () {
if [[ ! -z "${GA_KEY}" ]]; then
replace_in_env_files "${replace_ga_pattern}"
fi
fi
}

if [[ ! -z "${FONTAWESOME_NPM_AUTH_TOKEN}" ]]; then
replace_fa_settings () {
if [[ ! -z "${FONTAWESOME_NPM_AUTH_TOKEN}" ]]; then
if [[ -f "${npmrc}" ]]; then
replace_in_file 's~\# \(.*\)~\1~g' "${npmrc}"
fi
if [[ -f "${prod_env_file}" ]] && [[ -f "${env_file}" ]]; then
replace_in_env_files 's/proFontAwesomeAvailable: false$/proFontAwesomeAvailable: true/g'
replace_in_env_files "${replace_fa_pattern}"
fi
if [[ -f "${free_fa_add_file}" ]] && [[ -f "${pro_fa_add_file}" ]]; then
mv "${free_fa_add_file}" "${free_fa_add_file}.tmp"
mv "${pro_fa_add_file}" "${free_fa_add_file}"
fi
fi
}

if needs_env_backup; then
if [[ -f "$prod_env_file" ]] && [[ -f "$env_file" ]] && [[ ! -f "${prod_env_file}.tmp" ]] && [[ ! -f "${env_file}.tmp" ]]; then
cp "${prod_env_file}" "${prod_env_file}.tmp"
cp "${env_file}" "${env_file}.tmp"
fi
fi

replace_fa_settings
replace_rpc_url
replace_conseil_url
replace_conseil_api_key
replace_target_url
replace_ga_key
2 changes: 2 additions & 0 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import { ContractDetailComponent } from './pages/contract-detail/contract-detail
import { BakerOverviewComponent } from './pages/baker-overview/baker-overview.component'
import { HealthComponent } from './pages/health/health.component'
import { AccountOverviewComponent } from './pages/account-overview/account-overview.component'
import { TokenContractOverviewComponent } from './pages/token-contract-overview/token-contract-overview.component'

const routes: Routes = [
{ path: '', component: DashboardComponent },
{ path: 'resources/wallets', component: ResourcesWalletsComponent },
{ path: 'baker/list', component: BakerOverviewComponent },
{ path: 'account/list', component: AccountOverviewComponent },
{ path: 'token-contract/list', component: TokenContractOverviewComponent },
{ path: ':route/list', component: ListComponent },
{ path: 'block/:id', component: BlockDetailComponent },
{ path: 'account/:id', component: AccountDetailComponent },
Expand Down
7 changes: 7 additions & 0 deletions src/app/app.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ export const loadCryptoPriceSucceeded = createAction(
)
export const loadCryptoPriceFailed = createAction(`[${featureName}] Load Crypto Price Failed`, props<{ error: any }>())

export const loadExchangeRate = createAction(`[${featureName}] Load Exchange Rate`, props<{ from: string, to: string }>())
export const loadExchangeRateSucceeded = createAction(
`[${featureName}] Load Exchange Rate Succeeded`,
props<{ from: string, to: string, price: number }>()
)
export const loadExchangeRateFailed = createAction(`[${featureName}] Load Exchange Rate Failed`, props<{ error: any }>())

export const loadCryptoHistoricData = createAction(`[${featureName}] Load Crypto Historic Data`)
export const loadCryptoHistoricDataSucceeded = createAction(
`[${featureName}] Load Crypto Historic Data Succeeded`,
Expand Down
27 changes: 17 additions & 10 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component } from '@angular/core'
import { Component, OnInit } from '@angular/core'
import { Router, NavigationEnd } from '@angular/router'
import { filter } from 'rxjs/operators'
import { Store } from '@ngrx/store'
Expand All @@ -7,14 +7,20 @@ import { Actions, ofType } from '@ngrx/effects'
import * as actions from './app.actions'
import * as fromRoot from '@tezblock/reducers'
import { getRefresh } from '@tezblock/domain/synchronization'
import { AnalyticsService } from './services/analytics/analytics.service'

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
constructor(private readonly actions$: Actions, readonly router: Router, private readonly store$: Store<fromRoot.State>) {
export class AppComponent implements OnInit {
constructor(
private readonly actions$: Actions,
readonly router: Router,
private readonly store$: Store<fromRoot.State>,
private readonly analyticsService: AnalyticsService
) {
this.router.events
.pipe(filter(e => e instanceof NavigationEnd))
.subscribe(e => this.store$.dispatch(actions.saveLatestRoute({ navigation: <NavigationEnd>e })))
Expand All @@ -23,23 +29,24 @@ export class AppComponent {
this.actions$.pipe(ofType(actions.loadLatestBlockSucceeded)),
this.actions$.pipe(ofType(actions.loadLatestBlockFailed))
]).subscribe(() => this.store$.dispatch(actions.loadLatestBlock())),

this.store$.dispatch(actions.loadCryptoPriceFromCache())
this.store$.dispatch(actions.loadCryptoPriceFromCache())

getRefresh([
this.actions$.pipe(ofType(actions.loadCryptoPriceSucceeded)),
this.actions$.pipe(ofType(actions.loadCryptoPriceFailed))
]).subscribe(() => this.store$.dispatch(actions.loadCryptoPrice())),

getRefresh([
this.actions$.pipe(ofType(actions.loadCryptoHistoricDataSucceeded)),
this.actions$.pipe(ofType(actions.loadCryptoHistoricDataFailed))
]).subscribe(() => this.store$.dispatch(actions.loadCryptoHistoricData()))
getRefresh([
this.actions$.pipe(ofType(actions.loadCryptoHistoricDataSucceeded)),
this.actions$.pipe(ofType(actions.loadCryptoHistoricDataFailed))
]).subscribe(() => this.store$.dispatch(actions.loadCryptoHistoricData()))

this.store$.dispatch(actions.loadPeriodInfos())
}

navigate(entity: string) {
this.router.navigate([`${entity}/list`])
}
ngOnInit() {
this.analyticsService.init()
}
}
49 changes: 39 additions & 10 deletions src/app/app.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import { BaseService, Operation, ENVIRONMENT_URL } from '@tezblock/services/base
import { Block } from '@tezblock/interfaces/Block'
import { first } from '@tezblock/services/fp'
import * as fromRoot from '@tezblock/reducers'
import { ByCycleState, CacheService, CacheKeys, Currency } from '@tezblock/services/cache/cache.service'
import { ByCycleState, CacheService, CacheKeys, ExchangeRates } from '@tezblock/services/cache/cache.service'
import { BlockService } from '@tezblock/services/blocks/blocks.service'
import { CryptoPricesService } from '@tezblock/services/crypto-prices/crypto-prices.service'
import { Currency } from '@tezblock/domain/airgap'

@Injectable()
export class AppEffects {
Expand Down Expand Up @@ -123,10 +124,10 @@ export class AppEffects {
this.store$.select(state => state.app.fiatCurrencyInfo)
),
switchMap(([action, cryptoCurrencyInfo, fiatCurrencyInfo]) =>
this.cacheService.get<Currency>(CacheKeys.currency).pipe(
this.cacheService.get<ExchangeRates>(CacheKeys.exchangeRates).pipe(
map(currency => {
const fiatCurrency = get(currency, fiatCurrencyInfo.currency)
const cryptoCurrency = get(currency, cryptoCurrencyInfo.currency)
const fiatCurrency = get(get(currency, Currency.XTZ), fiatCurrencyInfo.currency)
const cryptoCurrency = get(get(currency, Currency.XTZ), cryptoCurrencyInfo.currency)
const fiatPrice = new BigNumber(fiatCurrency)
const cryptoPrice = new BigNumber(cryptoCurrency)

Expand All @@ -153,20 +154,22 @@ export class AppEffects {
this.store$.select(state => state.app.fiatCurrencyInfo)
),
switchMap(([action, cryptoCurrencyInfo, fiatCurrencyInfo]) =>
this.cacheService.get<Currency>(CacheKeys.currency).pipe(
switchMap(currency =>
this.cacheService.get<ExchangeRates>(CacheKeys.exchangeRates).pipe(
switchMap(exchangeRates =>
this.cryptoPricesService.getCryptoPrices('xtz', [fiatCurrencyInfo.currency, cryptoCurrencyInfo.currency]).pipe(
map(prices => {
const fiatCurrency = get(prices, fiatCurrencyInfo.currency) || get(currency, fiatCurrencyInfo.currency)
const cryptoCurrency = get(prices, cryptoCurrencyInfo.currency) || get(currency, cryptoCurrencyInfo.currency)
const fiatCurrency =
get(prices, fiatCurrencyInfo.currency) || get(get(exchangeRates, Currency.XTZ), fiatCurrencyInfo.currency)
const cryptoCurrency =
get(prices, cryptoCurrencyInfo.currency) || get(get(exchangeRates, Currency.XTZ), cryptoCurrencyInfo.currency)
const fiatPrice = new BigNumber(fiatCurrency)
const cryptoPrice = new BigNumber(cryptoCurrency)

return actions.loadCryptoPriceSucceeded({ fiatPrice, cryptoPrice })
}),
catchError(error => {
const fiatCurrency = get(currency, fiatCurrencyInfo.currency)
const cryptoCurrency = get(currency, cryptoCurrencyInfo.currency)
const fiatCurrency = get(get(exchangeRates, Currency.XTZ), fiatCurrencyInfo.currency)
const cryptoCurrency = get(get(exchangeRates, Currency.XTZ), cryptoCurrencyInfo.currency)
const fiatPrice = new BigNumber(fiatCurrency)
const cryptoPrice = new BigNumber(cryptoCurrency)

Expand All @@ -179,6 +182,32 @@ export class AppEffects {
)
)

loadExchangeRate$ = createEffect(() =>
this.actions$.pipe(
ofType(actions.loadExchangeRate),
switchMap(action =>
this.cacheService.get<ExchangeRates>(CacheKeys.exchangeRates).pipe(
switchMap(exchangeRates =>
this.cryptoPricesService.getCryptoPrices(action.from, [action.to]).pipe(
map(prices => {
const price = get(prices, action.to) || get(get(exchangeRates, action.from), action.to)

return actions.loadExchangeRateSucceeded({ from: action.from, to: action.to, price })
}),
catchError(error => {
const price = get(get(exchangeRates, action.from), action.to)

return price
? of(actions.loadExchangeRateSucceeded({ from: action.from, to: action.to, price }))
: of(actions.loadExchangeRateFailed({ error }))
})
)
)
)
)
)
)

loadCryptoHistoricData$ = createEffect(() =>
this.actions$.pipe(
ofType(actions.loadCryptoHistoricData),
Expand Down
Loading

0 comments on commit 543470b

Please sign in to comment.