merigo-labs / solana-wallet-adapter

MIT License
6 stars 1 forks source link

Desktop implementations must call setProvider() first #7

Open MarianoAkaMery opened 1 year ago

MarianoAkaMery commented 1 year ago

I'm trying to do a simple auth with solana wallet (phantom), reading all the docs I manage to add it correctly to my code, but when I click on the textbutton the code return:

Desktop implementations must call setProvider() first.

MarianoAkaMery commented 1 year ago

FutureBuilder( // 2. Initialize SolanaWalletProvider before use. future: SolanaWalletProvider .initialize(), builder: ((context, snapshot) { if (snapshot.connectionState != ConnectionState.done) { return const CircularProgressIndicator(); } // 3. Access SolanaWalletProvider. final provider = SolanaWalletProvider.of( context); return _textButton('Connect', enabled: !provider .adapter.isAuthorized, onPressed: () async { if (!provider .adapter.isAuthorized) { await provider .connect(context); setState(() {}); } }); })), ),``

merigo-labs commented 1 year ago

Hi @MarianoAkaMery,

The library has been updated, can you please try again with version solana_wallet_provider: ^0.1.5.

Thanks!

MarianoAkaMery commented 1 year ago
FutureBuilder(
                                        // 2. Initialize SolanaWalletProvider before use.
                                        future: SolanaWalletProvider
                                            .initialize(),
                                        builder: ((context, snapshot) {
                                          if (snapshot.connectionState !=
                                              ConnectionState.done) {
                                            return const CircularProgressIndicator();
                                          }
                                          // 3. Access SolanaWalletProvider.

                                          final provider =
                                              SolanaWalletProvider.of(
                                                  context);

                                          return _textButton(
                                            'Connect',
                                            enabled: !provider
                                                .adapter.isAuthorized,
                                            onPressed: () async {
                                              if (!provider
                                                  .adapter.isAuthorized) {
                                                try {
                                                  await provider
                                                      .connect(context);
                                                  setState(() {});
                                                } catch (e) {
                                                  print(e);
                                                }
                                              }
                                            },
                                          );
                                        }),
                                      ),

Failed to find an instance of [SolanaWalletProvider] in the widget tree. image I'm getting this screen running in localhost since I don't have Phantom installed and the same happens when I try with Solflare since I don't have it, is it possible to handle this error in order to not get this big pop-up and just a notification or a simple print (that I can handle)?

Also is it possible to get the documentation of the library, I'm seeing lot of differents one, would be amazing if you can share me the official one so I can see all the method I can use <3

MarianoAkaMery commented 1 year ago

Hi @MarianoAkaMery,

The library has been updated, can you please try again with version solana_wallet_provider: ^0.1.5.

Thanks!

Thanks to this I can now connect the wallet!

merigo-labs commented 1 year ago

Hi @MarianoAkaMery,

The error can be resolved by placing SolanaWalletProvider at the very top of the tree, for example:

return SolanaWalletProvider.create(
    identity: AppIdentity(),
    child: MaterialApp(
        title: 'Test App',
        home: TestPage(),
    ),
);

Here's a link to the available methods on the provider: https://github.com/merigo-labs/solana-wallet-provider#api

merigo-labs commented 1 year ago

The provider also has a connection property which maps to the HTTP and Websocket methods of JSON RPC API and an adapter property which maps to the Non-Privileged and Privileged methods of Mobile Wallet Adapter Specification.

MarianoAkaMery commented 1 year ago

Thanks a lot, I'm now trying to understand how to get the wallet of the account that made the connection, and how to handle when a user is already connected to website

merigo-labs commented 1 year ago

Hi @MarianoAkaMery,

The following properties found on the provider instance should help with this:

MarianoAkaMery commented 1 year ago

Managed to do everything, I'm now stuck here since I would like to automatically close this pop-up in order to use a setState after the login, but I have to manually remove the popup in order to let the setstate go through. image

MarianoAkaMery commented 1 year ago

                                                  try {
                                                    WidgetsFlutterBinding
                                                        .ensureInitialized();

                                                    await provider
                                                        .connect(context);

                                                    setState(() {
                                                      final jsonResult =
                                                          provider.adapter
                                                              .authorizeResult
                                                              ?.toJson();

                                                      String address =
                                                          jsonResult?[
                                                                  'accounts'][0]
                                                              ['address'];
                                                      main.user.solanaAddress =
                                                          address;

                                                      main.user.issolanaauth =
                                                          true;
                                                      print('fatto');
                                                    });
                                                  } catch (e) {
                                                    print(e);
                                                  }
                                                },```
merigo-labs commented 1 year ago

Hi @MarianoAkaMery,

You can now do this by passing the dismissState property to connect.

await provider.connect(context, dismissState: DismissState.success);

You'll need to use the updated library version solana_wallet_provider: #^0.1.6

MarianoAkaMery commented 1 year ago

Ok, i'm trying to figure this out in order to make the best login I can do, I'm also testing on IOS and looks like connecting with Phantom app is not working, also do you have any plans for adding more wallets?

I'm working for a big app in the web3 that will help lot of projects, shot me a dm on Discord, I think you might be interested.

DISCORD: meryakamariano

merigo-labs commented 1 year ago

Hi @MarianoAkaMery,

The Mobile Wallet Adapter Specification does not support iOS at the moment (link).

What are the wallets you would like to support? I can look at adding them for you.

MarianoAkaMery commented 12 months ago

Hi @MarianoAkaMery,

The Mobile Wallet Adapter Specification does not support iOS at the moment (link).

What are the wallets you would like to support? I can look at adding them for you.

Ehy sir I'm back to you since I finished my web app and now the last step is the solana part, I want to know if it's possible to retrieve, user wallet address, user balance, what NFT he owns and what tokens too. Thanks sir