aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjloup <jeanloup.jamet@gmail.com>2018-03-26 10:54:48 +0200
committerjloup <jeanloup.jamet@gmail.com>2018-03-26 10:55:40 +0200
commit908ee2dd22c85d5d850f62b1a9d0066b43b80a69 (patch)
tree8d8223b5bce680b49cd3b2a78d9b3b7d94803bc2
parent6200f9a3c47770119abbb8b563ba32a0ea363949 (diff)
downloadFront-908ee2dd22c85d5d850f62b1a9d0066b43b80a69.tar.gz
Front-908ee2dd22c85d5d850f62b1a9d0066b43b80a69.tar.zst
Front-908ee2dd22c85d5d850f62b1a9d0066b43b80a69.zip
Handle poloniex ip restriction.
-rw-r--r--api/const.go3
-rw-r--r--api/const_string.go4
-rw-r--r--cmd/web/js/poloniex.jsx5
-rw-r--r--markets/poloniex.go8
4 files changed, 17 insertions, 3 deletions
diff --git a/api/const.go b/api/const.go
index 1b22355..d3e5f42 100644
--- a/api/const.go
+++ b/api/const.go
@@ -19,6 +19,7 @@ const (
19 InvalidCredentials 19 InvalidCredentials
20 InvalidEmail 20 InvalidEmail
21 InvalidMarketCredentials 21 InvalidMarketCredentials
22 IPRestrictedApiKey
22 InvalidOtp 23 InvalidOtp
23 InvalidPassword 24 InvalidPassword
24 NeedOtpValidation 25 NeedOtpValidation
@@ -35,7 +36,7 @@ func StatusToHttpCode(status Status, code ErrorCode) int {
35 } 36 }
36 37
37 switch code { 38 switch code {
38 case BadRequest, InvalidPassword, InvalidEmail, InvalidMarketCredentials: 39 case BadRequest, InvalidPassword, InvalidEmail, InvalidMarketCredentials, IPRestrictedApiKey:
39 return http.StatusBadRequest 40 return http.StatusBadRequest
40 41
41 case InvalidCredentials, InvalidOtp: 42 case InvalidCredentials, InvalidOtp:
diff --git a/api/const_string.go b/api/const_string.go
index e4b9e50..58ed230 100644
--- a/api/const_string.go
+++ b/api/const_string.go
@@ -15,9 +15,9 @@ func (i Status) String() string {
15 return _Status_name[_Status_index[i]:_Status_index[i+1]] 15 return _Status_name[_Status_index[i]:_Status_index[i+1]]
16} 16}
17 17
18const _ErrorCode_name = "BadRequestEmailExistsExternalServiceTimeoutInternalErrorInvalidCredentialsInvalidEmailInvalidMarketCredentialsInvalidOtpInvalidPasswordNeedOtpValidationNotAuthorizedNotFoundOtpAlreadySetupOtpNotSetupUserNotConfirmed" 18const _ErrorCode_name = "BadRequestEmailExistsExternalServiceTimeoutInternalErrorInvalidCredentialsInvalidEmailInvalidMarketCredentialsIPRestrictedApiKeyInvalidOtpInvalidPasswordNeedOtpValidationNotAuthorizedNotFoundOtpAlreadySetupOtpNotSetupUserNotConfirmed"
19 19
20var _ErrorCode_index = [...]uint8{0, 10, 21, 43, 56, 74, 86, 110, 120, 135, 152, 165, 173, 188, 199, 215} 20var _ErrorCode_index = [...]uint8{0, 10, 21, 43, 56, 74, 86, 110, 128, 138, 153, 170, 183, 191, 206, 217, 233}
21 21
22func (i ErrorCode) String() string { 22func (i ErrorCode) String() string {
23 i -= 3 23 i -= 3
diff --git a/cmd/web/js/poloniex.jsx b/cmd/web/js/poloniex.jsx
index 482dbb6..813a506 100644
--- a/cmd/web/js/poloniex.jsx
+++ b/cmd/web/js/poloniex.jsx
@@ -32,6 +32,8 @@ class PoloniexController extends React.Component {
32 console.error(err, data); 32 console.error(err, data);
33 if (err.code === 'invalid_market_credentials') { 33 if (err.code === 'invalid_market_credentials') {
34 this.setState({'flag': 'invalidCredentials', 'valueCurrency': null, 'balanceValue': null, 'balance': null}); 34 this.setState({'flag': 'invalidCredentials', 'valueCurrency': null, 'balanceValue': null, 'balance': null});
35 } else if (err.code === 'ip_restricted_api_key') {
36 this.setState({'flag': 'ipRestricted', 'valueCurrency': null, 'balanceValue': null, 'balance': null});
35 } 37 }
36 return; 38 return;
37 } 39 }
@@ -68,6 +70,9 @@ class PoloniexController extends React.Component {
68 case 'invalidCredentials': 70 case 'invalidCredentials':
69 displayText = 'Invalid poloniex credentials'; 71 displayText = 'Invalid poloniex credentials';
70 break; 72 break;
73 case 'ipRestricted':
74 displayText = 'Your API key is IP restricted. Please whitelist us.';
75 break;
71 case 'emptyCredentials': 76 case 'emptyCredentials':
72 displayText = 'Please provide poloniex credentials'; 77 displayText = 'Please provide poloniex credentials';
73 break; 78 break;
diff --git a/markets/poloniex.go b/markets/poloniex.go
index 5e1ec64..34ebb7e 100644
--- a/markets/poloniex.go
+++ b/markets/poloniex.go
@@ -13,6 +13,7 @@ var (
13 ErrorFlagCounter utils.Counter = 0 13 ErrorFlagCounter utils.Counter = 0
14 CurrencyPairNotInTicker = utils.InitFlag(&ErrorFlagCounter, "CurrencyPairNotInTicker") 14 CurrencyPairNotInTicker = utils.InitFlag(&ErrorFlagCounter, "CurrencyPairNotInTicker")
15 InvalidCredentials = utils.InitFlag(&ErrorFlagCounter, "InvalidCredentials") 15 InvalidCredentials = utils.InitFlag(&ErrorFlagCounter, "InvalidCredentials")
16 IPRestricted = utils.InitFlag(&ErrorFlagCounter, "IPRestricted")
16) 17)
17 18
18func poloniexInvalidCredentialsError(err error) bool { 19func poloniexInvalidCredentialsError(err error) bool {
@@ -22,6 +23,13 @@ func poloniexInvalidCredentialsError(err error) bool {
22 return strings.Contains(err.Error(), "Invalid API key/secret pair") 23 return strings.Contains(err.Error(), "Invalid API key/secret pair")
23} 24}
24 25
26func poloniexRestrictedIPError(err error) bool {
27 if err == nil {
28 return false
29 }
30 return strings.Contains(err.Error(), "Permission denied")
31}
32
25type CurrencyPair struct { 33type CurrencyPair struct {
26 Name string 34 Name string
27 Rate decimal.Decimal 35 Rate decimal.Decimal