Skip to content

Commit

Permalink
Merge pull request #977 from Portkey-Wallet/feature/revamp-v2.2
Browse files Browse the repository at this point in the history
Feature/revamp v2.2
  • Loading branch information
sunny-k123 authored Nov 20, 2024
2 parents a2bb0f9 + 28b2edc commit 586677b
Show file tree
Hide file tree
Showing 73 changed files with 1,910 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.ComponentModel.DataAnnotations;

namespace CAServer.AddressBook.Dtos;

public class AddressBookCreateRequestDto
{
[RegularExpression(@"^[a-zA-Z\d'_'' '\s]{1,16}$")]
[Required]
public string Name { get; set; }

[Required] public string Address { get; set; }
[Required] public string Network { get; set; }
public string ChainId { get; set; }
public bool IsExchange { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;

namespace CAServer.AddressBook.Dtos;

public class AddressBookDeleteRequestDto
{
public Guid Id { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace CAServer.AddressBook.Dtos;

public class AddressBookDto
{
public Guid Id { get; set; }
public string Index { get; set; }
public string Name { get; set; }
public ContactAddressInfoDto AddressInfo { get; set; }
public ContactCaHolderInfo CaHolderInfo { get; set; }
public Guid UserId { get; set; }
public bool IsDeleted { get; set; }
public DateTime CreateTime { get; set; }
public DateTime ModificationTime { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace CAServer.AddressBook.Dtos;

public class AddressBookExistDto
{
public bool Existed { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Volo.Abp.Application.Dtos;

namespace CAServer.AddressBook.Dtos;

public class AddressBookListRequestDto : PagedResultRequestDto
{
public string Filter { get; set; }
public string Sort { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;

namespace CAServer.AddressBook.Dtos;

public class AddressBookUpdateRequestDto : AddressBookCreateRequestDto
{
public Guid Id { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace CAServer.AddressBook.Dtos;

public class ContactAddressInfo
{
public string Network { get; set; }
public string NetworkName { get; set; }
public string ChainId { get; set; }
public string Address { get; set; }
public bool IsExchange { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace CAServer.AddressBook.Dtos;

public class ContactAddressInfoDto : ContactAddressInfo
{
public string NetworkImage { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace CAServer.AddressBook.Dtos;

public class ContactCaHolderInfo
{
public Guid UserId { get; set; }
public string CaHash { get; set; }
public string WalletName { get; set; }
public string Avatar { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Collections.Generic;

namespace CAServer.AddressBook.Dtos;

public class GetNetworkListDto
{
public List<AddressBookNetwork> NetworkList { get; set; }
}

public class AddressBookNetwork
{
public string Network { get; set; }
public string Name { get; set; }
public string ChainId { get; set; }
public string ImageUrl { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using CAServer.AddressBook.Dtos;

namespace CAServer.AddressBook.Etos;

public class AddressBookEto : AddressBookDto
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Threading.Tasks;
using CAServer.AddressBook.Dtos;
using Volo.Abp.Application.Dtos;

namespace CAServer.AddressBook;

public interface IAddressBookAppService
{
Task<AddressBookDto> CreateAsync(AddressBookCreateRequestDto requestDto);
Task<AddressBookDto> UpdateAsync(AddressBookUpdateRequestDto requestDto);
Task DeleteAsync(AddressBookDeleteRequestDto requestDto);
Task<AddressBookExistDto> ExistAsync(string name);
Task<PagedResultDto<AddressBookDto>> GetListAsync(AddressBookListRequestDto requestDto);
Task<GetNetworkListDto> GetNetworkListAsync();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace CAServer.AddressBook.Migrate.Dto;

public class AddressBookMigrateDto
{
public string Name { get; set; }
public Guid UserId { get; set; }
public string Address { get; set; }
public string Network { get; set; }
public string ChainId { get; set; }
public bool IsExchange { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace CAServer.AddressBook.Migrate.Dto;

public class ContactMigrateCache
{
public int MigrateCount { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;

namespace CAServer.AddressBook.Migrate.Eto;

public class AddressBookMigrateEto
{
public string Id { get; set; } = Guid.NewGuid().ToString("N");
public Guid OriginalContactId { get; set; }
public Guid NewContactId { get; set; }
public Guid UserId { get; set; }
public string ChainId { get; set; }
public string Address { get; set; }
public string FailType { get; set; }
public string Status { get; set; }
public string Message { get; set; }
public DateTime CreateTime { get; set; }
public DateTime UpdateTime { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System.Threading.Tasks;

namespace CAServer.AddressBook.Migrate;

public interface IAddressBookMigrateService
{
Task MigrateAsync();
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public static class ActivityConstants
public const string AddManagerInfo = "AddManagerInfo";
public const string NotRegisterChainAddGuardianName = "Security upgrade-add guardian";
public const string NotRegisterChainAddManagerName = "Security upgrade-Scan code login";
public const string ReceiveName = "Receive";
public const string SendName = "Send";
public const string ReceiveName = "Received";
public const string SendName = "Sent";
public const string SwapExactTokensForTokensName = "SwapExactTokensForTokens";
public const string FreeMintNftName = "MintNft";
public const string DepositTypeName = "ReleaseToken";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ public class ActivityBase
public string ToAddress { get; set; }
public string FromChainId { get; set; }
public string FromChainIdUpdated { get; set; }
public string FromChainIcon { get; set; }
public string ToChainId { get; set; }
public string ToChainIdUpdated { get; set; }
public string ToChainIcon { get; set; }
public List<TransactionFee> TransactionFees { get; set; }
public string PriceInUsd { get; set; }
public bool IsDelegated { get; set; }
Expand Down
69 changes: 69 additions & 0 deletions src/CAServer.Application.Contracts/Commons/AddressHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System.Collections.Generic;
using System.Linq;

namespace CAServer.Commons;

public static class AddressHelper
{
private const string FullAddressPrefix = "ELF";
private const char FullAddressSeparator = '_';

public static string ToFullAddress(string address, string chainId)
{
if (address.Contains(FullAddressSeparator)) return address;

return string.Join(FullAddressSeparator, FullAddressPrefix, address, chainId);
}

public static string ToShortAddress(string address)
{
if (string.IsNullOrEmpty(address)) return address;
var parts = address.Split(FullAddressSeparator);
return parts.Length < 3 ? parts[parts.Length - 1] : parts[1];
}

public static string GetChainId(string address)
{
if (string.IsNullOrEmpty(address)) return string.Empty;
var chainId = address.Split(FullAddressSeparator).ToList().Last();
return chainId.Length != 4 ? string.Empty : chainId;
}

public static readonly Dictionary<string, string> ChainNameMap = new Dictionary<string, string>
{
[CommonConstant.MainChainId] = "aelf MainChain",
[CommonConstant.TDVWChainId] = "aelf dAppChain",
[CommonConstant.TDVVChainId] = "aelf dAppChain",
["ARBITRUM"] = "Arbitrum One",
["AVAXC"] = "AVAX C-Chain",
["Base"] = "Base", // need to confirm
["BSC"] = "BNB Smart Chain",
["TBSC"] = "BNB Smart Chain",
["ETH"] = "Ethereum",
["SETH"] = "Ethereum",
["OPTIMISM"] = "Optimism",
["MATIC"] = "Polygon",
["Solana"] = "Solana",
["TRX"] = "TRON",
["TON"] = "The Open Network"
};

public static string GetNetworkName(string network)
{
return ChainNameMap.GetOrDefault(network);
}

public static string GetNetwork(string network)
{
return network is CommonConstant.MainChainId or CommonConstant.TDVWChainId or CommonConstant.TDVWChainId
? "aelf"
: network;
}

public static string GetAelfChainId(string network)
{
return network is CommonConstant.MainChainId or CommonConstant.TDVWChainId or CommonConstant.TDVWChainId
? network
: null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ public static string GetDisplayName(string chainId)
? displayName
: chainId;
}

public static string GetChainUrl(string chainId)
{
return ChainImageUrlMap.TryGetValue(chainId, out var chainUrl)
? chainUrl
: string.Empty;
}

public static void SetDisplayName<T>(List<T> list)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,5 @@ public static class CommonConstant
public const string TokenInfoCachePrefix = "TokenInfo";
public const string SyncStateUri = "apps/sync-state";
public const string ReplaceUri = "app/graphql";
public const string V2ApiVersion = "v2";
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public static class ETransferConstant
public const string ToType = "to";
public const string TronName = "TRX";
public const string DefaultToken = "ELF";
public const string InvalidAddressCode = "40001";
public const string InvalidAddressMessage= "Invalid address";


public const string GetConnectToken = "connect/token";
Expand Down
Loading

0 comments on commit 586677b

Please sign in to comment.