Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
change Token#parentCurrency to be a Currency type
Browse files Browse the repository at this point in the history
  • Loading branch information
gre committed Jun 6, 2019
1 parent 9f2fa38 commit ba867b1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/__tests__/helpers/currencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ test("tokens are correct", () => {
expect(typeof token.name).toBe("string");
expect(typeof token.ledgerSignature).toBe("string");
expect(typeof token.tokenType).toBe("string");
expect(typeof token.parentCurrency).toBe("string");
expect(hasCryptoCurrencyId(token.parentCurrency)).toBe(true);
expect(typeof token.parentCurrency).toBe("object");
expect(hasCryptoCurrencyId(token.parentCurrency.id)).toBe(true);
expect(typeof token.ticker).toBe("string");
expect(token.units.length).toBeGreaterThan(0);
const unit = token.units[0];
Expand Down
12 changes: 10 additions & 2 deletions src/currencies/color.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
// @flow
import type { Currency } from "../types";

export const getCurrencyColor = (currency: Currency) =>
currency.type === "CryptoCurrency" ? currency.color : "#777";
export const getCurrencyColor = (currency: Currency) => {
switch (currency.type) {
case "CryptoCurrency":
return currency.color;
case "TokenCurrency":
return currency.parentCurrency.color;
default:
return "#999";
}
};
11 changes: 6 additions & 5 deletions src/data/tokens.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// @flow
import type { TokenCurrency, CryptoCurrency } from "../types";
import { getCryptoCurrencyById } from "../currencies";

const convertERC20 = ([
parentCurrency,
parentCurrencyId,
token,
ticker,
magnitude,
Expand All @@ -14,7 +15,7 @@ const convertERC20 = ([
id: "ethereum/erc20/" + token,
ledgerSignature,
contractAddress,
parentCurrency,
parentCurrency: getCryptoCurrencyById(parentCurrencyId),
tokenType: "erc20",
name,
ticker,
Expand Down Expand Up @@ -50,10 +51,10 @@ export function add(type: string, list: any[]) {
tokensByTicker[token.ticker] = token;
tokensByAddress[token.contractAddress.toLowerCase()] = token;
const { parentCurrency } = token;
if (!(parentCurrency in tokensByCryptoCurrency)) {
tokensByCryptoCurrency[parentCurrency] = [];
if (!(parentCurrency.id in tokensByCryptoCurrency)) {
tokensByCryptoCurrency[parentCurrency.id] = [];
}
tokensByCryptoCurrency[parentCurrency].push(token);
tokensByCryptoCurrency[parentCurrency.id].push(token);
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/types/currencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type TokenCurrency = CurrencyCommon & {
ledgerSignature: string,
contractAddress: string,
// the currency it belongs to. e.g. 'ethereum'
parentCurrency: string,
parentCurrency: CryptoCurrency,
// the type of token in the blockchain it belongs. e.g. 'erc20'
tokenType: string
};
Expand Down

0 comments on commit ba867b1

Please sign in to comment.