예제 #1
0
        public async Task <IActionResult> ListWallets()
        {
            if (GetUserId() == null)
            {
                return(Challenge(AuthenticationSchemes.Cookie));
            }
            var wallets = new ListWalletsViewModel();
            var stores  = await Repository.GetStoresByUserId(GetUserId());

            var onChainWallets = stores
                                 .SelectMany(s => s.GetSupportedPaymentMethods(NetworkProvider)
                                             .OfType <DerivationSchemeSettings>()
                                             .Select(d => ((Wallet: _walletProvider.GetWallet(d.Network),
                                                            DerivationStrategy: d.AccountDerivation,
                                                            Network: d.Network)))
                                             .Where(_ => _.Wallet != null && _.Network.WalletSupported)
                                             .Select(_ => (Wallet: _.Wallet,
                                                           Store: s,
                                                           Balance: GetBalanceString(_.Wallet, _.DerivationStrategy),
                                                           DerivationStrategy: _.DerivationStrategy,
                                                           Network: _.Network)))
                                 .ToList();

            foreach (var wallet in onChainWallets)
            {
                ListWalletsViewModel.WalletViewModel walletVm = new ListWalletsViewModel.WalletViewModel();
                wallets.Wallets.Add(walletVm);
                walletVm.Balance = await wallet.Balance + " " + wallet.Wallet.Network.CryptoCode;
                walletVm.IsOwner = wallet.Store.Role == StoreRoles.Owner;
                if (!walletVm.IsOwner)
                {
                    walletVm.Balance = "";
                }
                walletVm.CryptoCode = wallet.Network.CryptoCode;
                walletVm.StoreId    = wallet.Store.Id;
                walletVm.Id         = new WalletId(wallet.Store.Id, wallet.Network.CryptoCode);
                walletVm.StoreName  = wallet.Store.StoreName;
            }

            return(View(wallets));
        }
        public async Task <IActionResult> ListWallets()
        {
            var wallets = new ListWalletsViewModel();
            var stores  = await _Repo.GetStoresByUserId(GetUserId());

            var onChainWallets = stores
                                 .SelectMany(s => s.GetSupportedPaymentMethods(_NetworkProvider)
                                             .OfType <DerivationStrategy>()
                                             .Select(d => ((Wallet: _walletProvider.GetWallet(d.Network),
                                                            DerivationStrategy: d.DerivationStrategyBase,
                                                            Network: d.Network)))
                                             .Where(_ => _.Wallet != null)
                                             .Select(_ => (Wallet: _.Wallet,
                                                           Store: s,
                                                           Balance: GetBalanceString(_.Wallet, _.DerivationStrategy),
                                                           DerivationStrategy: _.DerivationStrategy,
                                                           Network: _.Network)))
                                 .ToList();

            foreach (var wallet in onChainWallets)
            {
                ListWalletsViewModel.WalletViewModel walletVm = new ListWalletsViewModel.WalletViewModel();
                wallets.Wallets.Add(walletVm);
                walletVm.Balance = await wallet.Balance + " " + wallet.Wallet.Network.CryptoCode;
                if (!wallet.Store.HasClaim(Policies.CanModifyStoreSettings.Key))
                {
                    walletVm.Balance = "";
                }
                walletVm.CryptoCode = wallet.Network.CryptoCode;
                walletVm.StoreId    = wallet.Store.Id;
                walletVm.Id         = new WalletId(wallet.Store.Id, wallet.Network.CryptoCode);
                walletVm.StoreName  = wallet.Store.StoreName;
                walletVm.IsOwner    = wallet.Store.HasClaim(Policies.CanModifyStoreSettings.Key);
            }

            return(View(wallets));
        }