I’m experimenting with UI development a bit more, and have made pretty good progress using the awesome RAD scaffolding tools.
Something I’m a bit confused about is how to handle different data types, and how to correctly call Holochain functions from values obtained in the UI. The example I currently have is as follows:
I have a list of all current users in my UI. The data from my ‘list_users’ function returns:
nickname: string
playerId: Uint8array
My console output shows the playerId value as base64: Profile { player_id: AgentPubKey(uhCAklmrhG4uKAWJsJI64rqOTBj47L1fDbRuqsM82BbcwQ6WFDqbY), nickname: "alex" }
In my UI I want to select a player to issue a cap grant to. This selection will either give me a JSON object or a string.
Now I need to pass this value in to my ‘create_capgrant’ function:
But this is giving me errors and I think it’s about the way that the UI is sending back a valid AgentPubKey for the function to use.
So - in the UI I can see all AgentPubKey’s as Uint8Arrays. I have tried to convert these to Base 64 before sending back, but the resulting value is quite long and doesn’t look similar to what I see in the console.
What is the correct way for me to send AgentPubKey back to the create_capgrant function?
Thanks for asking this question! I’m actually trying to do something very similar at the moment,. Passing a header hash to the UI, then back to the DNA, but can’t get the DNA to recognize it as a header hash when it comes back…
yeah, same issue!
I have a feeling it’s something to do with base64 vs not-base64. I recall there were some changes in approach to this (?) over the last few versions of holochain.
This worked, but it’s the other direction that’s my actual problem (ui to dna), and this library did not seem to help me there.
I tried another approach: pass a base64 string to the client and pass the same string back to the DNA and manually convert it to a header hash. For this I used holo_hash, something like this example:
Btw…
this will solve things when dealing with HeaderHash, AgentPubKey, EntryHash, etc, in your own Zome/DNA/happ codebase, but won’t solve for you if you have to convert back to a Buffer/Uint8Array and call non-zome AppWebsocket (appInfo) or AdminWebsocket calls… those will all expect Buffer/Uint8Array style hash encodings… so…
to read deeper into how those conversions can work, here’s a couple pointers…
it turns out this issue was ‘related’ to the very dumb mistake I made in another thread. The cause was very stupid but, because I didn’t think I could make such a stupid mistake, I went down a rabbit hole thinking it was about all these other things. Phew.
Once I’d sorted my profile management out, it turns out I can just pass the UInt8Array straight back to holochain from the UI and it works fine.
on the plus side, your issue is fixed and I learnt A LOT more about holochain data types