Enhance user authentication by adding optional OwnerWalletAddress parameter in LoginRequest and UserService. Update UserController and related components to support the new wallet address functionality, ensuring better user profile management and validation in trading operations.
This commit is contained in:
@@ -163,25 +163,20 @@ namespace Managing.Application.ManageBot
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ValidateKudaiStakingRequirements(User user)
|
||||
private async Task ValidateKudaiStakingRequirements(User user)
|
||||
{
|
||||
// Use the user's wallet address directly
|
||||
if (string.IsNullOrEmpty(user.OwnerWalletAddress))
|
||||
{
|
||||
// Get user's accounts to find their wallet address
|
||||
var userAccounts = await _accountService.GetAccountsByUserAsync(user, true, true);
|
||||
var evmAccount = userAccounts.FirstOrDefault(acc =>
|
||||
acc.Exchange == TradingExchanges.Evm ||
|
||||
acc.Exchange == TradingExchanges.GmxV2);
|
||||
throw new InvalidOperationException(
|
||||
"To copy trade the Kudai strategy, you must have a wallet address configured in your profile.");
|
||||
}
|
||||
|
||||
if (evmAccount == null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"To copy trade the Kudai strategy, you must have an EVM-compatible account (GMX V2 or EVM exchange).");
|
||||
}
|
||||
// Check KUDAI staked balance
|
||||
var kudaiStakedBalance = await _evmManager.GetKudaiStakedBalance(user.OwnerWalletAddress);
|
||||
|
||||
// Check KUDAI staked balance
|
||||
var kudaiStakedBalance = await _evmManager.GetKudaiStakedBalance(evmAccount.Key);
|
||||
|
||||
// Check GBC staked NFT count
|
||||
var gbcStakedCount = await _evmManager.GetGbcStakedCount(evmAccount.Key);
|
||||
// Check GBC staked NFT count
|
||||
var gbcStakedCount = await _evmManager.GetGbcStakedCount(user.OwnerWalletAddress);
|
||||
|
||||
// Requirements: 100 million KUDAI OR 10 GBC NFTs
|
||||
const decimal requiredKudaiAmount = 100_000_000m; // 100 million
|
||||
|
||||
@@ -45,7 +45,7 @@ public class UserService : IUserService
|
||||
: authorizedAddressesString.Split(';', StringSplitOptions.RemoveEmptyEntries);
|
||||
}
|
||||
|
||||
public async Task<User> Authenticate(string name, string address, string message, string signature)
|
||||
public async Task<User> Authenticate(string name, string address, string message, string signature, string? ownerWalletAddress = null)
|
||||
{
|
||||
var recoveredAddress = _evmManager.VerifySignature(signature, message);
|
||||
|
||||
@@ -106,6 +106,13 @@ public class UserService : IUserService
|
||||
throw new Exception("Account not found for address " + recoveredAddress);
|
||||
}
|
||||
|
||||
// Update owner wallet address if provided and user doesn't have one set yet
|
||||
if (!string.IsNullOrEmpty(ownerWalletAddress) && string.IsNullOrEmpty(user.OwnerWalletAddress))
|
||||
{
|
||||
user.OwnerWalletAddress = ownerWalletAddress;
|
||||
await _userRepository.SaveOrUpdateUserAsync(user);
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
else
|
||||
@@ -113,7 +120,8 @@ public class UserService : IUserService
|
||||
// First login - create user first
|
||||
user = new User
|
||||
{
|
||||
Name = name
|
||||
Name = name,
|
||||
OwnerWalletAddress = ownerWalletAddress ?? string.Empty
|
||||
};
|
||||
|
||||
// Save the user first
|
||||
|
||||
Reference in New Issue
Block a user