aeternity / aepp-sdk-js

JavaScript SDK for the æternity blockchain
http://docs.aeternity.com/aepp-sdk-js/
ISC License
120 stars 59 forks source link

Private element is not present on this object #2012

Closed janmichek closed 1 week ago

janmichek commented 2 weeks ago

Describe the bug For aeScan I built the feature of Contract Write. I needed to downgrade from 13.3.2 to 13.2.2

To Reproduce Steps to reproduce the behavior:

  1. Deploy contract (I used hamster from aestudio examples) to testnet
  2. Verify contract https://aescan.dev.service.aepps.com/contract-verification
  3. after successful verification go to detail -> Write tab
  4. Connect your wallet
  5. Dispatch some Write action

Expected behavior Now It works as expected because I used version 13.2.2. But when you upgrade to 13.3.2 and remove { ignoreVersion: true } You will get that 'Private element is not present on this object'

I am using suggested implementation using shallowReactive from example https://github.com/aeternity/aepp-sdk-js/tree/71da12b5df56b41f7317d1fb064e44e8ea118d6c/examples/browser/aepp

Screenshots

Uploading Screen Recording 2024-08-26 at 14.08.56.mov…

Please tell us about your environment:

Other information

davidyuk commented 2 weeks ago

The issue is because you are making sdk instance reactive. Sdk was working if the instance is not deep reactive (like when using shallowReactive), but I broke it in the recent releases and only shallowRef is working now. Anyway, you don't need to track changes in sdk instance fields, so use shallowRef. I've tried it on "contract-read" branch and it looks working

Screenshot 2024-08-28 at 12 57 32
--- a/src/stores/wallet.js
+++ b/src/stores/wallet.js
@@ -5,7 +5,7 @@ import { AeSdkAepp, BrowserWindowMessageConnection, Node, walletDetector } from
 export const useWalletStore = defineStore('wallet', () => {
   const { NODE_URL, NETWORK_ID } = useRuntimeConfig().public

-  const aeSdk = ref(null)
+  const aeSdk = shallowRef(null)
   const detectedWallets = ref(null)
   const status = ref(null)
   const backLink = ref(null)
@@ -20,7 +20,7 @@ export const useWalletStore = defineStore('wallet', () => {
         compilerUrl: 'https://compiler.aepps.com',
       }

-      aeSdk.value = shallowReactive(new AeSdkAepp({
+      aeSdk.value = new AeSdkAepp({
         name: 'æScan',
         ...aeSdkOptions,
         onNetworkChange({ networkId }) {
@@ -30,7 +30,7 @@ export const useWalletStore = defineStore('wallet', () => {
         onDisconnect() {
           status.value = 'disconnecting'
         },
-      }))
+      })
       await connect()
     } catch (error) {
       status.value = 'failed'
janmichek commented 2 weeks ago

Great, it works good. Thanks for the hint