GenesysGo / shadow-drive

Apache License 2.0
71 stars 22 forks source link

Upload not working in React component using wallet adapter #87

Closed Woody4618 closed 10 months ago

Woody4618 commented 1 year ago

Hello, i am using wallet adapter with the example from the docs. Creating a new storage account works, I can sign it with phantom wallet but uploadFile throws this error:

image

Do i need to pass in a private key and create a local wallet? That would mean I can not use it in combination with just the wallet adapter?

This is the code: `
const [file, setFile] = useState(undefined) const [uploadUrl, setUploadUrl] = useState(undefined) const [txnSig, setTxnSig] = useState(undefined) const wallet = useAnchorWallet();

const onSubmit = async (event: any) => {

    event.preventDefault()

    const drive = await new ShdwDrive(CONNECTION, wallet as AnchorWallet).init();

    const accounts = await drive.getStorageAccounts("v2");
    const acc = accounts[0].publicKey;
    const getStorageAccount = await drive.getStorageAccount(acc);

    const upload = await drive.uploadFile(acc, file);
    console.log(upload);
    setUploadUrl(upload.finalized_locations)
    setTxnSig(upload.transaction_signature)

}

`

Woody4618 commented 1 year ago

So readin the code it looks like AnchorWallet does not support signMessage in walletAdapterReact 🤔

Woody4618 commented 1 year ago

Ok I fixed it, looks like the docs where outdated. When I just pass in wallet instead of AnchorWallet it works since wallet implements signMessage:
const wallet = useWallet(); const drive = await new ShdwDrive(CONNECTION, wallet).init();

GummersGG commented 1 year ago

Thank you for letting us know. We will make the needed updates in the docs.

tracy-codes commented 1 year ago

@GummersGG please reopen this issue as it may be a bug that requires some attention.

GummersGG commented 1 year ago

Reopen

tracy-codes commented 1 year ago

Ok I fixed it, looks like the docs where outdated. When I just pass in wallet instead of AnchorWallet it works since wallet implements signMessage: const wallet = useWallet(); const drive = await new ShdwDrive(CONNECTION, wallet).init();

@Woody4618 Can you please share a link of the example you were working from that had wallet as AnchorWallet for react? Our web example for react and the readme both don't do this.

Woody4618 commented 1 year ago

Hey, i followed the instructions here: https://docs.genesysgo.com/shadow/shadow-drive/the-sdk It even sais in all caps it needs to be an anchor wallet :D "NOTE: the wallet object WILL need to be an AnchorWallet object in either instance."

tracy-codes commented 1 year ago

Gotcha gotcha, those docs are quite outdated for sure. We're working on a total revamp.

Once we launch our new docs, I'll follow up here and close this issue.

@GummersGG just a quick note that we need to update the code examples for shdw drive as part of the docs revamp.