コード例 #1
0
 private void InitializeValues()
 {
     pageNum = (userWalletManager.AccountNumber / 5) + 1;
     firstAddressNumInList    = pageNum == 0 ? 1 : (pageNum * 5) - 4;
     currentlySelectedAddress = userWalletManager.AccountNumber + 1;
     unlockedAccount          = userWalletManager.GetWalletAddress();
 }
コード例 #2
0
        private void AccountChanged()
        {
            var address            = userWalletManager.GetWalletAddress();
            var pendingTransaction = ethereumPendingTransactionManager.GetPendingTransaction(address);

            if ((PendingTransactionSectionOpen && pendingTransaction == null) || (PendingTransactionSectionOpen && !pendingTransaction.isPending && pendingTransaction.result == null))
            {
                AnimatePendingTransactionSection(false);
            }
            else if (!PendingTransactionSectionOpen && pendingTransaction?.isPending == true)
            {
                TransactionStarted(pendingTransaction.txHash, pendingTransaction.message);
            }
            else if (!PendingTransactionSectionOpen && pendingTransaction?.isPending == false && pendingTransaction?.result != null)
            {
                TransactionFinished(pendingTransaction.result == EthereumPendingTransactionManager.PendingTransaction.TransactionResult.Success);
                AnimatePendingTransactionSection(true, false);
            }
            else if (PendingTransactionSectionOpen && ((pendingTransaction?.isPending == true && pendingTransaction?.result == null) || pendingTransaction?.result != null))
            {
                TransactionStarted(pendingTransaction.txHash, pendingTransaction.message);

                if (pendingTransaction.result != null)
                {
                    TransactionFinished(pendingTransaction.result == EthereumPendingTransactionManager.PendingTransaction.TransactionResult.Success);
                }
            }
        }
コード例 #3
0
    /// <summary>
    /// Initializes all components and assigns them with the values of the current TradableAsset.
    /// </summary>
    protected override void OnStart()
    {
        var walletAddress = userWalletManager.GetWalletAddress();
        var tradableAsset = tradableAssetManager.ActiveTradableAsset;
        var symbol        = tradableAsset.AssetSymbol;

        addressText.text = walletAddress;
        qrImage.sprite   = QRUtils.GenerateQRCode(walletAddress);

        copyButton.onClick.AddListener(CopyAddressClicked);
    }
コード例 #4
0
    private void CheckTokenContract(bool existsInTokenList)
    {
        if (existsInTokenList)
        {
            return;
        }

        addressField.InputFieldBase.interactable = false;

        OnStatusChanged?.Invoke(Status.Loading);

        string addressText = addressField.Text;

        ERC20 erc20 = new ERC20(addressText);

        erc20.OnInitializationSuccessful(() =>
        {
            tradableAssetImageManager.LoadImage(erc20.Symbol, img =>
            {
                tokenIcon.sprite = img;

                CheckStatus(erc20.Symbol, erc20.Name, erc20.Decimals, 0);
            });
        });

        erc20.OnInitializationUnsuccessful(() =>
        {
            SimpleContractQueries.QueryUInt256Output <BalanceOf>(addressText, userWalletManager.GetWalletAddress(), userWalletManager.GetWalletAddress())
            .OnSuccess(balance => CheckStatus(null, null, null, balance.Value))
            .OnError(_ => CheckStatus(null, null, null, null));
        });
    }
コード例 #5
0
    /// <summary>
    /// Adds an asset to the list of assets to scrape transactions for.
    /// </summary>
    /// <param name="asset"> The asset to scrape transactions for. </param>
    private void AddAssetToScrape(TradableAsset asset)
    {
        if (asset?.AssetAddress == null)
        {
            return;
        }

        if (asset is EtherAsset)
        {
            QueueEther(userWalletManager.GetWalletAddress());
        }
        else
        {
            QueueToken(asset.AssetAddress, userWalletManager.GetWalletAddress());
        }
    }
コード例 #6
0
        public WalletNameSection(
            HopeWalletInfoManager hopeWalletInfoManager,
            WalletPasswordVerification walletPasswordVerification,
            ContactsManager contactsManager,
            DynamicDataCache dynamicDataCache,
            UserWalletManager userWalletManager,
            SettingsPopupAnimator settingsPopupAnimator,
            GameObject currentPasswordSection,
            GameObject walletNameSection,
            GameObject loadingIcon,
            HopeInputField currentPasswordField,
            HopeInputField currentWalletNameField,
            HopeInputField newWalletNameField,
            Button nextButton,
            Button saveButton,
            GameObject[] hopeOnlyCategoryButtons)
        {
            this.hopeWalletInfoManager      = hopeWalletInfoManager;
            this.walletPasswordVerification = walletPasswordVerification;
            this.contactsManager            = contactsManager;
            this.dynamicDataCache           = dynamicDataCache;
            this.settingsPopupAnimator      = settingsPopupAnimator;
            this.currentPasswordSection     = currentPasswordSection;
            this.walletNameSection          = walletNameSection;
            this.loadingIcon             = loadingIcon;
            this.currentPasswordField    = currentPasswordField;
            this.currentWalletNameField  = currentWalletNameField;
            this.newWalletNameField      = newWalletNameField;
            this.nextButton              = nextButton;
            this.saveButton              = saveButton;
            this.hopeOnlyCategoryButtons = hopeOnlyCategoryButtons;

            walletInfo = hopeWalletInfoManager.GetWalletInfo(userWalletManager.GetWalletAddress());
            SetListeners();
        }
コード例 #7
0
        public PasswordSection(
            PlayerPrefPasswordDerivation playerPrefPasswordDerivation,
            UserWalletManager userWalletManager,
            HopeWalletInfoManager hopeWalletInfoManager,
            DynamicDataCache dynamicDataCache,
            SettingsPopupAnimator settingsPopupAnimator,
            HopeInputField newPasswordField,
            HopeInputField confirmPasswordField,
            Button saveButton,
            GameObject loadingIcon)
        {
            this.playerPrefPasswordDerivation = playerPrefPasswordDerivation;
            this.hopeWalletInfoManager        = hopeWalletInfoManager;
            this.dynamicDataCache             = dynamicDataCache;
            this.settingsPopupAnimator        = settingsPopupAnimator;
            this.newPasswordField             = newPasswordField;
            this.confirmPasswordField         = confirmPasswordField;
            this.saveButton  = saveButton;
            this.loadingIcon = loadingIcon;

            walletEncryptor = new WalletEncryptor(playerPrefPasswordDerivation, dynamicDataCache);
            walletDecryptor = new WalletDecryptor(playerPrefPasswordDerivation, dynamicDataCache);
            walletInfo      = hopeWalletInfoManager.GetWalletInfo(userWalletManager.GetWalletAddress());

            newPasswordField.OnInputUpdated     += _ => PasswordsUpdated();
            confirmPasswordField.OnInputUpdated += _ => PasswordsUpdated();
            saveButton.onClick.AddListener(SavePasswordButtonClicked);
        }
コード例 #8
0
    public void Construct(
        PlayerPrefPasswordDerivation playerPrefPasswordDerivation,
        UserWalletManager userWalletManager,
        HopeWalletInfoManager hopeWalletInfoManager,
        WalletPasswordVerification walletPasswordVerification,
        ContactsManager contactsManager,
        DynamicDataCache dynamicDataCache,
        ButtonClickObserver buttonClickObserver,
        CurrencyManager currencyManager,
        LogoutHandler logoutHandler)
    {
        this.playerPrefPasswordDerivation = playerPrefPasswordDerivation;
        this.userWalletManager            = userWalletManager;
        this.hopeWalletInfoManager        = hopeWalletInfoManager;
        this.walletPasswordVerification   = walletPasswordVerification;
        this.contactsManager     = contactsManager;
        this.dynamicDataCache    = dynamicDataCache;
        this.buttonClickObserver = buttonClickObserver;
        this.currencyManager     = currencyManager;
        this.logoutHandler       = logoutHandler;

        buttonClickObserver.SubscribeObservable(this);
        defaultCurrencyOptions.ButtonClicked((int)currencyManager.ActiveCurrency);

        walletName = hopeWalletInfoManager.GetWalletInfo(userWalletManager.GetWalletAddress()).WalletName;

        deleteWalletButton.onClick.AddListener(() => popupManager.GetPopup <GeneralOkCancelPopup>(true)
                                               .SetSubText($"Are you sure you want to delete wallet '{walletName}'?\nThis cannot be undone!")
                                               .OnOkClicked(() => DeleteWallet(userWalletManager, hopeWalletInfoManager, logoutHandler))
                                               .DisableEnterButton());
    }
コード例 #9
0
    /// <summary>
    /// Creates an instance of a <see cref="ContractFunction"/> of type <typeparamref name="T"/> to use to send a contract message.
    /// </summary>
    /// <typeparam name="T"> The concrete type of <see cref="ContractFunction"/>. </typeparam>
    /// <param name="userWalletManager"> The active <see cref="UserWalletManager"/> instance. </param>
    /// <param name="gasPrice"> The <see cref="HexBigInteger"/> gas price to use with the transaction when the function is executed. </param>
    /// <param name="gasLimit"> The <see cref="HexBigInteger"/> gas limit to use with the transaction when the function is executed. </param>
    /// <param name="functionInput"> The input parameters to pass through the function. </param>
    /// <returns> The newly created instance of <see cref="ContractFunction"/> of type <typeparamref name="T"/>. </returns>
    public static T CreateFunction <T>(UserWalletManager userWalletManager, HexBigInteger gasPrice, HexBigInteger gasLimit, params object[] functionInput) where T : ContractFunction
    {
        T func = CreateFunction <T>(functionInput);

        func.FromAddress = userWalletManager.GetWalletAddress();
        func.GasPrice    = gasPrice.Value;
        func.Gas         = gasLimit.Value;

        return(func);
    }
コード例 #10
0
    private void DeleteWallet(UserWalletManager userWalletManager, HopeWalletInfoManager hopeWalletInfoManager, LogoutHandler logoutHandler)
    {
        var wallets        = hopeWalletInfoManager.Wallets;
        var walletToDelete = hopeWalletInfoManager.GetWalletInfo(userWalletManager.GetWalletAddress());

        for (int i = wallets.IndexOf(walletToDelete) + 1; i < wallets.Count; i++)
        {
            hopeWalletInfoManager.UpdateWalletInfo(wallets[i].WalletNum, new WalletInfo(wallets[i].EncryptedWalletData, wallets[i].WalletName, wallets[i].WalletAddresses, wallets[i].WalletNum - 1));
        }

        hopeWalletInfoManager.DeleteWalletInfo(walletToDelete);
        logoutHandler.Logout();
    }
コード例 #11
0
    /// <summary>
    /// Updates this asset balance belonging in the user's wallet.
    /// </summary>
    public void UpdateBalance()
    {
        GetBalance(userWalletManager.GetWalletAddress(), balance =>
        {
            bool changed = balance != AssetBalance;

            AssetBalance = balance;

            if (changed)
            {
                OnAssetBalanceChanged?.Invoke(AssetBalance);
            }
        });
    }
コード例 #12
0
ファイル: EtherAsset.cs プロジェクト: HopeWallet/Hope-Desktop
 /// <summary>
 /// Transfers a specified amount of ether from the input UserWallet to a specified address.
 /// </summary>
 /// <param name="userWalletManager"> The wallet to send the ether from. </param>
 /// <param name="gasLimit"> The gas limit to use for this ether send transaction. </param>
 /// <param name="gasPrice"> The gas price to use for this ether send transaction. </param>
 /// <param name="address"> The address to send the ether to. </param>
 /// <param name="amount"> The amount of ether to send. </param>
 public override void Transfer(UserWalletManager userWalletManager, HexBigInteger gasLimit, HexBigInteger gasPrice, string address, decimal amount)
 {
     userWalletManager.SignTransaction <ConfirmTransactionPopup>(
         request => EthUtils.SendEther(request, gasLimit, gasPrice, userWalletManager.GetWalletAddress(), address, amount),
         gasLimit,
         gasPrice,
         SolidityUtils.ConvertToUInt(amount, 18),
         address,
         "",
         address,
         AssetAddress,
         amount,
         "ETH");
 }
コード例 #13
0
    public void Construct(
        TradableAssetManager tradableAssetManager,
        TradableAssetImageManager tradableAssetImageManager,
        ContactsManager contactsManager,
        UserWalletManager userWalletManager,
        HopeWalletInfoManager userWalletInfoManager,
        Hodler hodler)
    {
        this.tradableAssetManager      = tradableAssetManager;
        this.tradableAssetImageManager = tradableAssetImageManager;
        this.contactsManager           = contactsManager;
        this.hodler = hodler;

        walletAddress = userWalletManager.GetWalletAddress();
        walletName    = userWalletManager.ActiveWalletType == UserWalletManager.WalletType.Hope ? userWalletInfoManager.GetWalletInfo(walletAddress).WalletName : userWalletManager.ActiveWalletType.ToString();
    }
コード例 #14
0
    public void Construct(
        HopeWalletInfoManager hopeWalletInfoManager,
        UserWalletManager userWalletManager,
        WalletPasswordVerification walletPasswordVerification,
        LogoutHandler logoutHandler,
        DynamicDataCache dynamicDataCache,
        ButtonClickObserver buttonClickObserver)
    {
        this.walletPasswordVerification = walletPasswordVerification;
        this.logoutHandler       = logoutHandler;
        this.dynamicDataCache    = dynamicDataCache;
        this.buttonClickObserver = buttonClickObserver;

        walletName     = hopeWalletInfoManager.GetWalletInfo(userWalletManager.GetWalletAddress()).WalletName;
        formTitle.text = walletName;

        SetMessageText();

        (dynamicDataCache.GetData("pass") as ProtectedString)?.SetValue(RandomBytes.Secure.SHA3.GetBytes(16));
    }
コード例 #15
0
    /// <summary>
    /// Creates a TransactionInfo object from a token transaction json object.
    /// </summary>
    /// <param name="tokenTransaction"> The token json to convert. </param>
    /// <param name="userWalletManager"> The active UserWalletManager. </param>
    /// <returns> The TransactionInfo created from the json. </returns>
    public static TransactionInfo CreateTokenTransaction(TokenTransactionJson tokenTransaction, UserWalletManager userWalletManager)
    {
        var topics        = tokenTransaction.topics;
        var tokenSender   = topics[1].Remove(2, 24);
        var tokenReceiver = topics[2].Remove(2, 24);

        if (tokenSender == tokenReceiver)
        {
            return(null);
        }

        return(new TransactionInfo(GetTransactionType(tokenSender.EqualsIgnoreCase(userWalletManager.GetWalletAddress())),
                                   tokenSender,
                                   tokenReceiver,
                                   tokenTransaction.address,
                                   tokenTransaction.transactionHash,
                                   tokenTransaction.data.ConvertFromHex(),
                                   tokenTransaction.gasPrice.ConvertFromHex(),
                                   (int)tokenTransaction.gasUsed.ConvertFromHex(),
                                   (long)tokenTransaction.timeStamp.ConvertFromHex()));
    }
コード例 #16
0
    /// <summary>
    /// Adds contact under the newly created wallet name and address
    /// </summary>
    /// <param name="userWalletManager"> The active UserWalletManager </param>
    /// <param name="userWalletInfoManager"> The active UserWalletInfoManager </param>
    /// <param name="settings"> The settings for the ContactsManager. </param>
    /// <param name="networkSettings"> The settings for the EthereumNetworkManager. </param>
    public ContactsManager(
        UserWalletManager userWalletManager,
        HopeWalletInfoManager userWalletInfoManager,
        EthereumNetworkManager.Settings networkSettings)
    {
        UserWalletManager.OnWalletLoadSuccessful += () =>
        {
            ContactList = new SecurePlayerPrefList <ContactInfo>(PlayerPrefConstants.CONTACT_LIST, (int)networkSettings.networkType);

            var walletAddress = userWalletManager.GetWalletAddress();

            if (!ContactList.Contains(walletAddress.ToLower()))
            {
                var info = userWalletInfoManager.GetWalletInfo(walletAddress);

                if (!string.IsNullOrEmpty(info?.WalletName))
                {
                    AddContact(walletAddress.ToLower(), info.WalletName);
                }
            }
        };
    }
コード例 #17
0
 /// <summary>
 /// Searches for any token transfers from the user's address to the hodl contract.
 /// </summary>
 private void StartNewItemSearch()
 {
     apiService.SendTokenTransfersFromAndToAddressRequest(userWalletManager.GetWalletAddress(), hodlerContract.ContractAddress, prpsContract.ContractAddress)
     .OnSuccess(ProcessTxList);
 }
コード例 #18
0
 /// <summary>
 /// Updates the dubi and purpose balances.
 /// </summary>
 public void PeriodicUpdate()
 {
     GetDUBIBalance(dubiContract.ContractAddress, userWalletManager.GetWalletAddress());
     GetPRPSBalance(prpsContract.ContractAddress, userWalletManager.GetWalletAddress());
 }
コード例 #19
0
    /// <summary>
    /// Creates a TransactionInfo object from an ethereum transaction json object.
    /// </summary>
    /// <param name="transaction"> The ethereum transaction json to convert. </param>
    /// <param name="userWalletManager"> The active UserWalletManager. </param>
    /// <returns> The TransactionInfo created from the json. </returns>
    public static TransactionInfo CreateEtherTransaction(EtherTransactionJson transaction, UserWalletManager userWalletManager)
    {
        var value = BigInteger.Parse(transaction.value);

        if (transaction.from == transaction.to || value == 0)
        {
            return(null);
        }

        return(new TransactionInfo(GetTransactionType(transaction.from.EqualsIgnoreCase(userWalletManager.GetWalletAddress())),
                                   transaction.from,
                                   transaction.to,
                                   EtherAsset.ETHER_ADDRESS,
                                   transaction.hash,
                                   value,
                                   string.IsNullOrEmpty(transaction.gasPrice) ? new BigInteger(0) : BigInteger.Parse(transaction.gasPrice),
                                   transaction.gasUsed,
                                   transaction.timeStamp));
    }
コード例 #20
0
    protected override void OnValueUpdated(TokenInfo info)
    {
        if (info.Address.EqualsIgnoreCase(previousTokenInfo?.Address))
        {
            return;
        }

        previousTokenInfo     = info;
        tokenBalanceText.text = "-";
        tokenDisplayText.text = info.Name.LimitEnd(55, "...") + " (" + info.Symbol + ")";
        tradableAssetImageManager.LoadImage(info.Symbol, icon => tokenIcon.sprite = icon);

        SimpleContractQueries.QueryUInt256Output <ERC20.Queries.BalanceOf>(info.Address, userWalletManager.GetWalletAddress(), userWalletManager.GetWalletAddress())
        .OnSuccess(balance => tokenBalanceText.text = $"{balance.Value}".LimitEnd(5, "..."));
    }
コード例 #21
0
 /// <summary>
 /// Updates the wallet name text.
 /// </summary>
 private void UpdateWalletName()
 {
     walletNameText.text = userWalletManager.ActiveWalletType == UserWalletManager.WalletType.Hope
         ? hopeWalletInfoManager.GetWalletInfo(userWalletManager.GetWalletAddress()).WalletName
         : userWalletManager.ActiveWalletType.ToString();
 }