|
| 1 | +<template> |
| 2 | + <div class="send-address-input" :class="{ focus: isFocus }"> |
| 3 | + <div class="send-address-input__avatar"> |
| 4 | + <img |
| 5 | + v-if=" |
| 6 | + isSparkAddress(btcAddress) || |
| 7 | + isAddress(btcAddress, props.network.networkInfo) |
| 8 | + " |
| 9 | + :src="network.identicon(btcAddress)" |
| 10 | + alt="" |
| 11 | + /> |
| 12 | + </div> |
| 13 | + <div class="send-address-input__address"> |
| 14 | + <p>{{ props.title }}:</p> |
| 15 | + <input |
| 16 | + ref="addressInput" |
| 17 | + v-model="address" |
| 18 | + type="text" |
| 19 | + :disabled="disableDirectInput" |
| 20 | + placeholder="address" |
| 21 | + :style="{ |
| 22 | + color: |
| 23 | + !isSparkAddress(btcAddress) && |
| 24 | + !isAddress(btcAddress, props.network.networkInfo) |
| 25 | + ? 'red' |
| 26 | + : 'black', |
| 27 | + }" |
| 28 | + @focus="changeFocus" |
| 29 | + @blur="changeFocus" |
| 30 | + /> |
| 31 | + </div> |
| 32 | + </div> |
| 33 | +</template> |
| 34 | + |
| 35 | +<script setup lang="ts"> |
| 36 | +import { computed } from "@vue/reactivity"; |
| 37 | +import { PropType, ref } from "vue"; |
| 38 | +import { isAddress, isSparkAddress } from "@/providers/bitcoin/libs/utils"; |
| 39 | +import { BitcoinNetwork } from "@/providers/bitcoin/types/bitcoin-network"; |
| 40 | +
|
| 41 | +const isFocus = ref<boolean>(false); |
| 42 | +const addressInput = ref<HTMLInputElement>(); |
| 43 | +
|
| 44 | +const pasteFromClipboard = () => { |
| 45 | + addressInput.value?.focus(); |
| 46 | + document.execCommand("paste"); |
| 47 | +}; |
| 48 | +defineExpose({ addressInput, pasteFromClipboard }); |
| 49 | +
|
| 50 | +const props = defineProps({ |
| 51 | + value: { |
| 52 | + type: String, |
| 53 | + default: () => { |
| 54 | + return ""; |
| 55 | + }, |
| 56 | + }, |
| 57 | + network: { |
| 58 | + type: Object as PropType<BitcoinNetwork>, |
| 59 | + default: () => ({}), |
| 60 | + }, |
| 61 | + title: { |
| 62 | + type: String, |
| 63 | + default: "To Spark address", |
| 64 | + }, |
| 65 | + disableDirectInput: Boolean, |
| 66 | +}); |
| 67 | +const emit = defineEmits<{ |
| 68 | + (e: "update:inputAddress", address: string): void; |
| 69 | + (e: "toggle:showContacts", show: boolean): void; |
| 70 | +}>(); |
| 71 | +const btcAddress = computed(() => { |
| 72 | + return props.value; |
| 73 | +}); |
| 74 | +const address = computed({ |
| 75 | + get: () => btcAddress.value, |
| 76 | + set: (value) => emit("update:inputAddress", value), |
| 77 | +}); |
| 78 | +
|
| 79 | +const changeFocus = (val: FocusEvent) => { |
| 80 | + isFocus.value = val.type === "focus"; |
| 81 | + if (isFocus.value) emit("toggle:showContacts", isFocus.value); |
| 82 | +}; |
| 83 | +</script> |
| 84 | + |
| 85 | +<style lang="less"> |
| 86 | +@import "~@action/styles/theme.less"; |
| 87 | +
|
| 88 | +.send-address-input { |
| 89 | + height: 64px; |
| 90 | + background: #ffffff; |
| 91 | + margin: 12px 32px 8px 32px; |
| 92 | + box-sizing: border-box; |
| 93 | + border: 1px solid @gray02; |
| 94 | + box-sizing: border-box; |
| 95 | + border-radius: 10px; |
| 96 | + width: calc(~"100% - 64px"); |
| 97 | + padding: 16px; |
| 98 | + display: flex; |
| 99 | + justify-content: flex-start; |
| 100 | + align-items: center; |
| 101 | + flex-direction: row; |
| 102 | + position: relative; |
| 103 | +
|
| 104 | + &.focus { |
| 105 | + border: 2px solid @primary; |
| 106 | + width: calc(~"100% - 62px"); |
| 107 | + margin: 12px 31px 8px 31px; |
| 108 | + } |
| 109 | +
|
| 110 | + &__avatar { |
| 111 | + background: @buttonBg; |
| 112 | + box-shadow: inset 0px 0px 1px rgba(0, 0, 0, 0.16); |
| 113 | + width: 32px; |
| 114 | + height: 32px; |
| 115 | + border-radius: 100%; |
| 116 | + overflow: hidden; |
| 117 | + margin-right: 12px; |
| 118 | +
|
| 119 | + img { |
| 120 | + width: 100%; |
| 121 | + height: 100%; |
| 122 | + } |
| 123 | + } |
| 124 | +
|
| 125 | + &__address { |
| 126 | + p { |
| 127 | + font-style: normal; |
| 128 | + font-weight: 400; |
| 129 | + font-size: 12px; |
| 130 | + line-height: 16px; |
| 131 | + letter-spacing: 0.5px; |
| 132 | + color: @secondaryLabel; |
| 133 | + margin: 0; |
| 134 | + } |
| 135 | +
|
| 136 | + input { |
| 137 | + width: 290px; |
| 138 | + height: 24px; |
| 139 | + font-style: normal; |
| 140 | + font-weight: 400; |
| 141 | + font-size: 16px; |
| 142 | + line-height: 24px; |
| 143 | + letter-spacing: 0.25px; |
| 144 | + color: @primaryLabel; |
| 145 | + border: 0 none; |
| 146 | + outline: none; |
| 147 | + padding: 0; |
| 148 | + } |
| 149 | + } |
| 150 | +
|
| 151 | + &__arrow { |
| 152 | + position: absolute; |
| 153 | + font-size: 0; |
| 154 | + cursor: pointer; |
| 155 | + padding: 4px; |
| 156 | + right: 8px; |
| 157 | + top: 16px; |
| 158 | + } |
| 159 | +} |
| 160 | +</style> |
0 commit comments