Skip to content

Commit

Permalink
🚸 Add copy button
Browse files Browse the repository at this point in the history
  • Loading branch information
williamchong committed Nov 20, 2024
1 parent df3be96 commit 2acd5b0
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 8 deletions.
12 changes: 6 additions & 6 deletions app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
<label>Cosmos:</label>
</td>
<td>
<code>{{ convertedCosmosAddress }}</code>
<CopyableField :value="convertedCosmosAddress" />
</td>
</tr>
<tr>
<td>
<label>EVM/Ethereum:</label>
</td>
<td>
<p><code>{{ convertedEvmAddress }}</code></p>
<CopyableField :value="convertedEvmAddress" />
</td>
</tr>
<tr>
Expand All @@ -41,7 +41,7 @@
<input v-model="newPrefix" placeholder="osmos">
</td>
<td>
<code>{{ convertedPrefixAddress }}</code>
<CopyableField :value="convertedPrefixAddress" />
</td>
</tr>
</tbody>
Expand Down Expand Up @@ -120,17 +120,17 @@ const isInputValid = computed(() => {
})
const convertedPrefixAddress = computed(() => {
if (!newPrefix.value || convertedWords.value.length === 0) return '-';
if (!newPrefix.value || convertedWords.value.length === 0) return '';
return bech32.encode(newPrefix.value, convertedWords.value)
})
const convertedCosmosAddress = computed(() => {
if (convertedWords.value.length === 0) return '-'
if (convertedWords.value.length === 0) return ''
return bech32.encode('cosmos', convertedWords.value)
})
const convertedEvmAddress = computed(() => {
if (convertedWords.value.length === 0) return '-'
if (convertedWords.value.length === 0) return ''
const data = bech32.fromWords(convertedWords.value)
const address = Buffer.from(data).toString('hex');
const hash = window.keccak256(address).toString('hex');
Expand Down
23 changes: 23 additions & 0 deletions components/copyableField.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<template>
<div>
<code>
{{ value || '-' }}
</code>
<button v-if="value && isSupported" @click="onClickCopy">
<span v-if="!copied">Copy</span>
<span v-else>Copied!</span>
</button>
</div>
</template>

<script setup lang="ts">
const props = defineProps<{
value: string
}>()
const { copy, copied, isSupported } = useClipboard({ source: props.value })
function onClickCopy() {
copy(props.value)
}
</script>
5 changes: 4 additions & 1 deletion nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export default defineNuxtConfig({
],
},
},
modules: ['nuxt-gtag'],
modules: [
'nuxt-gtag',
'@vueuse/nuxt',
],
gtag: {
id: "G-J481P5HG5T",
},
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"postinstall": "nuxt prepare"
},
"dependencies": {
"@vueuse/core": "^11.2.0",
"@vueuse/nuxt": "^11.2.0",
"bech32": "^2.0.0",
"nuxt": "^3.12.3",
"nuxt-gtag": "^3.0.1",
Expand Down
95 changes: 94 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,32 @@
unimport "^3.13.1"
untyped "^1.5.1"

"@nuxt/kit@^3.13.2":
version "3.14.1592"
resolved "https://registry.yarnpkg.com/@nuxt/kit/-/kit-3.14.1592.tgz#f959a269424c1ee313585a46112e474b6ccab3bc"
integrity sha512-r9r8bISBBisvfcNgNL3dSIQHSBe0v5YkX5zwNblIC2T0CIEgxEVoM5rq9O5wqgb5OEydsHTtT2hL57vdv6VT2w==
dependencies:
"@nuxt/schema" "3.14.1592"
c12 "^2.0.1"
consola "^3.2.3"
defu "^6.1.4"
destr "^2.0.3"
globby "^14.0.2"
hash-sum "^2.0.0"
ignore "^6.0.2"
jiti "^2.4.0"
klona "^2.0.6"
knitwork "^1.1.0"
mlly "^1.7.3"
pathe "^1.1.2"
pkg-types "^1.2.1"
scule "^1.3.0"
semver "^7.6.3"
ufo "^1.5.4"
unctx "^2.3.1"
unimport "^3.13.2"
untyped "^1.5.1"

"@nuxt/[email protected]", "@nuxt/schema@^3.12.3":
version "3.12.3"
resolved "https://registry.yarnpkg.com/@nuxt/schema/-/schema-3.12.3.tgz#da72479aea11a5136d1d08fe2889a4cac4ad3533"
Expand Down Expand Up @@ -1111,6 +1137,25 @@
unimport "^3.13.1"
untyped "^1.5.1"

"@nuxt/[email protected]":
version "3.14.1592"
resolved "https://registry.yarnpkg.com/@nuxt/schema/-/schema-3.14.1592.tgz#38c5c0af51d0b95e011db6c332f578aac97c8c82"
integrity sha512-A1d/08ueX8stTXNkvGqnr1eEXZgvKn+vj6s7jXhZNWApUSqMgItU4VK28vrrdpKbjIPwq2SwhnGOHUYvN9HwCQ==
dependencies:
c12 "^2.0.1"
compatx "^0.1.8"
consola "^3.2.3"
defu "^6.1.4"
hookable "^5.5.3"
pathe "^1.1.2"
pkg-types "^1.2.1"
scule "^1.3.0"
std-env "^3.8.0"
ufo "^1.5.4"
uncrypto "^0.1.3"
unimport "^3.13.2"
untyped "^1.5.1"

"@nuxt/telemetry@^2.5.4":
version "2.5.4"
resolved "https://registry.yarnpkg.com/@nuxt/telemetry/-/telemetry-2.5.4.tgz#a395be090cef23de14204cd7b4e1a9faf81e1838"
Expand Down Expand Up @@ -1479,6 +1524,11 @@
resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-1.20.2.tgz#97d26e00cd4a0423b4af620abecf3e6f442b7975"
integrity sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==

"@types/web-bluetooth@^0.0.20":
version "0.0.20"
resolved "https://registry.yarnpkg.com/@types/web-bluetooth/-/web-bluetooth-0.0.20.tgz#f066abfcd1cbe66267cdbbf0de010d8a41b41597"
integrity sha512-g9gZnnXVq7gM7v3tJCWV/qw7w+KeOlSHAhgF9RytFyifW6AF61hdT2ucrYhPq9hLs5JIryeupHV3qGk95dH9ow==

"@unhead/[email protected]", "@unhead/dom@^1.9.14":
version "1.9.15"
resolved "https://registry.yarnpkg.com/@unhead/dom/-/dom-1.9.15.tgz#1e1902f8e6897698da8a533706e9b0b6ec14fad7"
Expand Down Expand Up @@ -1727,6 +1777,39 @@
resolved "https://registry.yarnpkg.com/@vue/shared/-/shared-3.4.31.tgz#af9981f57def2c3f080c14bf219314fc0dc808a0"
integrity sha512-Yp3wtJk//8cO4NItOPpi3QkLExAr/aLBGZMmTtW9WpdwBCJpRM6zj9WgWktXAl8IDIozwNMByT45JP3tO3ACWA==

"@vueuse/[email protected]", "@vueuse/core@^11.2.0":
version "11.2.0"
resolved "https://registry.yarnpkg.com/@vueuse/core/-/core-11.2.0.tgz#3fc6c0963051bb154dc4c08061889405e3fc745d"
integrity sha512-JIUwRcOqOWzcdu1dGlfW04kaJhW3EXnnjJJfLTtddJanymTL7lF1C0+dVVZ/siLfc73mWn+cGP1PE1PKPruRSA==
dependencies:
"@types/web-bluetooth" "^0.0.20"
"@vueuse/metadata" "11.2.0"
"@vueuse/shared" "11.2.0"
vue-demi ">=0.14.10"

"@vueuse/[email protected]":
version "11.2.0"
resolved "https://registry.yarnpkg.com/@vueuse/metadata/-/metadata-11.2.0.tgz#fd02cbbc7d08cb4592fceea0486559b89ae38643"
integrity sha512-L0ZmtRmNx+ZW95DmrgD6vn484gSpVeRbgpWevFKXwqqQxW9hnSi2Ppuh2BzMjnbv4aJRiIw8tQatXT9uOB23dQ==

"@vueuse/nuxt@^11.2.0":
version "11.2.0"
resolved "https://registry.yarnpkg.com/@vueuse/nuxt/-/nuxt-11.2.0.tgz#f0d2441004efccf5e80e3e16c196b6aad25966eb"
integrity sha512-4Mp1SXpXy8KRKY7lJqN4AuiMkun9IUVGt02t2SBk1hf/RVe4U6AIR2ukmHws0uYvjIGIhlGNv4o6ayTK/7ELWQ==
dependencies:
"@nuxt/kit" "^3.13.2"
"@vueuse/core" "11.2.0"
"@vueuse/metadata" "11.2.0"
local-pkg "^0.5.0"
vue-demi ">=0.14.10"

"@vueuse/[email protected]":
version "11.2.0"
resolved "https://registry.yarnpkg.com/@vueuse/shared/-/shared-11.2.0.tgz#7fb2f3cade6b6c00ef97e613f187ee9bdcfb9a3a"
integrity sha512-VxFjie0EanOudYSgMErxXfq6fo8vhr5ICI+BuE3I9FnX7ePllEsVrRQ7O6Q1TLgApeLuPKcHQxAXpP+KnlrJsg==
dependencies:
vue-demi ">=0.14.10"

abbrev@1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8"
Expand Down Expand Up @@ -4780,6 +4863,11 @@ std-env@^3.7.0:
resolved "https://registry.yarnpkg.com/std-env/-/std-env-3.7.0.tgz#c9f7386ced6ecf13360b6c6c55b8aaa4ef7481d2"
integrity sha512-JPbdCEQLj1w5GilpiHAx3qJvFndqybBysA3qUOnznweH4QbNYUsW/ea8QzSrnh0vNsezMMw5bcVool8lM0gwzg==

std-env@^3.8.0:
version "3.8.0"
resolved "https://registry.yarnpkg.com/std-env/-/std-env-3.8.0.tgz#b56ffc1baf1a29dcc80a3bdf11d7fca7c315e7d5"
integrity sha512-Bc3YwwCB+OzldMxOXJIIvC6cPRWr/LxOp48CdQTOkPyk/t4JWWJbrilwBd7RJzKV8QW7tJkcgAmeuLLJugl5/w==

streamx@^2.15.0:
version "2.18.0"
resolved "https://registry.yarnpkg.com/streamx/-/streamx-2.18.0.tgz#5bc1a51eb412a667ebfdcd4e6cf6a6fc65721ac7"
Expand Down Expand Up @@ -5064,7 +5152,7 @@ unicorn-magic@^0.1.0:
resolved "https://registry.yarnpkg.com/unicorn-magic/-/unicorn-magic-0.1.0.tgz#1bb9a51c823aaf9d73a8bfcd3d1a23dde94b0ce4"
integrity sha512-lRfVq8fE8gz6QMBuDM6a+LO3IAzTi05H6gCVaUpir2E1Rwpo4ZUog45KpNXKC/Mn3Yb9UDuHumeFTo9iV/D9FQ==

unimport@^3.13.1:
unimport@^3.13.1, unimport@^3.13.2:
version "3.13.2"
resolved "https://registry.yarnpkg.com/unimport/-/unimport-3.13.2.tgz#2a5f7458c66bc65485d62ad28462d38832aee0ba"
integrity sha512-VKAepeIb6BWLtBl4tmyHY1/7rJgz3ynmZrWf8cU1a+v5Uv/k1gyyAEeGBnYcrwy8bxG5sflxEx4a9VQUqOVHUA==
Expand Down Expand Up @@ -5366,6 +5454,11 @@ vue-bundle-renderer@^2.1.0:
dependencies:
ufo "^1.5.3"

vue-demi@>=0.14.10:
version "0.14.10"
resolved "https://registry.yarnpkg.com/vue-demi/-/vue-demi-0.14.10.tgz#afc78de3d6f9e11bf78c55e8510ee12814522f04"
integrity sha512-nMZBOwuzabUO0nLgIcc6rycZEebF6eeUfaiQx9+WSk8e29IbLvPU9feI6tqW4kTo3hvoYAJkMh8n8D0fuISphg==

vue-devtools-stub@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/vue-devtools-stub/-/vue-devtools-stub-0.1.0.tgz#a65b9485edecd4273cedcb8102c739b83add2c81"
Expand Down

0 comments on commit 2acd5b0

Please sign in to comment.