Skip to content

Commit

Permalink
Fix swap destination verification for manually entered addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmpa committed Feb 27, 2021
1 parent 9a1495d commit f607687
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
5 changes: 5 additions & 0 deletions Assets/Scripts/Wallet/AccountManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ public static PlatformKind GetTransferTargets(this PlatformKind kind, Token toke
return PlatformKind.None;
}
}
public static bool ValidateTransferTarget(this PlatformKind kind, Token token, PlatformKind targetKind)
{
var targets = kind.GetTransferTargets(token);
return targets.HasFlag(targetKind);
}
}

public struct TransferRequest
Expand Down
21 changes: 14 additions & 7 deletions Assets/Scripts/Wallet/WalletGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4363,7 +4363,7 @@ private void DoBalanceEntry(Balance balance, int index, int curY, Rect rect)
var ethereumAddressUtil = new Phantasma.Ethereum.Util.AddressUtil();
if (Address.IsValidAddress(destAddress))
if (Address.IsValidAddress(destAddress) && accountManager.CurrentPlatform.ValidateTransferTarget(transferToken, PlatformKind.Phantasma))
{
if (accountManager.CurrentPlatform == PlatformKind.Phantasma)
{
Expand All @@ -4375,7 +4375,7 @@ private void DoBalanceEntry(Balance balance, int index, int curY, Rect rect)
}
}
else
if (Phantasma.Neo.Utils.NeoUtils.IsValidAddress(destAddress))
if (Phantasma.Neo.Utils.NeoUtils.IsValidAddress(destAddress) && accountManager.CurrentPlatform.ValidateTransferTarget(transferToken, PlatformKind.Neo))
{
if (accountManager.CurrentPlatform == PlatformKind.Neo)
{
Expand All @@ -4392,7 +4392,7 @@ private void DoBalanceEntry(Balance balance, int index, int curY, Rect rect)
}
}
else
if (ethereumAddressUtil.IsValidEthereumAddressHexFormat(destAddress) && ethereumAddressUtil.IsChecksumAddress(destAddress))
if (ethereumAddressUtil.IsValidEthereumAddressHexFormat(destAddress) && ethereumAddressUtil.IsChecksumAddress(destAddress) && accountManager.CurrentPlatform.ValidateTransferTarget(transferToken, PlatformKind.Ethereum))
{
if (accountManager.CurrentPlatform == PlatformKind.Ethereum)
{
Expand All @@ -4409,7 +4409,7 @@ private void DoBalanceEntry(Balance balance, int index, int curY, Rect rect)
}
}
else
if (ValidationUtils.IsValidIdentifier(destAddress) && destAddress != state.name)
if (ValidationUtils.IsValidIdentifier(destAddress) && destAddress != state.name && accountManager.CurrentPlatform.ValidateTransferTarget(transferToken, PlatformKind.Phantasma))
{
BeginWaitingModal("Looking up account name");
accountManager.ValidateAccountName(destAddress, (lookupAddress) =>
Expand Down Expand Up @@ -5726,7 +5726,9 @@ private int DoBottomMenuForNftTransferList()
return; // user canceled
}
if (Address.IsValidAddress(destAddress))
var ethereumAddressUtil = new Phantasma.Ethereum.Util.AddressUtil();
if (Address.IsValidAddress(destAddress) && accountManager.CurrentPlatform.ValidateTransferTarget(transferToken, PlatformKind.Phantasma))
{
if (accountManager.CurrentPlatform == PlatformKind.Phantasma)
{
Expand All @@ -5740,10 +5742,15 @@ private int DoBottomMenuForNftTransferList()
else
if (Phantasma.Neo.Utils.NeoUtils.IsValidAddress(destAddress))
{
MessageBox(MessageKind.Error, $"Direct transfers from {accountManager.CurrentPlatform} to this type of address not supported.");
MessageBox(MessageKind.Error, $"Direct transfers from {accountManager.CurrentPlatform} to Neo address not supported.");
}
else
if (ethereumAddressUtil.IsValidEthereumAddressHexFormat(destAddress) && ethereumAddressUtil.IsChecksumAddress(destAddress))
{
MessageBox(MessageKind.Error, $"Direct transfers from {accountManager.CurrentPlatform} to Ethereum address not supported.");
}
else
if (ValidationUtils.IsValidIdentifier(destAddress) && destAddress != state.name)
if (ValidationUtils.IsValidIdentifier(destAddress) && destAddress != state.name && accountManager.CurrentPlatform.ValidateTransferTarget(transferToken, PlatformKind.Phantasma))
{
BeginWaitingModal("Looking up account name");
accountManager.ValidateAccountName(destAddress, (lookupAddress) =>
Expand Down

0 comments on commit f607687

Please sign in to comment.