public async Task <LinkingRequestResultModel> CreateLinkRequestAsync(Guid customerId) { #region Validation if (customerId == Guid.Empty) { return(LinkingRequestResultModel.Failed(LinkingError.InvalidCustomerId)); } var walletError = await CheckWalletStatus(customerId.ToString()); if (walletError != LinkingError.None) { return(LinkingRequestResultModel.Failed(walletError)); } var linkRequest = await _requestsRepository.GetByIdAsync(customerId.ToString()); if (linkRequest != null) { _log.Warning(message: "Link request already exists", context: new { customerId }); return(LinkingRequestResultModel.Succeeded(linkRequest.LinkCode)); } var walletResponse = await _pbfClient.CustomersApi.GetWalletAddress(customerId); if (walletResponse.Error != CustomerWalletAddressError.None) { _log.Error(message: "Can't get customer wallet address", context: new { customerId, error = walletResponse.Error.ToString() }); return(LinkingRequestResultModel.Failed(LinkingError.CustomerWalletMissing)); } #endregion var linkCode = GenerateRandomLinkCode(); try { await _requestsRepository.AddAsync(customerId.ToString(), walletResponse.WalletAddress, linkCode); } catch (LinkingRequestAlreadyExistsException) { return(LinkingRequestResultModel.Failed(LinkingError.LinkingRequestAlreadyExists)); } _log.Info("New wallet linking request has been added", new { customerId, linkCode }); return(LinkingRequestResultModel.Succeeded(linkCode)); }
public async Task <PublicAddressResultModel> GetPublicAddressAsync(Guid customerId) { if (customerId == Guid.Empty) { return(PublicAddressResultModel.Failed(PublicAddressError.InvalidCustomerId)); } var linkingRequest = await _requestsRepository.GetByIdAsync(customerId.ToString()); if (linkingRequest == null) { return(PublicAddressResultModel.Succeeded(string.Empty, PublicAddressStatus.NotLinked)); } if (linkingRequest.IsPendingApproval()) { return(PublicAddressResultModel.Succeeded(string.Empty, PublicAddressStatus.PendingCustomerApproval)); } if (linkingRequest.IsConfirmed()) { return(PublicAddressResultModel.Succeeded(linkingRequest.PublicAddress, PublicAddressStatus.Linked)); } return(PublicAddressResultModel.Succeeded(linkingRequest.PublicAddress, PublicAddressStatus.PendingConfirmation)); }