File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import { getOrFail as get } from '@kodadot1/metasquid/entity'
22import { CollectionEntity , NFTEntity } from '../../model'
33import { unwrap } from '../utils/extract'
44import { Context , isNFT } from '../utils/types'
5- import { addressOf , unHex } from '../utils/helper'
5+ import { addressOf , isAddress , unHex } from '../utils/helper'
66import { getAttributeEvent } from './getters'
77import { attributeFrom , tokenIdOf } from './types'
88
@@ -37,8 +37,11 @@ export async function handleAttributeSet(context: Context): Promise<void> {
3737 try {
3838 final . recipient = final . recipient || addressOf ( event . value as string )
3939 } catch ( error ) {
40- console . log ( error )
41- final . recipient = '' // final.recipient ?? (event.value as string)
40+ const human = unHex ( event . value )
41+ final . recipient = isAddress ( human ) ? human : ''
42+ if ( final . recipient === '' ) {
43+ console . log ( error )
44+ }
4245 }
4346 }
4447
Original file line number Diff line number Diff line change @@ -51,6 +51,19 @@ export function addressOf(address: Uint8Array | string): string {
5151 return ss58 . codec ( codec ) . encode ( value )
5252}
5353
54+ export function isAddress ( value : Optional < string > ) : value is string {
55+ if ( ! value ) {
56+ return false
57+ }
58+
59+ try {
60+ ss58 . decode ( value )
61+ return true
62+ } catch {
63+ return false
64+ }
65+ }
66+
5467/**
5568 * Decode a hex value
5669 * @param value - the value to decode
You can’t perform that action at this time.
0 commit comments