-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vue-identicon does not work with vue3 #747
Labels
Bug
Tracks issues causing errors or unintended behavior, critical to fix for reliability.
Comments
And the wrapper component looks like this:
<template>
<component :is="componentToRender" v-bind="{ address, size, isAlternative, key }"></component>
</template>
<script lang="ts">
import { defineComponent, ref, watch, computed, h } from 'vue'
import { isHex, isU8a, u8aToHex } from '@polkadot/util'
import { decodeAddress, encodeAddress } from '@polkadot/util-crypto'
// import { Beachball, Empty, Jdenticon, Polkadot } from './icons/index.js';
import { Beachball, Empty, Jdenticon } from '@polkadot/vue-identicon/icons'
import Polkadot from './Polkadot.vue'
// const DEFAULT_SIZE = 64;
function encodeAccount(value: string, prefix?: number) {
try {
const address = isU8a(value) || isHex(value)
? encodeAddress(value, prefix)
: value;
const publicKey = u8aToHex(decodeAddress(address, false, prefix))
return { address, publicKey }
}
catch {
return { address: '', publicKey: '0x' }
}
}
/**
* @name Identicon
* @description The main Identicon component, taking a number of properties
* @example
* ```html
* <Identicon :size="128" :theme="polkadot" :value="..." />
* ```
*/
export default defineComponent({
components: {
Beachball,
Empty,
Jdenticon,
Polkadot
},
props: ['prefix', 'isAlternative', 'size', 'theme', 'value'],
setup (props) {
const { prefix, isAlternative=false, size=64, theme='empty', value } = props
const address = ref('')
const isAlternativeIcon = ref(props.isAlternative || false)
const publicKey = ref('0x')
const type = ref('empty')
const createData = function () {
type.value = theme
isAlternativeIcon.value = isAlternative || false
recodeAddress()
}
const recodeAddress = function () {
const encoded = encodeAccount(value);
address.value = encoded.address;
publicKey.value = encoded.publicKey;
}
watch(() => value, () => {
recodeAddress()
})
const componentToRender = computed(() => type.value.charAt(0).toUpperCase() + type.value.slice(1))
createData()
return {
address,
isAlternativeIcon,
key: publicKey,
componentToRender
}
}
});
</script>
|
jacogr
added
the
Bug
Tracks issues causing errors or unintended behavior, critical to fix for reliability.
label
Apr 4, 2023
Merged
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
vue-identicon does not render the identicon in a vue3 project.
It should be possble using
composition api
Please tell us about your environment:
Version:
Environment:
Language:
dependencies from package.json
Here is an example:
Polkadot.vue
That produces:
The text was updated successfully, but these errors were encountered: