Ejemplo n.º 1
0
        public override async Task <QuestionnaireResponse> GetQuestionnaire(Empty request, ServerCallContext context)
        {
            var result = new QuestionnaireResponse();

            var token    = context.GetBearerToken();
            var response = await _walletApiV1Client.TiersGetQuestionnaireAsync(token);

            if (response.Result != null)
            {
                result.Body = new QuestionnaireResponse.Types.Body();

                foreach (var question in response.Result.Questionnaire)
                {
                    var q = _mapper.Map <QuestionnaireResponse.Types.Question>(question);
                    q.Answers.AddRange(_mapper.Map <List <QuestionnaireResponse.Types.Answer> >(question.Answers));
                    result.Body.Questionnaire.Add(q);
                }
            }

            if (response.Error != null)
            {
                result.Error = response.Error.ToApiError();
            }

            return(result);
        }
Ejemplo n.º 2
0
        public override async Task <WalletsResponse> GetWallets(Empty request, ServerCallContext context)
        {
            var token    = context.GetBearerToken();
            var response = await _walletApiV1Client.WalletsGetAsync(token);

            var result = new WalletsResponse();

            if (response.Result != null)
            {
                result.Body = new WalletsResponse.Types.Body
                {
                    Lykke = new WalletsResponse.Types.LykkeWalletsPayload {
                        Equity = response.Result.Lykke.Equity.ToString(CultureInfo.InvariantCulture)
                    },
                    MultiSig         = response.Result.MultiSig,
                    ColoredMultiSig  = response.Result.ColoredMultiSig,
                    SolarCoinAddress = response.Result.SolarCoinAddress
                };

                result.Body.Lykke.Assets.AddRange(_mapper.Map <List <WalletsResponse.Types.WalletAsset> >(response.Result.Lykke.Assets));
            }

            if (response.Error != null)
            {
                result.Error = response.Error.ToApiError();
            }

            return(result);
        }
Ejemplo n.º 3
0
        public override async Task <PrivateWalletsResponse> GetPrivateWallets(Empty request, ServerCallContext context)
        {
            var result = new PrivateWalletsResponse();

            var token    = context.GetBearerToken();
            var response = await _walletApiV1Client.PrivateWalletGetAsync(token);

            if (response.Result != null)
            {
                result.Body = new PrivateWalletsResponse.Types.Body();

                foreach (var wallet in response.Result.Wallets)
                {
                    var res = _mapper.Map <PrivateWallet>(wallet);
                    res.Balances.AddRange(_mapper.Map <List <BalanceRecord> >(wallet.Balances));
                    result.Body.Wallets.Add(res);
                }
            }

            if (response.Error != null)
            {
                result.Error = response.Error.ToApiError();
            }

            return(result);
        }
Ejemplo n.º 4
0
        public override async Task <PlaceOrderResponse> PlaceMarketOrder(MarketOrderRequest request, ServerCallContext context)
        {
            var token    = context.GetBearerToken();
            var response = await _walletApiV1Client.HotWalletPlaceMarketOrderAsync(
                new HotWalletOperation
            {
                AssetPair = request.AssetPairId,
                AssetId   = request.AssetId,
                Volume    = request.Volume
            },
                token,
                _walletApiConfig.Secret);

            var result = new PlaceOrderResponse();

            if (response.Result != null)
            {
                result.Body = _mapper.Map <OrderModel>(response.Result.Order);
            }

            if (response.Error != null)
            {
                result.Error = response.Error.ToApiError();
            }

            return(result);
        }
Ejemplo n.º 5
0
        public override async Task <TierInfoResponse> GetTierInfo(Empty request, ServerCallContext context)
        {
            var token    = context.GetBearerToken();
            var response = await _walletApiV1Client.TiersGetInfoAsync(token);

            var result = new TierInfoResponse();

            if (response.Result != null)
            {
                result.Body = new TierInfoPayload
                {
                    CurrentTier           = _mapper.Map <CurrentTier>(response.Result.CurrentTier),
                    NextTier              = _mapper.Map <NextTier>(response.Result.NextTier),
                    UpgradeRequest        = _mapper.Map <UpgradeRequest>(response.Result.UpgradeRequest),
                    QuestionnaireAnswered = response.Result.QuestionnaireAnswered
                };

                result.Body.NextTier?.Documents.AddRange(response.Result.NextTier?.Documents);
            }

            if (response.Error != null)
            {
                result.Error = response.Error.ToApiError();
            }

            return(result);
        }
Ejemplo n.º 6
0
        public override async Task <EmptyResponse> SetBaseAsset(BaseAssetUpdateRequest request, ServerCallContext context)
        {
            var result = new EmptyResponse();

            try
            {
                var token = context.GetBearerToken();
                await _walletApiV2Client.SetBaseAssetAsync(new BaseAssetUpdateModel { BaseAssetId = request.BaseAssetId },
                                                           token);

                return(result);
            }
            catch (ApiExceptionV2 ex)
            {
                if (ex.StatusCode == 404)
                {
                    result.Error = new ErrorResponseBody
                    {
                        Code    = ErrorCode.InvalidField,
                        Message = "Asset not found"
                    };

                    result.Error.Fields.Add(nameof(request.BaseAssetId), "Asset not found");

                    return(result);
                }

                throw;
            }
        }
Ejemplo n.º 7
0
        public override async Task <WatchlistsResponse> GetWatchlists(Empty request, ServerCallContext context)
        {
            var token    = context.GetBearerToken();
            var response = await _walletApiV1Client.WatchListsGetListAsync(token);

            var result = new WatchlistsResponse();

            if (response.Result != null)
            {
                result.Body = new WatchlistsResponse.Types.Body();

                foreach (var watchlist in response.Result)
                {
                    var list = _mapper.Map <Watchlist>(watchlist);
                    list.AssetIds.AddRange(watchlist.AssetIds);

                    result.Body.Result.Add(list);
                }
            }

            if (response.Error != null)
            {
                result.Error = response.Error.ToApiError();
            }

            return(result);
        }
Ejemplo n.º 8
0
        public override async Task <WatchlistResponse> UpdateWatchlist(UpdateWatchlistRequest request, ServerCallContext context)
        {
            var token    = context.GetBearerToken();
            var response = await _walletApiV1Client.WatchListsUpdateAsync(
                request.Id,
                new CustomWatchListUpdateModel
            {
                Name     = request.Name,
                Order    = request.Order,
                AssetIds = request.AssetIds.ToList()
            }, token);

            var result = new WatchlistResponse();

            if (response.Result != null)
            {
                result.Body = _mapper.Map <Watchlist>(response.Result);
                result.Body.AssetIds.AddRange(response.Result.AssetIds);
            }

            if (response.Error != null)
            {
                result.Error = response.Error.ToApiError();
            }

            return(result);
        }
Ejemplo n.º 9
0
        public override async Task <KycDocumentsResponse> GetKycDocuments(Empty request, ServerCallContext context)
        {
            var result = new KycDocumentsResponse();

            var token    = context.GetBearerToken();
            var response = await _walletApiV1Client.GetKycProfilesDocumentsByProfileTypeAsync("LykkeEurope", token);

            if (response.Result != null)
            {
                foreach (var item in response.Result)
                {
                    var document = _mapper.Map <KycDocument>(item.Value);
                    if (item.Value.Files.Any())
                    {
                        document.Files.AddRange(_mapper.Map <List <KycFile> >(item.Value.Files));
                    }

                    result.Body = new KycDocumentsResponse.Types.Body();
                    result.Body.Result.Add(item.Key, document);
                }
            }

            if (response.Error != null)
            {
                result.Error = response.Error.ToApiError();
            }

            return(result);
        }
Ejemplo n.º 10
0
        public override async Task <AssetDisclaimersResponse> GetAssetDisclaimers(Empty request, ServerCallContext context)
        {
            var result = new AssetDisclaimersResponse();

            var token    = context.GetBearerToken();
            var response = await _walletApiV1Client.GetAssetDisclaimersAsync(token);

            if (response.Result != null)
            {
                result.Body = new AssetDisclaimersResponse.Types.Body();

                foreach (var disclaimer in response.Result.Disclaimers)
                {
                    var res = new AssetDisclaimer {
                        Id = disclaimer.Id, Text = disclaimer.Text
                    };
                    result.Body.Disclaimers.Add(res);
                }
            }

            if (response.Error != null)
            {
                result.Error = response.Error.ToApiError();
            }

            return(result);
        }
Ejemplo n.º 11
0
        public override async Task <EmptyResponse> SetAddress(SetAddressRequest request, ServerCallContext context)
        {
            var result = new EmptyResponse();

            var token = context.GetBearerToken();
            await _walletApiV2Client.UpdateAddressAsync(new AddressModel { Address = request.Address }, token);

            return(result);
        }
Ejemplo n.º 12
0
        public override async Task <EmptyResponse> SetZip(SetZipRequest request, ServerCallContext context)
        {
            var result = new EmptyResponse();

            var token = context.GetBearerToken();
            await _walletApiV2Client.UpdateZipCodeAsync(new ZipCodeModel { Zip = request.Zip }, token);

            return(result);
        }
Ejemplo n.º 13
0
        public override async Task <WithdrawalCryptoInfoResponse> GetWithdrawalCryptoInfo(WithdrawalCryptoInfoRequest request, ServerCallContext context)
        {
            var result = new WithdrawalCryptoInfoResponse();

            var token    = context.GetBearerToken();
            var response = await _walletApiV2Client.GetAssetInfoAsync(request.AssetId, token);

            if (response != null)
            {
                result.Body = _mapper.Map <WithdrawalCryptoInfoResponse.Types.Body>(response);
            }

            return(result);
        }
Ejemplo n.º 14
0
        public override async Task <EmptyResponse> DeleteWatchlist(DeleteWatchlistRequest request, ServerCallContext context)
        {
            var token    = context.GetBearerToken();
            var response = await _walletApiV1Client.WatchListsDeleteAsync(request.Id, token);

            var result = new EmptyResponse();

            if (response.Error != null)
            {
                result.Error = response.Error.ToApiError();
            }

            return(result);
        }
Ejemplo n.º 15
0
        public override async Task <EmptyResponse> CryptoCashout(CryptoCashoutRequest request, ServerCallContext context)
        {
            var result = new EmptyResponse();

            var token    = context.GetBearerToken();
            var response = await _walletApiV1Client.HotWalletCashoutAsync(_mapper.Map <HotWalletCashoutOperation>(request),
                                                                          token, _walletApiConfig.Secret);

            if (response.Error != null)
            {
                result.Error = response.Error.ToApiError();
            }

            return(result);
        }
Ejemplo n.º 16
0
        public override async Task <EmptyResponse> DeclineAssetDisclaimer(AssetDisclaimerRequest request, ServerCallContext context)
        {
            var result = new EmptyResponse();

            var token = context.GetBearerToken();

            var response = await _walletApiV1Client.DeclineAssetDisclaimerAsync(request.DisclaimerId, token);

            if (response.Error != null)
            {
                result.Error = response.Error.ToApiError();
            }

            return(result);
        }
Ejemplo n.º 17
0
        public override async Task <EmptyResponse> SetPushSettings(PushSettingsRequest request, ServerCallContext context)
        {
            var result = new EmptyResponse();

            var token = context.GetBearerToken();

            var response = await _walletApiV1Client.PushSettingsPostAsync(new PushNotificationsSettingsModel { Enabled = request.Enabled }, token);

            if (response.Error != null)
            {
                result.Error = response.Error.ToApiError();
            }

            return(result);
        }
Ejemplo n.º 18
0
        public override async Task <BaseAssetResponse> GetBaseAsset(Empty request, ServerCallContext context)
        {
            var result = new BaseAssetResponse();

            var token    = context.GetBearerToken();
            var response = await _walletApiV2Client.GetBaseAssetAsync(token);

            if (response != null)
            {
                result.Body = new BaseAssetResponse.Types.Body
                {
                    AssetId = response.BaseAssetId
                };
            }

            return(result);
        }
Ejemplo n.º 19
0
        public override async Task <CryptoDepositAddressResponse> GetCryptoDepositAddress(
            CryptoDepositAddressRequest request,
            ServerCallContext context)
        {
            var result = new CryptoDepositAddressResponse();
            var token  = context.GetBearerToken();

            CryptoDepositAddressRespModel response;

            try
            {
                response = await _walletApiV2Client.GetCryptosDepositAddressesAsync(request.AssetId, token);
            }
            catch (ApiExceptionV2 ex)
            {
                if (ex.StatusCode == 400)
                {
                    var error = JsonConvert.DeserializeObject <ErrorV2Model>(ex.Response);

                    if (error.Error == "BlockchainWalletDepositAddressNotGenerated")
                    {
                        var address = await GenerateAndGetAddressAsync(request.AssetId, token);

                        if (address != null)
                        {
                            result.Body = address;
                        }

                        return(result);
                    }
                }

                throw;
            }

            if (response != null)
            {
                result.Body = new CryptoDepositAddressResponse.Types.Body
                {
                    Address = string.IsNullOrEmpty(response.BaseAddress) ? response.Address : response.BaseAddress,
                    Tag     = response.AddressExtension ?? string.Empty
                };
            }

            return(result);
        }
Ejemplo n.º 20
0
        public override async Task <ExplorerLinksResponse> GetExplorerLinks(ExplorerLinksRequest request, ServerCallContext context)
        {
            var result = new ExplorerLinksResponse();

            var token = context.GetBearerToken();

            var response = await _walletApiV2Client.GetExplorerLinksAsync(request.AssetId, request.TransactionHash,
                                                                          token);

            if (response != null)
            {
                result.Body = new ExplorerLinksResponse.Types.Body();
                result.Body.Links.AddRange(_mapper.Map <List <ExplorerLinksResponse.Types.ExplorerLinkModel> >(response.Links));
            }

            return(result);
        }
Ejemplo n.º 21
0
        public override async Task <EmptyResponse> SubmitProfile(SubmitProfileRequest request, ServerCallContext context)
        {
            var result = new EmptyResponse();

            var token = context.GetBearerToken();
            var tier  = request.OptionalTierCase == SubmitProfileRequest.OptionalTierOneofCase.None
                ? (Tier?)null
                : request.Tier == TierUpgrade.Advanced ? Tier.Advanced : Tier.ProIndividual;

            var response = await _walletApiV1Client.KycProfilesSubmitAsync("LykkeEurope", tier, token);

            if (response.Error != null)
            {
                result.Error = response.Error.ToApiError();
            }

            return(result);
        }
Ejemplo n.º 22
0
        public override async Task <SwiftCashoutInfoResponse> GetSwiftCashoutInfo(Empty request, ServerCallContext context)
        {
            var result = new SwiftCashoutInfoResponse();

            var token    = context.GetBearerToken();
            var response = await _walletApiV1Client.OffchainGetCashoutSwiftLastDataAsync(token);

            if (response.Result != null)
            {
                result.Body = _mapper.Map <SwiftCashoutInfoResponse.Types.Body>(response.Result);
            }

            if (response.Error != null)
            {
                result.Error = response.Error.ToApiError();
            }

            return(result);
        }
Ejemplo n.º 23
0
        public override async Task <SwiftCashoutFeeResponse> GetSwiftCashoutFee(SwiftCashoutFeeRequest request, ServerCallContext context)
        {
            var result = new SwiftCashoutFeeResponse();

            var token    = context.GetBearerToken();
            var response = await _walletApiV1Client.OffchainCashoutSwiftFeeAsync(request.AssetId, request.CountryCode, token);

            if (response.Result != null)
            {
                result.Body = _mapper.Map <SwiftCashoutFeeResponse.Types.Body>(response.Result);
            }

            if (response.Error != null)
            {
                result.Error = response.Error.ToApiError();
            }

            return(result);
        }
Ejemplo n.º 24
0
        public override async Task <BankCardPaymentDetailsResponse> GetBankCardPaymentDetails(Empty request, ServerCallContext context)
        {
            var result = new BankCardPaymentDetailsResponse();

            var token    = context.GetBearerToken();
            var response = await _walletApiV1Client.GetBankCardPaymentUrlFormValuesAsync(token);

            if (response.Result != null)
            {
                result.Body = _mapper.Map <BankCardPaymentDetailsResponse.Types.Body>(response.Result);
            }

            if (response.Error != null)
            {
                result.Error = response.Error.ToApiError();
            }

            return(result);
        }
Ejemplo n.º 25
0
        public override async Task <EthereumSettingsResponse> GetEthereumSettings(Empty request, ServerCallContext context)
        {
            var result = new EthereumSettingsResponse();

            var token    = context.GetBearerToken();
            var response = await _walletApiV1Client.GetEthereumPrivateWalletSettingsAsync(token);

            if (response.Result != null)
            {
                result.Body = _mapper.Map <EthereumSettingsResponse.Types.Body>(response.Result);
            }

            if (response.Error != null)
            {
                result.Error = response.Error.ToApiError();
            }

            return(result);
        }
Ejemplo n.º 26
0
        public override async Task <PendingActionsResponse> GetPendingActions(Empty request, ServerCallContext context)
        {
            var token    = context.GetBearerToken();
            var response = await _walletApiV1Client.ClientGetPendingActionsAsync(token);

            var result = new PendingActionsResponse();

            if (response.Result != null)
            {
                result.Body = _mapper.Map <PendingActionsResponse.Types.Body>(response.Result);
            }

            if (response.Error != null)
            {
                result.Error = response.Error.ToApiError();
            }

            return(result);
        }
Ejemplo n.º 27
0
        public override async Task <EmptyResponse> UploadKycFile(KycFileRequest request, ServerCallContext context)
        {
            var result = new EmptyResponse();

            var token = context.GetBearerToken();

            if (request.File.IsEmpty)
            {
                return(result);
            }

            var maxSize = _config.MaxReceiveMessageSizeInMb * 1024 * 1024;

            if (request.File.Length > maxSize)
            {
                result.Error = new ErrorResponseBody
                {
                    Code    = ErrorCode.InvalidField,
                    Message = ErrorMessages.TooBig(nameof(request.File),
                                                   request.File.Length.ToString(),
                                                   maxSize.ToString()),
                };

                result.Error.Fields.Add(nameof(request.File), result.Error.Message);

                return(result);
            }

            var provider = new FileExtensionContentTypeProvider();

            if (!provider.TryGetContentType(request.Filename, out var contentType))
            {
                contentType = "image/jpeg";
            }

            using (var ms = new MemoryStream(request.File.ToByteArray()))
            {
                await _walletApiV1Client.KycFilesUploadFileAsync(request.DocumentType, string.Empty,
                                                                 new FileParameter(ms, request.Filename, contentType), token);

                return(result);
            }
        }
Ejemplo n.º 28
0
        public override async Task <WalletResponse> GetWallet(WalletRequest request, ServerCallContext context)
        {
            var result = new WalletResponse();

            var token    = context.GetBearerToken();
            var response = await _walletApiV1Client.WalletsGetByIdAsync(request.AssetId, token);

            if (response.Result != null)
            {
                result.Body = _mapper.Map <WalletResponse.Types.Body>(response.Result);
            }

            if (response.Error != null)
            {
                result.Error = response.Error.ToApiError();
            }

            return(result);
        }
Ejemplo n.º 29
0
        public override async Task <EmptyResponse> SendBankTransferRequest(BankTransferRequest request, ServerCallContext context)
        {
            var result = new EmptyResponse();

            var token    = context.GetBearerToken();
            var response = await _walletApiV1Client.BankTransferRequestAsync(
                new TransferReqModel
            {
                AssetId       = request.AssetId,
                BalanceChange = request.BalanceChange
            },
                token);

            if (response.Error != null)
            {
                result.Error = response.Error.ToApiError();
            }

            return(result);
        }
Ejemplo n.º 30
0
        public override async Task <EmptyResponse> SaveQuestionnaire(AnswersRequest request, ServerCallContext context)
        {
            var result = new EmptyResponse();

            var token = context.GetBearerToken();

            var req = new Lykke.ApiClients.V1.AnswersRequest
            {
                Answers = _mapper.Map <List <ChoiceModel> >(request.Answers.ToList())
            };

            var response = await _walletApiV1Client.TiersSaveQuestionnaireAsync(req, token);

            if (response.Error != null)
            {
                result.Error = response.Error.ToApiError();
            }

            return(result);
        }