Skip to content

Commit

Permalink
Many more bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Relfos committed Oct 6, 2019
1 parent 5006c89 commit e5667e5
Show file tree
Hide file tree
Showing 8 changed files with 680 additions and 379 deletions.
5 changes: 5 additions & 0 deletions Assets/Scripts/Audio/AudioManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public AudioClip FindClip(string name)

public void PlaySFX(string name)
{
if (!AccountManager.Instance.Settings.sfx)
{
return;
}

var clip = FindClip(name);
if (clip == null)
{
Expand Down
106 changes: 76 additions & 30 deletions Assets/Scripts/Wallet/AccountManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,6 @@ public override string ToString()
{
return $"{name.ToUpper()} [{platforms}]";
}

public string GetAddress(PlatformKind platform)
{
if (!platforms.HasFlag(platform))
{
return null;
}

switch (platform)
{
case PlatformKind.Phantasma:
{
var keys = PhantasmaKeys.FromWIF(WIF);
return keys.Address.Text;
}

case PlatformKind.Neo:
{
var keys = NeoKeys.FromWIF(WIF);
return keys.Address;
}

default:
return null;
}
}
}

public struct HistoryEntry
Expand Down Expand Up @@ -217,6 +191,8 @@ public class AccountManager : MonoBehaviour

private int _pendingRequestCount;

private bool _accountInitialized;

private void Awake()
{
Instance = this;
Expand Down Expand Up @@ -372,10 +348,15 @@ public void RefreshTokenPrices()
}
}

private void LoadNexus()
public void UpdateAPIs()
{
phantasmaApi = new PhantasmaAPI(Settings.phantasmaRPCURL);
neoApi = new NeoAPI(Settings.neoRPCURL, Settings.neoscanURL);
}

private void LoadNexus()
{
UpdateAPIs();

PrepareTokens(new Token[] { });

Expand Down Expand Up @@ -571,6 +552,8 @@ public void SelectAccount(int index)
_lastHistoryRefresh = DateTime.MinValue;
_selectedAccountIndex = index;

_accountInitialized = false;

var platforms = CurrentAccount.platforms.Split();
CurrentPlatform = platforms.FirstOrDefault();
_states.Clear();
Expand All @@ -590,14 +573,15 @@ private void ReportWalletBalance(PlatformKind platform, AccountState state)
Debug.Log("Received new state for " + platform);
_states[platform] = state;

if (GetWorthOfPlatform(platform) > GetWorthOfPlatform(CurrentPlatform))
if (!_accountInitialized && GetWorthOfPlatform(platform) > GetWorthOfPlatform(CurrentPlatform))
{
CurrentPlatform = platform;
}
}

if (_pendingRequestCount == 0)
{
_accountInitialized = true;
InvokeRefreshCallback();
}
}
Expand Down Expand Up @@ -879,7 +863,7 @@ public void RefreshBalances(bool force, Action callback = null)
var state = new AccountState()
{
address = keys.Address,
name = keys.Address, // TODO support NNS
name = "anonymous", // TODO support NNS
balances = balanceMap.Values.ToArray(),
flags = AccountFlags.None
};
Expand Down Expand Up @@ -1005,6 +989,7 @@ public void RefreshHistory(bool force, Action callback = null)
{
hash = tx.hash,
date = new DateTime(timeSpan.Ticks).ToLocalTime(),
url = GetPhantasmaTransactionURL(tx.hash)
});
}
Expand Down Expand Up @@ -1057,6 +1042,11 @@ public void RefreshHistory(bool force, Action callback = null)
}
}

private string GetPhantasmaTransactionURL(string hash)
{
return $"https://explorer.phantasma.io/tx/{hash}";
}

private void RequestPendings(string address, Action<Swap[], string> callback)
{
StartCoroutine(phantasmaApi.GetSwapsForAddress(address, (swaps) =>
Expand Down Expand Up @@ -1213,10 +1203,66 @@ internal void DeleteAccount(int currentIndex)
SaveAccounts();
}

public void RenameAccount(string newName)
public bool RenameAccount(string newName)
{
foreach (var account in Accounts)
{
if (account.name.Equals(newName, StringComparison.OrdinalIgnoreCase))
{
return true;
}
}

Accounts[CurrentIndex].name = newName;
SaveAccounts();
return true;
}

internal void ValidateAccountName(string name, Action<string> callback)
{
StartCoroutine(
this.phantasmaApi.LookUpName(name, (address) =>
{
callback(address);
},
(error, msg) =>
{
callback(null);
})
);
}

public string GetAddress(int index, PlatformKind platform)
{
if (index < 0 || index >= Accounts.Length)
{
return null;
}

if (index == _selectedAccountIndex)
{
foreach (var entry in _states)
{
if (entry.Key == platform)
{
return entry.Value.address;
}
}
}
else
{
var wif = Accounts[index].WIF;
switch (platform)
{
case PlatformKind.Phantasma:
return PhantasmaKeys.FromWIF(wif).Address.Text;

case PlatformKind.Neo:
return NeoKeys.FromWIF(wif).Address;
}
}

return null;
}
}
}
1 change: 1 addition & 0 deletions Assets/Scripts/Wallet/ComboBox.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Poltergeist;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
Expand Down
7 changes: 7 additions & 0 deletions Assets/Scripts/Wallet/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class Settings
public const string NexusKindTag = "settings.nexus.kind";
public const string CurrencyTag = "settings.currency";
public const string GasPriceTag = "settings.fee.price";
public const string SFXTag = "settings.sfx";

public string phantasmaRPCURL;
public string neoRPCURL;
Expand All @@ -49,6 +50,7 @@ public class Settings
public string currency;
public BigInteger feePrice;
public NexusKind nexusKind;
public bool sfx;

public void Load()
{
Expand All @@ -64,6 +66,7 @@ public void Load()
this.nexusName = PlayerPrefs.GetString(NexusNameTag, GetDefaultValue(NexusNameTag));

this.currency = PlayerPrefs.GetString(CurrencyTag, "USD");
this.sfx = PlayerPrefs.GetInt(SFXTag, 1)!=0;

var defaultGasPrice = 100000;
if (!BigInteger.TryParse(PlayerPrefs.GetString(GasPriceTag, defaultGasPrice.ToString()), out feePrice))
Expand All @@ -79,6 +82,9 @@ public string GetDefaultValue(string tag)
case PhantasmaRPCTag:
switch (nexusKind)
{
case NexusKind.Main_Net:
return "http://207.148.17.86:7071/rpc";

case NexusKind.Local_Net:
return "http://localhost:7077/rpc";

Expand Down Expand Up @@ -135,6 +141,7 @@ public void Save()
PlayerPrefs.SetString(NexusNameTag, this.nexusName);
PlayerPrefs.SetString(CurrencyTag, this.currency);
PlayerPrefs.SetString(GasPriceTag, this.feePrice.ToString());
PlayerPrefs.SetInt(SFXTag, this.sfx ?1:0);
PlayerPrefs.Save();
}

Expand Down
Loading

0 comments on commit e5667e5

Please sign in to comment.