Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
238 commits
Select commit Hold shift + click to select a range
41b405d
converting from integer to decimal in the listing short model
rmisio May 13, 2019
f791c87
base unti conversions in the listing models
rmisio May 13, 2019
e74c1ea
adding in the coin divisibility when creating a new listing
rmisio May 13, 2019
7d897a3
setting the coinDivisibility in the Edit Listing modal
rmisio May 13, 2019
2b8047e
tweaking formatPrice to use coinDiv
rmisio May 13, 2019
909af58
fixd lint error
rmisio May 13, 2019
9216bd3
merging in top level nested model errors into the nested instances
rmisio May 15, 2019
9760d2f
removing the format pric function and instad doing error validations …
rmisio May 15, 2019
96cf85a
some lint cleanup
rmisio May 15, 2019
7139d88
adjusting the formatCurrency function to base decimal places bases of…
rmisio May 15, 2019
20ac92c
some coinDivisibility related tweaks in the listing model for crypto …
rmisio May 16, 2019
52e4ab9
converting the crypto quantity in the listing model based on the coin…
rmisio May 16, 2019
3ef2c1a
added some crypto quantity validations to the purchase item model
rmisio May 16, 2019
dbce4a7
Using the coin divisibility to convert the moderator fee in the profile
rmisio May 16, 2019
b3761b8
using the coinDivisibility to convert wallet balances
rmisio May 16, 2019
bf82b34
convrting the price in the transactions models using a coin div
rmisio May 16, 2019
41fad47
initial implementation of an init function for the wallet currencies …
rmisio Sep 3, 2019
82f7d12
initial changs to start.js to initialized the wallet currencies module
rmisio Sep 3, 2019
2c14b4a
a couple bug tweaks in start regarding wallet cur initialization
rmisio Sep 3, 2019
e37340f
working through a couple precision related bugs in the edit listing m…
rmisio Sep 3, 2019
764f9ef
putting in some temporary code to account for ob-go bug 1694
rmisio Sep 3, 2019
db926f3
removing temp code that accounted for a server bug which has since be…
rmisio Sep 4, 2019
d9dce7c
fixed bug in the initialization of the resyncBlockchain module
rmisio Sep 4, 2019
2042a5e
converting the wallet transaction value into an integer
rmisio Sep 4, 2019
ffb3728
updating the wallet balance model to consume the updated API schema
rmisio Sep 4, 2019
f41d069
updatd the estimate fee functionality to handle the new amount schema…
rmisio Sep 4, 2019
9b0ada2
WIP - updating the spend model to send an amount object
rmisio Sep 4, 2019
1ba7add
updated the spend model to handle the new amount format
rmisio Sep 5, 2019
017259e
fixing an issue where the edit listing modal errored when open in cry…
rmisio Sep 5, 2019
b5d80ba
fixing an issue where a hidden moderation error can prevent a real er…
rmisio Sep 6, 2019
ea859b6
cleaning up some debugging code
rmisio Sep 6, 2019
be272ab
updates based on server changes to the wallet spend call
rmisio Sep 6, 2019
5768895
adjustement to the wallet fees api
rmisio Sep 6, 2019
abd9df5
remove debugging code
rmisio Sep 6, 2019
255f40f
refactoreed multiple functions in the currency module
rmisio Sep 6, 2019
4e0a4bc
changes based on new format of the mod info in profile
rmisio Sep 9, 2019
cf9becb
reimplementing the walletUpdate socket handling code
rmisio Sep 9, 2019
b3e01a6
updating wallet currency related tests
rmisio Sep 9, 2019
86c5169
fixed the walletCurrencies tests
rmisio Sep 10, 2019
9012af2
wip - updating the tests for the currency module
rmisio Sep 10, 2019
5d7fa92
WIP - handling server amounts as strings rather than converting to nu…
rmisio Sep 10, 2019
002da96
Adding additional spend odel validations
rmisio Sep 11, 2019
7198dee
added more moderation fee amount validations to the profile model
rmisio Sep 11, 2019
24664ec
using common function to get min coin div price in the purchase-item …
rmisio Sep 11, 2019
81761fe
removing the number var type for many fields which will now be treate…
rmisio Sep 11, 2019
4d166f7
added additiona currency util module tests
rmisio Sep 11, 2019
c933f9e
added more currency module tests
rmisio Sep 12, 2019
c975b51
merging in master
rmisio Sep 12, 2019
09f5bf3
fix to borked package.json
rmisio Sep 12, 2019
7e86939
bumping the node version in the travis config
rmisio Sep 12, 2019
20ac8c7
updated package lock
rmisio Sep 12, 2019
df8ffd7
adjusting the npm test script
rmisio Sep 12, 2019
ef90e91
currency updates to properly handle unsupported numbers
rmisio Sep 13, 2019
3465c9e
more currency module tests
rmisio Sep 16, 2019
4193a20
WIP - coupon model and test updates
rmisio Sep 16, 2019
2dfa0de
WIP - abstracted way to validate and test that model fields do not ex…
rmisio Sep 18, 2019
b72bd47
cleaning up some fixed feemodel validations
rmisio Sep 19, 2019
e826167
updated toStandardNotation to handle big nums
rmisio Sep 20, 2019
03b5ead
tweaking some validations on the fixd fee model
rmisio Sep 20, 2019
19174a0
fixed error with currency code in the fixed fee model
rmisio Sep 23, 2019
b68874b
forgot to save a file
rmisio Sep 23, 2019
55f5dac
renamed function name in the currency utility module
rmisio Sep 23, 2019
d6e4b13
listing model validation tweaks for string based amounts
rmisio Sep 23, 2019
5676784
updates to the purchase flow to handle string based numbers
rmisio Sep 23, 2019
aa8fe54
tweaking number validation functions in the number util module
rmisio Sep 24, 2019
885aebb
WIP - updating the receipt to use bignums
rmisio Sep 24, 2019
e021bb0
fixed purchase bug if an empty quantity is entered in the UI
rmisio Sep 25, 2019
f7f474d
WIP - handling coupon values as big nummbers in the purchase flow
rmisio Sep 25, 2019
04088a9
fixed some bugs in the coupon math
rmisio Sep 26, 2019
5a5b2fd
more currency module tests
rmisio Sep 26, 2019
8688c5f
additional currency tests
rmisio Sep 27, 2019
73ece35
fixing someconveert currency tests
rmisio Sep 27, 2019
f85949b
slight refactor to integer to decimal conversion functions
rmisio Sep 27, 2019
a83917d
updated validateCurrencyAmount to optionally require a big number ins…
rmisio Sep 27, 2019
ad90311
throttling the balance model error logs
rmisio Sep 27, 2019
43fb881
wallet changes based on some currency mod changes
rmisio Sep 27, 2019
e9f5248
added tests for decimalToCurDef
rmisio Sep 27, 2019
6d62279
adding the bignumber var type to the mod fixed fee field in seettings
rmisio Oct 1, 2019
637a759
wrote tests for curDefToDecimal
rmisio Oct 1, 2019
f726d43
added a test for validateCurrencyAmount
rmisio Oct 1, 2019
b5d7de1
updates based on profile api changes
rmisio Oct 2, 2019
023ab83
changes based on server changes to the wallet currency definition
rmisio Oct 2, 2019
f0feeb5
Updating the item price handling when editing a listing based on serv…
rmisio Oct 3, 2019
59c0732
wip - tweaking shipping prices based on server schema changes
rmisio Oct 3, 2019
50daf33
WIP - bigAmount validation on shipping service prices in edit listing
rmisio Oct 3, 2019
5062657
converting listing item price in sync to cur def
rmisio Oct 3, 2019
0b6d081
tweaks to the listing model to handle price conversions for shipping …
rmisio Oct 4, 2019
98e2c4b
fixed issues in the listing model where the divisibility is set
rmisio Oct 7, 2019
9d95dba
handling the variant surcharge for listings based on precision API ch…
rmisio Oct 7, 2019
6f7b234
initial precision coupon validations
rmisio Oct 8, 2019
8ebfbe7
completed the coupon precision validations
rmisio Oct 8, 2019
506a517
changes to parse and sync of the listing model to handle big nums on …
rmisio Oct 8, 2019
5776caa
WIP - starting to work on crypto cur listing eth precision changes
rmisio Oct 8, 2019
e9380a5
WIP: crypto currency listing related ETH precision work
rmisio Oct 9, 2019
27c5a71
WIP - using bigQuantity for listing inventory tracking
rmisio Oct 9, 2019
b5d6156
moved the price modifier from the metadata to the item model
rmisio Oct 10, 2019
1395bc5
WIP - inventory related validations
rmisio Oct 10, 2019
4f0eb2e
various inventory relatd vlidations
rmisio Oct 11, 2019
ea2430a
listing card eth precision changes
rmisio Oct 14, 2019
b6baf6a
removing renderFormattedCurrency
rmisio Oct 14, 2019
aafe25b
removing an unused import
rmisio Oct 14, 2019
de429d7
listing detail eth-precision tweaks
rmisio Oct 14, 2019
07e1fe9
addition eth precision listing detail tweaks
rmisio Oct 14, 2019
5e8e51c
WIP - another round of Purchase precision tweaks
rmisio Oct 14, 2019
3c5fe0b
fixed issue where coupone line item was not displaying in the purchas…
rmisio Oct 15, 2019
35ef184
fixing an issue where the variant quantity is not cleared when specif…
rmisio Oct 15, 2019
217a0ff
WIP - purchase eth precision changes
rmisio Oct 15, 2019
b25121d
tweaks to currency formatting utility
rmisio Oct 16, 2019
6ab3be3
cleanup of some crypto inventory purchase validations
rmisio Oct 16, 2019
80e8c97
some tweaks based on the revived wallet socket
rmisio Oct 17, 2019
e44c71e
fixed bug where the pricing currency was not being shown in the UI of…
rmisio Oct 18, 2019
ef35684
fixed broken currency module test
rmisio Oct 18, 2019
eeec852
fixed listing model tests
rmisio Oct 18, 2019
e43c543
fixed payment socket handler to handle a string based funding total
rmisio Oct 21, 2019
2e2c9f7
fixing a styling issue with inline spinners on order transactions
rmisio Oct 21, 2019
e372673
fixing renamed cancel notifcation
rmisio Oct 22, 2019
094c8d1
adjusting to renamed order declined notification
rmisio Oct 22, 2019
be50025
eth precision work on the payments within an order
rmisio Oct 22, 2019
db40f8b
updating the refunded view in the ordeer detail to handle the bigValue
rmisio Oct 23, 2019
f1bbbed
showing the bigQuantity on the Order Details screen
rmisio Oct 23, 2019
bcc8c9d
fixing handling of determination of whether an order is funded in the…
rmisio Oct 23, 2019
6f34a3c
fixied issue obtaining the currency for a refund
rmisio Oct 23, 2019
e07b761
fixes issue where variants beyond the first one don't show in the var…
rmisio Oct 23, 2019
dff9a1c
fixed a validation issue for validating the amount for crypto currenc…
rmisio Oct 23, 2019
426eaec
clean up of some debugging code
rmisio Oct 24, 2019
e9df714
adding a 0 default for bigSurcharge in the Sku model
rmisio Oct 24, 2019
0b7dcc6
Merge branch 'eth-precision' into eth-orders
rmisio Oct 24, 2019
5955ea9
not showing payment address and related fields on the Pay For Order v…
rmisio Oct 25, 2019
00af178
converting transaction totals based on base units
rmisio Oct 25, 2019
d3be8c9
added test for the externally funded orders boolean in the wllet cur …
rmisio Oct 25, 2019
62280e1
fixed broken Item and Metadata model tests
rmisio Oct 25, 2019
dffb5cd
fixes 1820
rmisio Oct 28, 2019
1cb3cba
fixes 1824
rmisio Oct 28, 2019
e48ad66
In the Payment view, auto-selecting the first (and only) payment curr…
rmisio Oct 28, 2019
f76aa3a
added a todo note
rmisio Oct 29, 2019
647c023
wip - fixing bug in how models pass data between different settings tabs
rmisio Oct 29, 2019
8aea84e
fixed a bug in how data is passed around in settings between tabs
rmisio Oct 30, 2019
c26a4df
for a case in the transactions table, obtaining divisibility from the…
rmisio Oct 30, 2019
78d8ece
tweak to parse of Order to only convert the bigQuantity for base unit…
rmisio Oct 30, 2019
7de4551
moved some common case/order parse functionality to the base class
rmisio Oct 31, 2019
6b396e2
fixed an issue where the paymentType was not being correctly determin…
rmisio Oct 31, 2019
8afcbf2
removed some debugging code
rmisio Oct 31, 2019
c8a3fae
fixed broken service model tests and moved service price validations …
rmisio Nov 1, 2019
6e09cfe
wip - cleaning up fix fee model tests
rmisio Nov 1, 2019
f17e073
fixed remaining issues with broken fixed fee model tests
rmisio Nov 4, 2019
7591e77
fixed the broken purchase item model tests
rmisio Nov 4, 2019
ed2fdc8
hiding/disabling inventory related UI since it's not working properly…
rmisio Nov 4, 2019
d62e50a
removed todo comment
rmisio Nov 4, 2019
d4c183c
working through some documentation and TODOs on the currency module
rmisio Nov 5, 2019
ba3c518
refactored the listing detail template to not rely on getCurrencyVali…
rmisio Nov 5, 2019
d811cf9
removed getCurrencyValidity and remaining references
rmisio Nov 5, 2019
03f7d2b
cleaned up lint errors
rmisio Nov 5, 2019
55e9dba
some code cleanup
rmisio Nov 5, 2019
c755b34
documented some newer BaseModel functionality
rmisio Nov 6, 2019
ed38446
cleaned up logic that sets the coinDivisibility on the listing model
rmisio Nov 6, 2019
9bd3e83
various code cleanup
rmisio Nov 6, 2019
0a4dd30
a bunch of TODOs + added some tests
rmisio Nov 7, 2019
9d4cc51
documentation for the number module
rmisio Nov 7, 2019
66c69bb
added a test of the removeProp function of the objct module
rmisio Nov 7, 2019
eb18641
showing the coin type on thee edit listing modal even if it doesn't c…
rmisio Nov 8, 2019
298afae
fixed a bug in purchase with an error message shown if thee inveotry …
rmisio Nov 8, 2019
486ce9e
some code cleanup
rmisio Nov 8, 2019
b199c15
fixed lint ereror
rmisio Nov 8, 2019
69f4a13
more gracefully handling bad listing short data in the listing card
rmisio Nov 11, 2019
2393298
removed some debugging code
rmisio Nov 11, 2019
32f4a25
added error message on failed listing card to the translations file
rmisio Nov 11, 2019
622501f
fixing a bug where the unconfirmed balance was not showing in the wallet
rmisio Nov 11, 2019
167e84d
some code cleanup
rmisio Nov 12, 2019
264c8a0
Update js/languages/en_US.json
rmisio Nov 15, 2019
77f2498
Update js/models/BaseModel.js
rmisio Nov 15, 2019
aeb13d7
Update js/utils/currency.js
rmisio Nov 15, 2019
55c746c
Update js/utils/currency.js
rmisio Nov 15, 2019
118dd68
Update js/views/modals/editListing/EditListing.js
rmisio Nov 15, 2019
1668e0b
code review tweaks
rmisio Nov 15, 2019
493d54e
merging in eth-master
rmisio Nov 15, 2019
0c760ea
Merge branch 'eth-precision' of github.com:OpenBazaar/openbazaar-desk…
rmisio Nov 15, 2019
ee70c7b
removing unused variable from the coupons collection
rmisio Nov 15, 2019
2458a98
Update js/utils/currency.js
rmisio Nov 15, 2019
a8d03a2
fixed broken test
rmisio Nov 15, 2019
bb64096
additional work to fix broken test
rmisio Nov 15, 2019
21ccbe2
Merge pull request #1833 from OpenBazaar/eth-precision
jjeffryes Nov 15, 2019
96d2274
converting dispute reoslution amounts from strings to numbers
rmisio Nov 26, 2019
1081f67
removing unused import
rmisio Nov 26, 2019
c2e0dd9
When saving the profile in settings, not sending over the fixed fee o…
rmisio Nov 27, 2019
f37ae5d
removing unused imports
rmisio Nov 27, 2019
2e803cf
Update js/utils/currency.js
rmisio Nov 27, 2019
5f63c5f
rmoving 0 defaults for mod fees
rmisio Nov 27, 2019
6e9c142
fixed bug in the decimalPlaces number util function
rmisio Nov 27, 2019
06081ef
for dispute resolutions using the newly embedded divisibility
rmisio Dec 2, 2019
84ea7fb
sending over a percentage of zero for fixed mod fees
rmisio Dec 2, 2019
c3337e2
1841 - using the correct mod fee currency code in the settings modera…
rmisio Dec 3, 2019
8668c93
limiting the max decimals for the totals in the transation lists to b…
rmisio Dec 4, 2019
a859563
removing some debugging code
rmisio Dec 5, 2019
5a90cc5
fixed issue where the listing detail modal was bombing on a listing w…
rmisio Dec 6, 2019
62c6672
removing some debugging code
rmisio Dec 6, 2019
53546f1
limiting the max display decimals in the listing card to 6 for crypto…
rmisio Dec 6, 2019
4881c8d
bumping down the font on the listing card price line if the text won'…
rmisio Dec 6, 2019
daf665c
removing an unneeded import
rmisio Dec 9, 2019
ea09bab
removing some unused code
rmisio Dec 9, 2019
110e5ae
fixed bug where divisibility was not being properly vlidated in a lis…
rmisio Dec 9, 2019
35a3f6f
tet change in a test
rmisio Dec 9, 2019
6e87a5b
lint fixes
rmisio Dec 9, 2019
555109d
putting in a translations for some server purchase error codes
rmisio Dec 9, 2019
e5413d1
fixed some linting errors
rmisio Dec 9, 2019
b65129c
fixed issue where the coupon discount type was not showing correctly …
rmisio Dec 9, 2019
47e8974
removing error code that wont happen on the api it was being handled …
rmisio Dec 10, 2019
0e0cc1e
Merge pull request #1845 from OpenBazaar/tweaks
jjeffryes Dec 12, 2019
769979c
adjusting the max number of decimal places in the bigNumber config
rmisio Dec 12, 2019
94c5f01
removing unused import
rmisio Dec 12, 2019
2812b86
added messaging to the purchase receipt total
rmisio Dec 13, 2019
9850cfe
fixed lint error
rmisio Dec 13, 2019
b2ace61
updated the payment notification handler to handle the updated payloa…
rmisio Dec 18, 2019
e61ea7f
lint fixes
rmisio Dec 18, 2019
10f42a9
Merge branch 'master' into eth-master
Dec 18, 2019
7d9618c
Merge pull request #1850 from OpenBazaar/eth-master-update
rmisio Dec 18, 2019
350a85e
tweaks in the wallet stats area to better handle lengthy amounts
rmisio Dec 18, 2019
92cef69
updating the mod component to pass in an asyncID rather than relying …
rmisio Dec 19, 2019
b82afd6
removing some debugging code
rmisio Dec 19, 2019
96eabae
fixed issue where the moderator fixed fee curreency was not properly …
rmisio Dec 19, 2019
8cde596
Merge pull request #1838 from OpenBazaar/disput-payout-precision
jjeffryes Dec 19, 2019
03b13e0
not showing the receipt total tip after the "pay" phase
rmisio Dec 19, 2019
eaf2896
fixed wrong variable reference in the spendConfirmBox template
rmisio Dec 19, 2019
e013240
mergd in eth-master
rmisio Dec 19, 2019
b76c078
fixed lint errors
rmisio Dec 19, 2019
88b0df9
capping the width of the fee column in the mod card so long decimals …
rmisio Dec 23, 2019
063342f
setting escrow timeout hours to 1 on testnet
rmisio Dec 23, 2019
446289b
Merge pull request #1848 from OpenBazaar/more-tweaks
jjeffryes Jan 3, 2020
6fd61d1
better naming
Jan 14, 2020
65ea496
update package lock
Jan 15, 2020
9b2249c
Merge branch 'master' into updateEthFromMaster
Jan 15, 2020
b9f0c1e
switch back to using a set
Jan 15, 2020
b46514a
Merge pull request #1863 from OpenBazaar/updateEthFromMaster
rmisio Jan 30, 2020
820d422
updates to the case and transaction model to convert the cur def as o…
rmisio Feb 5, 2020
ff13c5f
locking the version of the bignumber js npm package
rmisio Feb 5, 2020
ec574f7
Merge pull request #1865 from OpenBazaar/transactions-api-fix
jjeffryes Feb 6, 2020
5fc57ce
Account for v4/v5 search API pricing schemas
hoffmabc Mar 9, 2020
6ac697e
Linting fixes
hoffmabc Mar 9, 2020
f46c9dc
Merge pull request #1871 from OpenBazaar/brian.fix-search-v5
hoffmabc Mar 9, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ cache:
- $HOME/Library/Caches/Homebrew

node_js:
- '8'
- '11'
addons:
apt:
packages:
Expand Down
3 changes: 3 additions & 0 deletions js/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Errors
export const ERROR_INSUFFICIENT_FUNDS = 'ERROR_INSUFFICIENT_FUNDS';
export const ERROR_DUST_AMOUNT = 'ERROR_DUST_AMOUNT';
4 changes: 1 addition & 3 deletions js/data/cryptoListingCurrencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ let currenciesNeedRefresh = true;
let exchangeRateChangeBound = false;
let currenciesSortedByNameDeferred = null;

export const defaultQuantityBaseUnit = 100000000;

export function getCurrencies() {
if (!exchangeRateChangeBound) {
getCurrencyEvents().on('exchange-rate-change',
Expand Down Expand Up @@ -118,7 +116,7 @@ export function getCurrencies() {
exchangeRateCurs = _exchangeRateCurs.sort();
_exchangeRateCurs
.forEach(cur => {
// If it's not a fiat currency code (base on our hard-code list),
// If it's not a fiat currency code (base on our hard-coded list),
// or on our exclude list, we'll assume it's a crypto currency.
if (!fiatCurrencyCodes.includes(cur) && !excludes.includes(cur)) {
curs.add(cur);
Expand Down
4 changes: 0 additions & 4 deletions js/data/currencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,3 @@ export function getCurrenciesSortedByCode(options = {}) {
sortBy: 'code',
});
}

export function isFiatCur(code) {
return !!getCurrencyByCode(code, { includeWalletCurs: false });
}
167 changes: 117 additions & 50 deletions js/data/walletCurrencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ import bech32 from 'bech32';
// If a currency does not support fee bumping or you want to disable it, do not provide a
// feeBumpTransactionSize setting.

const currencies = [
let _currencies = [
{
code: 'BTC',
testnetCode: 'TBTC',
symbol: '₿',
baseUnit: 100000000,
averageModeratedTransactionSize: 184,
// Not allowing fee bump on BTC right now given the fees.
// feeBumpTransactionSize: 154,
qrCodeText: address => `bitcoin:${address}`,
Expand Down Expand Up @@ -47,12 +45,11 @@ const currencies = [
},
supportsEscrowTimeout: true,
blockTime: 1000 * 60 * 10,
externallyFundableOrders: true,
},
{
code: 'BCH',
testnetCode: 'TBCH',
baseUnit: 100000000,
averageModeratedTransactionSize: 184,
feeBumpTransactionSize: 154,
qrCodeText: address => {
let prefixedAddress = address;
Expand All @@ -77,12 +74,31 @@ const currencies = [
),
supportsEscrowTimeout: true,
blockTime: 1000 * 60 * 10,
externallyFundableOrders: true,
},
{
code: 'ETH',
testnetCode: 'TETH',
qrCodeText: address => `ethereum:${address}`,
icon: 'imgs/cryptoIcons/ETH.png',
url: 'https://ethereum.org/',
getBlockChainAddressUrl: (address, isTestnet) => (
isTestnet ?
`https://rinkeby.etherscan.io/address/${address}` :
`https://blockchair.com/ethereum/address/${address}`
),
getBlockChainTxUrl: (txid, isTestnet) => (
isTestnet ?
`https://rinkeby.etherscan.io/tx/${txid}` :
`https://blockchair.com/ethereum/transaction/${txid}`
),
supportsEscrowTimeout: true,
blockTime: 1000 * 10,
externallyFundableOrders: false,
},
{
code: 'LTC',
testnetCode: 'TLTC',
baseUnit: 100000000,
averageModeratedTransactionSize: 184,
feeBumpTransactionSize: 154,
qrCodeText: address => `litecoin:${address}`,
icon: 'imgs/cryptoIcons/LTC.png',
Expand All @@ -99,12 +115,11 @@ const currencies = [
),
supportsEscrowTimeout: true,
blockTime: 1000 * 60 * 2.5,
externallyFundableOrders: true,
},
{
code: 'ZEC',
testnetCode: 'TZEC',
baseUnit: 100000000,
averageModeratedTransactionSize: 184,
feeBumpTransactionSize: 154,
qrCodeText: address => `zcash:${address}`,
icon: 'imgs/cryptoIcons/ZEC.png',
Expand All @@ -121,22 +136,89 @@ const currencies = [
),
supportsEscrowTimeout: false,
blockTime: 1000 * 60 * 2.5,
externallyFundableOrders: true,
},
];

export default currencies;
let _initialized = false;

function enforceInitialized() {
if (!_initialized) {
throw new Error('This module must be initialized before proceeeding.');
}
}

let _indexedCurrencies;

function getIndexedCurrencies() {
if (_indexedCurrencies) return _indexedCurrencies;

_indexedCurrencies = _currencies
.reduce((indexedObj, currency) => {
indexedObj[currency.code] = indexedObj[currency.testnetCode] = { ...currency };
return indexedObj;
}, {});

return _indexedCurrencies;
}

export function init(walletCurs, walletCurDef) {
if (!Array.isArray(walletCurs)) {
// the wallet curs as provided in the 'wallets' property of 'ob/config'
throw new Error('Please provide a list of wallet currencies.');
}

if (typeof walletCurDef !== 'object') {
// the wallet cur definition as provided in 'ob/wallet/currencies'
throw new Error('Please provide the wallet currencies definition as an object.');
}

// The final currencies list stored in this module will be a union of
// the walletCurs, the walletCur def and the initial currencies declared
// here in the _currencies variable. The currency must be declared in all
// three for it to remain.
const curs = [];

const indexedCurs = getIndexedCurrencies();
// We don't want the indexed curs cached since the definition is about to change
_indexedCurrencies = null;

Object
.keys(indexedCurs)
.forEach(curCode => {
const curDef = walletCurDef[curCode];

if (
curDef &&
walletCurs.includes(curDef.code)
) {
const clientCur = indexedCurs[curDef.code];
const curData = {
...clientCur,
coinDivisibility: curDef.divisibility,
};

curs.push(curData);
}
});

_currencies = curs;
_initialized = true;
}

function getTranslatedCurrencies(
lang = app && app.localSettings &&
app.localSettings.standardizedTranslatedLang() || 'en-US',
sort = true
) {
enforceInitialized();

if (!lang) {
throw new Error('Please provide the language the translated currencies' +
' should be returned in.');
}

let translated = currencies.map((currency) => ({
let translated = _currencies.map((currency) => ({
...currency,
name: app.polyglot.t(`cryptoCurrencies.${currency.code}`),
}));
Expand All @@ -153,21 +235,9 @@ const memoizedGetTranslatedCurrencies =

export { memoizedGetTranslatedCurrencies as getTranslatedCurrencies };

let _indexedCurrencies;

function getIndexedCurrencies() {
if (_indexedCurrencies) return _indexedCurrencies;

_indexedCurrencies = currencies
.reduce((indexedObj, currency) => {
indexedObj[currency.code] = indexedObj[currency.testnetCode] = { ...currency };
return indexedObj;
}, {});

return _indexedCurrencies;
}

export function getCurrencyByCode(code) {
enforceInitialized();

if (typeof code !== 'string') {
throw new Error('Please provide a currency code as a string.');
}
Expand All @@ -178,11 +248,13 @@ export function getCurrencyByCode(code) {
let currenciesSortedByCode;

export function getCurrenciesSortedByCode() {
enforceInitialized();

if (currenciesSortedByCode) {
return currenciesSortedByCode;
}

currenciesSortedByCode = currencies.sort((a, b) => {
currenciesSortedByCode = _currencies.sort((a, b) => {
if (a.code < b.code) return -1;
if (a.code > b.code) return 1;
return 0;
Expand All @@ -199,6 +271,8 @@ export function getCurrenciesSortedByCode() {
* the only ones that should ever come as testnet codes.
*/
export function ensureMainnetCode(cur) {
enforceInitialized();

if (typeof cur !== 'string' || !cur.length) {
throw new Error('Please provide a non-empty string.');
}
Expand All @@ -207,41 +281,29 @@ export function ensureMainnetCode(cur) {
return curObj ? curObj.code : cur;
}

export function getWalletCurs() {
return _currencies;
}

/**
* Returns a list of the crypto currencies supported by the wallet.
* Returns a list of the wallet currency codes supported by the wallet.
*
* @param {object} [options={}] - Function options
* @param {boolean} [options.clientSupported=true] - If true, it will only include
* currencies that are supported by both the client and the server. For the client to
* support the currency, it must have an entry in the walletCurrencies data file. Without
* that information, the client can't really support the currency since fundamental information
* (e.g baseUnits) aren't available. In most context, we will not want to show a currency if it
* is not client supported.
* @param {Array} [options.serverCurs=app.serverConfig.wallets] - The list of currencies that
* are supported by the server's wallet. By default, this is obtained from the server config
* API. In almost all cases, the default should be used. It's mainly exposed as an option
* for unit testing.
* @param {boolean} [options.testnet=apps.serverConfig.testnet] - Indicates if the app
* is running on testnet. If so, testnet codes will be returned.
* @return {Array} An Array containing the currency codes that are supported by the wallet.
*/
export function supportedWalletCurs(options = {}) {
const opts = {
clientSupported: true,
serverCurs: app && app.serverConfig && app.serverConfig.wallets || [],
testnet: app && app.serverConfig && app.serverConfig.testnet || false,
...options,
};

if (!Array.isArray(opts.serverCurs)) {
throw new Error('options.serverCurs must be provided as an Array.');
}
enforceInitialized();

return opts.serverCurs
.filter(cur =>
(
opts.clientSupported ?
!!getIndexedCurrencies()[cur] :
true
)
);
return getWalletCurs()
.filter(cur => (opts.testnet ? cur.testnetCode : true))
.map(cur => (opts.testnet ? cur.testnetCode : cur.code));
}

/**
Expand All @@ -252,6 +314,8 @@ export function supportedWalletCurs(options = {}) {
* @return {boolean} A boolean indicating whether the given code is supported by the wallet.
*/
export function isSupportedWalletCur(cur, options = {}) {
enforceInitialized();

if (typeof cur !== 'string') {
throw new Error('Please provide a cur as a string.');
}
Expand All @@ -269,6 +333,8 @@ export function isSupportedWalletCur(cur, options = {}) {
* wallt curs.
*/
export function onlySupportedWalletCurs(curs = [], options = {}) {
enforceInitialized();

if (!Array.isArray(curs)) {
throw new Error('Curs must be provided as an Array.');
}
Expand All @@ -288,5 +354,6 @@ export function onlySupportedWalletCurs(curs = [], options = {}) {
* as wallet currencies.
*/
export function anySupportedByWallet(...args) {
enforceInitialized();
return !!(onlySupportedWalletCurs(...args).length);
}
Loading