# Path: multiexplorer/wallet/models.py
# class WalletMasterKeys(models.Model):
#     """
#     Stores the BIP32 HD master seed for the user's wallet.
#     The seed is stored encrypted with the user's password.
#     """
#     user = models.ForeignKey('auth.User', on_delete=models.CASCADE)
#     encrypted_mnemonic = models.CharField(max_length=172)
# 
#     auto_logout = models.IntegerField(choices=AUTO_LOGOUT_CHOICES, default=0)
#     display_fiat = models.CharField(max_length=5, default='usd')
#     show_wallet_list = models.TextField(default='btc,ltc,doge,dash') # comma seperated
# 
#     def __unicode__(self):
#         return self.user.username
# 
#     def get_show_wallet_list(self):
#         return self.show_wallet_list.split(",")
# 
#     def get_settings(self):
#         if self.display_fiat in ['cad', 'usd']:
#             symbol = '$'
#         elif self.display_fiat == 'eur':
#             symbol = '€'
#         elif self.display_fiat == 'gbp':
#             symbol = '£'
#         elif self.display_fiat in ['jpy', 'cny']:
#             symbol = '¥'
#         elif self.display_fiat == 'idr':
#             symbol = "Rp"
#         else:
#             symbol = ''
# 
#         return {
#             'show_wallet_list': self.get_show_wallet_list(),
#             'display_fiat_unit': self.display_fiat,
#             'display_fiat_symbol': symbol,
#             'auto_logout': self.auto_logout
#         }
# 
# class FailedLogin(models.Model):
#     username = models.CharField(max_length=64, db_index=True)
#     time = models.DateTimeField(default=datetime.datetime.now)
# 
#     class Meta:
#         get_latest_by = 'time'
# 
# AUTO_LOGOUT_CHOICES = (
#     (5, "5 minutes of inactivity"),
#     (30, "30 minutes of inactivity"),
#     (0, "Never"),
# )


import datetime
import json
from django.views.decorators.csrf import ensure_csrf_cookie, csrf_exempt
from django.contrib.auth import authenticate, login as init_login
from django.contrib.auth.models import User
from django.conf import settings
from django.utils import timezone
from django.template.response import TemplateResponse
from django import http
from .models import WalletMasterKeys, FailedLogin, AUTO_LOGOUT_CHOICES
from pricetick.models import PriceTick
from multiexplorer.utils import get_wallet_currencies
from moneywagon.core import NoService
from multiexplorer.views import _cached_fetch
                source_name=response['service_name'],
                price=response['current_price'],
            )
            rates[data['code']] = {
                'rate': response['current_price'],
                'provider': response['service_name']
            }
        except NoService as exc:
            rates[data['code']] = {
                'error': str(exc),
            }
    return rates

def home(request):
    return TemplateResponse(request, "wallet_home.html", {
        'crypto_data_json': crypto_data_json,
        'crypto_data': crypto_data,
        'supported_fiats': settings.WALLET_SUPPORTED_FIATS,
        'autologout_choices': AUTO_LOGOUT_CHOICES,
        'use_inverted_colors': ['vtc', 'uno', 'fjc', 'leo'], # makes spinner white
    })


@csrf_exempt
def save_settings(request):
    wallet = WalletMasterKeys.objects.get(user=request.user)
    new_fiat = request.POST['display_fiat']
    previous_fiat = wallet.display_fiat
    previous_show_wallet_list = wallet.show_wallet_list
    wallet.display_fiat = new_fiat

# Path: multiexplorer/wallet/models.py
# class WalletMasterKeys(models.Model):
#     """
#     Stores the BIP32 HD master seed for the user's wallet.
#     The seed is stored encrypted with the user's password.
#     """
#     user = models.ForeignKey('auth.User', on_delete=models.CASCADE)
#     encrypted_mnemonic = models.CharField(max_length=172)
# 
#     auto_logout = models.IntegerField(choices=AUTO_LOGOUT_CHOICES, default=0)
#     display_fiat = models.CharField(max_length=5, default='usd')
#     show_wallet_list = models.TextField(default='btc,ltc,doge,dash') # comma seperated
# 
#     def __unicode__(self):
#         return self.user.username
# 
#     def get_show_wallet_list(self):
#         return self.show_wallet_list.split(",")
# 
#     def get_settings(self):
#         if self.display_fiat in ['cad', 'usd']:
#             symbol = '$'
#         elif self.display_fiat == 'eur':
#             symbol = '€'
#         elif self.display_fiat == 'gbp':
#             symbol = '£'
#         elif self.display_fiat in ['jpy', 'cny']:
#             symbol = '¥'
#         elif self.display_fiat == 'idr':
#             symbol = "Rp"
#         else:
#             symbol = ''
# 
#         return {
#             'show_wallet_list': self.get_show_wallet_list(),
#             'display_fiat_unit': self.display_fiat,
#             'display_fiat_symbol': symbol,
#             'auto_logout': self.auto_logout
#         }
# 
# class FailedLogin(models.Model):
#     username = models.CharField(max_length=64, db_index=True)
#     time = models.DateTimeField(default=datetime.datetime.now)
# 
#     class Meta:
#         get_latest_by = 'time'
# 
# AUTO_LOGOUT_CHOICES = (
#     (5, "5 minutes of inactivity"),
#     (30, "30 minutes of inactivity"),
#     (0, "Never"),
# )


# Path: multiexplorer/wallet/views.py
import datetime
import json
from django.views.decorators.csrf import ensure_csrf_cookie, csrf_exempt
from django.contrib.auth import authenticate, login as init_login
from django.contrib.auth.models import User
from django.conf import settings
from django.utils import timezone
from django.template.response import TemplateResponse
from django import http
from .models import WalletMasterKeys, FailedLogin, AUTO_LOGOUT_CHOICES
from pricetick.models import PriceTick
from multiexplorer.utils import get_wallet_currencies
from moneywagon.core import NoService
from multiexplorer.views import _cached_fetch

                source_name=response['service_name'],
                price=response['current_price'],
            )
            rates[data['code']] = {
                'rate': response['current_price'],
                'provider': response['service_name']
            }
        except NoService as exc:
            rates[data['code']] = {
                'error': str(exc),
            }
    return rates

def home(request):
    return TemplateResponse(request, "wallet_home.html", {
        'crypto_data_json': crypto_data_json,
        'crypto_data': crypto_data,
        'supported_fiats': settings.WALLET_SUPPORTED_FIATS,
        'autologout_choices': AUTO_LOGOUT_CHOICES,
        'use_inverted_colors': ['vtc', 'uno', 'fjc', 'leo'], # makes spinner white
    })


@csrf_exempt
def save_settings(request):
    wallet = WalletMasterKeys.objects.get(user=request.user)
    new_fiat = request.POST['display_fiat']
    previous_fiat = wallet.display_fiat
    previous_show_wallet_list = wallet.show_wallet_list
    wallet.display_fiat = new_fiat

    wallet.auto_logout = request.POST['auto_logout']