Skip to content
Permalink
Browse files

fix(ajax): stop using ember-host-manager

  • Loading branch information...
devinus committed Nov 30, 2018
1 parent c1a12a3 commit 9f66e1e6a37dc8f54f71cea3c2731a62bf3e2363
@@ -34,15 +34,15 @@ export default class ApplicationAjaxService extends AjaxService.extend({
}
}), backoffPolicy).enqueue().maxConcurrency(20),
}) {
@service session;
@service config;

@service hostManager;
@service session;

@service electron;

@overridableReads('hostManager.host.rpcHost') host;
@overridableReads('config.rpc.host') host;

@overridableReads('hostManager.host.rpcNamespace') namespace;
@overridableReads('config.rpc.namespace') namespace;

contentType = 'application/json'

@@ -53,15 +53,15 @@ export default class BalanceOverviewComponent extends Component.extend(
}

@keepLatestTask
* exchangeRateTask(currency = Symbol.keyFor(DEFAULT_CURRENCY)) {
return yield getExchangeRate(Symbol.for(currency));
* exchangeRateTask(currency = DEFAULT_CURRENCY) {
return yield getExchangeRate(currency);
}

@observes('currency')
async updateExchangeRate() {
return this.runTask(async () => {
const currency = this.get('currency');
if (currency === Symbol.keyFor(DEFAULT_CURRENCY)) {
if (currency === DEFAULT_CURRENCY) {
this.set('exchangeRate', DEFAULT_EXCHANGE_RATE);
return DEFAULT_EXCHANGE_RATE;
}
@@ -8,7 +8,7 @@ import {
export default class WalletBalanceComponent extends Component {
amount = 0;

currency = Symbol.keyFor(DEFAULT_CURRENCY);
currency = DEFAULT_CURRENCY;

exchangeRate = DEFAULT_EXCHANGE_RATE;
}
@@ -1,11 +1,10 @@
import console from 'console';
import isElectron from '../utils/is-electron';

const logger = console;

function electronLog(level, ...args) {
const fn = typeof logger[level] === 'function'
? logger[level].bind(logger)
: logger.log.bind(logger);
const fn = typeof console[level] === 'function'
? ::console[level]
: ::console.log;
return fn('<ELECTRON>', ...args);
}

@@ -17,8 +17,8 @@ export default function formatAmount(intl, value, options = {}) {
const {
locale = get(intl, 'locale'),
useGrouping = true,
unit = Symbol.keyFor(DEFAULT_UNIT),
currency = Symbol.keyFor(DEFAULT_CURRENCY),
unit = DEFAULT_UNIT,
currency = DEFAULT_CURRENCY,
exchangeRate = DEFAULT_EXCHANGE_RATE,
} = options;

@@ -27,7 +27,7 @@ export default function formatAmount(intl, value, options = {}) {
return '0';
}

const divisor = getConversion(Symbol.for(unit));
const divisor = getConversion(unit);
const quotient = BigNumber(value).dividedBy(divisor);
const product = BigNumber(quotient).times(exchangeRate);
const decimalPlaces = product.decimalPlaces();
@@ -4,12 +4,12 @@ import BigNumber from 'bignumber.js';

const base10 = BigNumber(10);

const Gxrb = Symbol.for('Gxrb');
const Mxrb = Symbol.for('Mxrb');
const kxrb = Symbol.for('kxrb');
const xrb = Symbol.for('xrb');
const mxrb = Symbol.for('mxrb');
const uxrb = Symbol.for('uxrb');
export const Gxrb = 'Gxrb';
export const Mxrb = 'Mxrb';
export const kxrb = 'kxrb';
export const xrb = 'xrb';
export const mxrb = 'mxrb';
export const uxrb = 'uxrb';

export const UNITS = new Set([
Gxrb,
@@ -3,10 +3,10 @@ import { defineError } from 'ember-exex/error';
import coinmarketcap from 'coinmarketcap';
import BigNumber from 'bignumber.js';

export const NANO = Symbol.for('NANO');
export const BTC = Symbol.for('BTC');
export const USD = Symbol.for('USD');
export const EUR = Symbol.for('EUR');
export const NANO = 'NANO';
export const BTC = 'BTC';
export const USD = 'USD';
export const EUR = 'EUR';

export const CURRENCIES = new Set([
NANO,
@@ -44,8 +44,8 @@ export default async function getExchangeRate(currency = DEFAULT_CURRENCY) {
throw new InvalidCurrencyError({ params: { currency } });
}

const asset = Symbol.keyFor(DEFAULT_CURRENCY);
const convert = Symbol.keyFor(currency).toLowerCase();
const asset = DEFAULT_CURRENCY;
const convert = String(currency).toLowerCase();
let ticker;
try {
ticker = await coinmarketcap.tickerByAsset(asset, { convert });
@@ -4,6 +4,7 @@ window.deprecationWorkflow.config = {
{ handler: 'silence', matchId: 'deprecate-router-events' },
{ handler: 'silence', matchId: 'ember-component.send-action' },
{ handler: 'silence', matchId: 'ember-polyfills.deprecate-merge' },
{ handler: 'silence', matchId: 'ember-runtime.deprecate-copy-copyable' },
{ handler: 'silence', matchId: 'events.remove-all-listeners' },
{ handler: 'silence', matchId: 'remove-handler-infos' },
],
@@ -7,6 +7,7 @@ const {
} = require('../package');

module.exports = (environment) => {
const isElectron = !!process.env.EMBER_CLI_ELECTRON;
const ENV = {
title,
version,
@@ -15,6 +16,7 @@ module.exports = (environment) => {
environment,
rootURL: '',
locationType: 'hash',
exportApplicationGlobal: 'App',
EmberENV: {
FEATURES: {
// Here you can enable experimental features on an ember canary build
@@ -85,6 +87,11 @@ module.exports = (environment) => {
signature: 'https://snapshots.nano.org/data.tar.xz.sha256',
},
},

rpc: {
host: 'http://localhost:55000',
namespace: null,
},
};

if (environment === 'development') {
@@ -109,16 +116,22 @@ module.exports = (environment) => {
ENV.APP.autoboot = false;

ENV.contentSecurityPolicy['script-src'].push("'sha256-37u63EBe1EibDZ3vZNr6mxLepqlY1CQw+4N89HrzP9s='");

ENV.rpc.host = '';
ENV.rpc.namespace = 'rpc';
}

if (environment === 'production') {
// here you can enable a production-specific feature
}

if (process.env.EMBER_CLI_ELECTRON) {
if (isElectron) {
ENV.contentSecurityPolicy['script-src'].push("'sha256-bOpoN0CEbM1axa1+hv51a4JK31vrAOV7Cbze5rS9GJI='");
ENV.contentSecurityPolicy['script-src'].push("'sha256-k8ysrhm1lqKyZpON3/YocPOUXAF4sGsu7JIycGDxCWw='");
ENV.contentSecurityPolicy['connect-src'].push('https://localhost:17076');

ENV.rpc.host = 'https://localhost:17076';
ENV.rpc.namespace = 'rpc';
}

return ENV;
@@ -9,15 +9,15 @@ if (isElectron) {
const electronVersion = semver.clean(devDependencies['electron-prebuilt-compile']);
browsers.push(`Electron >= ${electronVersion}`);
} else {
browsers.push('last 2 Chrome versions');
browsers.push('last 1 Chrome versions');

const isCI = !!process.env.CI;
const isProduction = process.env.EMBER_ENV === 'production';
if (isCI || isProduction) {
browsers.push(
'last 2 Safari versions',
'last 2 Firefox versions',
'last 2 Edge versions',
'last 1 Safari versions',
'last 1 Firefox versions',
'last 1 Edge versions',
);
}
}
@@ -35,6 +35,8 @@ export default function () {
// Electron proxy
this.passthrough('https://localhost:17076/**');

this.passthrough('https://api.coinmarketcap.com/**');

this.namespace = 'rpc';

this.post('/', (schema, request) => {
@@ -6,9 +6,9 @@ describe('Unit | Service | ajax', () => {
setupTest('service:ajax', {
// Specify the other units that are required for this test.
needs: [
'service:config',
'service:intl',
'service:session',
'service:hostManager',
'service:electron',
],
});

0 comments on commit 9f66e1e

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