forked from jfbeats/ArweaveWalletConnector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWalletSelector.vue
85 lines (73 loc) · 1.99 KB
/
WalletSelector.vue
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<template>
<div class="url-input">
<input class="url" v-model="model" :placeholder="wallet.url" @keydown.enter="connect" />
<div class="actions">
<transition name="fade">
<Button v-if="wallet.address" class="action" :icon="popupIcon" @click="togglePopup" :class="{ dim: !wallet.keepPopup }" />
</transition>
<Button class="action" :icon="connectionIcon" @click="wallet.address ? disconnect() : connect()" :class="{ dim: data.loading }" />
</div>
</div>
</template>
<script setup lang="ts">
import { wallet } from '../ReactiveWallet'
import { reactive, computed } from "vue";
import Button from './WalletSelectorIcons.vue';
const props = defineProps(['modelValue', 'icon', 'placeholder', 'actions', 'autocomplete', 'mask', 'disabled', 'id'])
const emit = defineEmits(['update:modelValue'])
const model = computed<string>({ // url should be persisted to storage to remember last selected wallet
get () { return props.modelValue },
set (value) { emit('update:modelValue', value) }
})
const data = reactive({
loading: false,
})
const connect = () => {
wallet.setUrl(model.value || wallet.url)
wallet.connect()
data.loading = true
wallet.once('change', () => data.loading = false)
}
const disconnect = () => wallet.disconnect()
const togglePopup = () => wallet.keepPopup = !wallet.keepPopup
const popupIcon = computed(() => wallet.keepPopup ? 'close' : 'launch')
const connectionIcon = computed(() => wallet.address ? 'unplug' : 'plug')
</script>
<style scoped>
.url-input {
background: #161616;
border: 0.5px solid #333;
display: flex;
align-items: stretch;
border-radius: 8px;
width: 100%;
min-width: 0;
max-width: 800px;
--spacing: 2em;
}
.url {
padding: var(--spacing);
padding-right: 0;
flex: 1 1 0;
min-width: 0;
outline: none;
}
.actions {
display: flex;
}
.actions:last-child {
padding-right: calc(var(--spacing) / 2);
}
.action.dim {
opacity: 0.2;
}
input {
flex: 1 1 0;
color: inherit;
background: none;
border: none;
margin: 0;
padding: 0;
font-size: 1em;
}
</style>