/// <summary> /// Updates the ui for the newest TradableAsset. /// </summary> private void UpdateAssetUI() { var tradableAsset = tradableAssetManager.ActiveTradableAsset; if (tradableAsset == null) { return; } string assetBalance = tradableAsset.AssetBalance?.ToString(); string assetSymbol = tradableAsset.AssetSymbol; if (!string.IsNullOrEmpty(assetBalance)) { balanceText.text = assetBalance.LimitEnd(MAX_ASSET_BALANCE_LENGTH - (assetSymbol.Length + 1), "...") + $"<style=Symbol> {assetSymbol}</size>"; } if (!string.IsNullOrEmpty(assetBalance) && tradableAsset.AssetAddress.EqualsIgnoreCase(prpsContract.ContractAddress) && lockedPrpsManager.UnfulfilledItems.Count > 0) { balanceText.text = $"{balanceText.text} | {SolidityUtils.ConvertFromUInt(lockedPrpsManager.UnfulfilledItems.Select(item => item.Value).Aggregate((v1, v2) => v1 + v2), 18)}<style=Symbol> Locked</style>"; } lockPurposeSection.SetActive(tradableAsset.AssetAddress.EqualsIgnoreCase(prpsContract.ContractAddress)); assetText.text = tradableAsset.AssetName.LimitEnd(MAX_ASSET_NAME_LENGTH, "..."); assetImage.sprite = tradableAsset.AssetImage; UpdateAssetNotifications(); }
/// <summary> /// Assigns the transaction info to all elements in this popup. /// </summary> private void AssignTransactionInfo() { var sendTransaction = transactionInfo.Type == TransactionInfo.TransactionType.Send; var valSymbol = sendTransaction ? "-" : "+"; var tradableAsset = tradableAssetManager.GetTradableAsset(transactionInfo.AssetAddress); assetImage.sprite = tradableAsset.AssetImage; valueText.color = sendTransaction ? UIColors.Red : UIColors.Green; transactionHash.text = transactionInfo.TxHash; valueText.text = StringUtils.LimitEnd(valSymbol + SolidityUtils.ConvertFromUInt(transactionInfo.Value, tradableAsset.AssetDecimals).ConvertDecimalToString(), 18, "...") + "<style=Symbol> " + tradableAsset.AssetSymbol + "</style>"; fromAddress.text = transactionInfo.From; toAddress.text = transactionInfo.To; timestampText.text = DateTimeUtils.TimeStampToDateTime(transactionInfo.TimeStamp).GetFormattedDateAndTimeString(true); gasUsedText.text = transactionInfo.GasUsed.ToString(); txCostText.text = (UnitConversion.Convert.FromWei(transactionInfo.GasPrice) * transactionInfo.GasUsed).ConvertDecimalToString() + "<style=Symbol> Ether</style>"; CheckIfContact(transactionInfo.From.ToLower(), fromAddressName); CheckIfContact(transactionInfo.To.ToLower(), toAddressName); TransactionUtils.GetTransactionDetails(transactionInfo.TxHash).OnSuccess(tx => { gasPriceText.SetText(UnitConversion.Convert.FromWei(tx.GasPrice.Value, UnitConversion.EthUnit.Gwei) + "<style=Symbol> Gwei</style>"); gasLimitText.SetText(tx.Gas.Value.ToString()); }); }
public async Task <decimal> QueryAllowance(string owner, string spender) { var allowance = await SimpleContractQueries.QueryUInt256Output(new Queries.Allowance { Owner = owner, Spender = spender }, ContractAddress, null); return(SolidityUtils.ConvertFromUInt(allowance.Value, Decimals.Value)); }
/// <summary> /// Gets the token balance of an address. /// </summary> /// <param name="address"> The address to check the balance of. </param> public async Task <decimal> QueryBalanceOf(string address) { var balance = await SimpleContractQueries.QueryUInt256Output(new Queries.BalanceOf { Owner = address }, ContractAddress, address); return(SolidityUtils.ConvertFromUInt(balance.Value, Decimals.Value)); }
/// <summary> /// Sets the amount of the asset that was traded in this transaction. /// </summary> /// <param name="transaction"> The info of this transaction. </param> /// <param name="tradableAsset"> The asset that was traded. </param> private void SetAmount(TransactionInfo transaction, TradableAsset tradableAsset) { var send = transaction.Type == TransactionInfo.TransactionType.Send; var start = send ? "-" : "+"; var amount = start + SolidityUtils.ConvertFromUInt(transaction.Value, tradableAsset.AssetDecimals); var symbol = tradableAsset.AssetSymbol; amountText.SetText(amount.LimitEnd(18 - symbol.Length, "...") + "<style=Symbol> " + symbol + "</style>"); amountText.color = send ? UIColors.Red : UIColors.Green; }
/// <summary> /// Gets the total supply of this ERC20 token contract. /// </summary> public EthCallPromise <decimal> QueryTotalSupply() { EthCallPromise <decimal> promise = new EthCallPromise <decimal>(); SimpleContractQueries.QueryUInt256Output(new Queries.TotalSupply(), ContractAddress, null) .OnSuccess(supply => promise.Build(() => SolidityUtils.ConvertFromUInt(supply.Value, Decimals.Value))) .OnError(error => promise.Build(() => "error", () => error)); return(promise); }
public EthCallPromise <decimal> QueryAllowance(string owner, string spender) { EthCallPromise <decimal> promise = new EthCallPromise <decimal>(); SimpleContractQueries.QueryUInt256Output(new Queries.Allowance { Owner = owner, Spender = spender }, ContractAddress, null) .OnSuccess(allowance => promise.Build(() => SolidityUtils.ConvertFromUInt(allowance.Value, Decimals.Value))) .OnError(error => promise.Build(() => "error", () => error)); return(promise); }
/// <summary> /// Gets the token balance of an address. /// </summary> /// <param name="address"> The address to check the balance of. </param> public EthCallPromise <decimal> QueryBalanceOf(string address) { EthCallPromise <decimal> promise = new EthCallPromise <decimal>(); SimpleContractQueries.QueryUInt256Output(new Queries.BalanceOf { Owner = address }, ContractAddress, address) .OnSuccess(balance => promise.Build(() => SolidityUtils.ConvertFromUInt(balance.Value, Decimals.Value))) .OnError(error => promise.Build(() => "error", () => error)); return(promise); }
public async Task QueryTest() { SimpleOutputs.UInt256 output = await ContractUtils.QueryContract <ERC20.Queries.BalanceOf, SimpleOutputs.UInt256>( new ERC20.Queries.BalanceOf { Owner = "0x0000000000000000000000000000000000000000" }, "0x6810e776880C02933D47DB1b9fc05908e5386b96", null).ConfigureAwait(false); decimal result = SolidityUtils.ConvertFromUInt(output.Value, 18); Assert.IsTrue(result > 0); }
/// <summary> /// Gets the gas limit which would be used to lock the curent purpose balance. /// </summary> /// <param name="prpsBalance"> The output received from the BalanceOf function of the PRPS contract. </param> private void GetLockableGasLimit(SimpleOutputs.UInt256 prpsBalance) { PRPSBalance = SolidityUtils.ConvertFromUInt(prpsBalance.Value, 18); if (prpsBalance.Value <= 0) { return; } object[] funcParams = new object[] { estimationId, prpsBalance.Value, estimationMonths }; GasUtils.EstimateContractGasLimit <Hodler.Messages.Hodl>(hodlerContract.ContractAddress, userWalletManager.GetWalletAddress(), funcParams).OnSuccess(limit => GasLimit = limit); OnAmountsUpdated?.Invoke(); }
/// <summary> /// Updates the ui elements and the transaction info whenever the HodlerItem is changed/updated. /// </summary> /// <param name="info"> The item that holds the info on the purpose locked in the contract. </param> protected override void OnValueUpdated(Hodler.Output.Item info) { lockedPurpose = SolidityUtils.ConvertFromUInt(info.Value, 18); item = info; var minPercentageTime = networkSettings.networkType == EthereumNetworkManager.NetworkType.Mainnet ? MIN_PERCENTAGE_TIME_MAINNET : MIN_PERCENTAGE_TIME_RINKEBY; var releaseTimeDifference = info.ReleaseTime - info.LockedTimeStamp; var currentTimeDifference = info.ReleaseTime - DateTimeUtils.GetCurrentUnixTime(); var multiplier = (decimal)releaseTimeDifference / minPercentageTime / 100; lockPeriodDone = currentTimeDifference < 0; purposeAmountText.text = lockedPurpose.ConvertDecimalToString().LimitEnd(12, "..."); dubiAmountText.text = (multiplier * lockedPurpose).ConvertDecimalToString().LimitEnd(11, "..."); lockPeriodText.text = DateTimeUtils.GetMaxTimeInterval((int)releaseTimeDifference); timeLeftText.text = currentTimeDifference < 0 && !useUnlockableTime ? "Done" : !useUnlockableTime ? GetTimeLeftString((int)currentTimeDifference) : DateTimeUtils.TimeStampToDateTime((long)info.ReleaseTime).GetStringFormattedDate(true); }
/// <summary> /// Gets the most recent DUBI balance. /// </summary> /// <param name="contractAddress"> The contract address for DUBI. </param> /// <param name="walletAddress"> The current wallet address. </param> private void GetDUBIBalance(string contractAddress, string walletAddress) { SimpleContractQueries.QueryUInt256Output <ERC20.Queries.BalanceOf>(contractAddress, walletAddress, walletAddress) .OnSuccess(balance => DUBIBalance = SolidityUtils.ConvertFromUInt(balance.Value, 18)); }
/// <summary> /// Gets the total supply of this ERC20 token contract. /// </summary> public async Task <decimal> QueryTotalSupply() { var supply = await SimpleContractQueries.QueryUInt256Output(new Queries.TotalSupply(), ContractAddress, null); return(SolidityUtils.ConvertFromUInt(supply.Value, Decimals.Value)); }
/// <summary> /// Gets the total supply of this ERC20 token contract. /// </summary> /// <param name="onSupplyReceived"> Callback action which should pass in the total supply of this token. </param> public void TotalSupply(Action <dynamic> onSupplyReceived) { SimpleContractQueries.QueryUInt256Output <Queries.TotalSupply>(ContractAddress, null) .OnSuccess(supply => onSupplyReceived?.Invoke(SolidityUtils.ConvertFromUInt(supply, Decimals.Value))); }
/// <summary> /// Gets the token balance of an address. /// </summary> /// <param name="address"> The address to check the balance of. </param> /// <param name="onBalanceReceived"> Callback action which should pass in the received balance of Gold tokens on the address. </param> public void BalanceOf(string address, Action <dynamic> onBalanceReceived) { SimpleContractQueries.QueryUInt256Output <Queries.BalanceOf>(ContractAddress, address, address) .OnSuccess(balance => onBalanceReceived?.Invoke(SolidityUtils.ConvertFromUInt(balance, Decimals.Value))); }