Spaces:
Running

File size: 2,575 Bytes
1c17489
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
05c6109
1c17489
05c6109
 
 
1c17489
 
05c6109
1c17489
 
 
 
 
05c6109
1c17489
 
 
 
 
 
 
05c6109
1c17489
05c6109
 
 
 
 
 
 
 
1c17489
 
7e3b29c
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { ChevronDown } from 'lucide-react'
import { useState } from 'react'

const ASSETS = [
  { id: 'bitcoin', symbol: 'BTC', name: 'Bitcoin' },
  { id: 'ethereum', symbol: 'ETH', name: 'Ethereum' },
  { id: 'solana', symbol: 'SOL', name: 'Solana' },
]

export default function AssetSelector({ selected, onChange }) {
  const [isOpen, setIsOpen] = useState(false)
  const currentAsset = ASSETS.find(a => a.id === selected) || ASSETS[0]

  return (
    <div className="relative">
      <button
        onClick={() => setIsOpen(!isOpen)}
        className="flex items-center space-x-2 bg-dark-800 hover:bg-dark-700 border border-white/10 px-4 py-2.5 rounded-xl transition-all group shadow-lg shadow-black/20"
      >
        <div className="w-6 h-6 rounded-full bg-dark-900 flex items-center justify-center text-[10px] font-bold text-white border border-white/10">
          {currentAsset.symbol[0]}
        </div>
        <span className="font-bold text-white">{currentAsset.symbol}</span>
        <span className="text-dark-400 text-sm hidden sm:inline">{currentAsset.name}</span>
        <ChevronDown className={`w-4 h-4 text-dark-400 transition-transform ${isOpen ? 'rotate-180' : ''}`} />
      </button>

      {isOpen && (
        <>
          <div className="fixed inset-0 z-10" onClick={() => setIsOpen(false)} />
          <div className="absolute right-0 mt-2 w-48 bg-dark-800 border border-white/10 rounded-xl shadow-2xl z-20 overflow-hidden backdrop-blur-xl">
            {ASSETS.map((asset) => (
              <button
                key={asset.id}
                onClick={() => {
                  onChange(asset.id)
                  setIsOpen(false)

                className="w-full text-left px-4 py-3 hover:bg-white/5 flex items-center justify-between group transition-colors"
              >
                <div className="flex items-center space-x-3">
                  <div className="w-5 h-5 rounded-full bg-dark-900 flex items-center justify-center text-[8px] font-bold text-white border border-white/10">
                    {asset.symbol[0]}
                  </div>
                  <div>
                    <div className="font-medium text-white text-sm">{asset.symbol}</div>
                    <div className="text-[10px] text-dark-400">{asset.name}</div>
                  </div>
                </div>
                {asset.id === selected && (
                  <div className="w-1.5 h-1.5 rounded-full bg-primary-500" />
                )}
              </button>
            ))}
          </div>
        </>
      )}
    </div>
  )
}