Skip to content

Commit 038fb28

Browse files
draft flutter document for new release
1 parent 4d48c1e commit 038fb28

1 file changed

Lines changed: 158 additions & 51 deletions

File tree

docs/sdk/pnp/flutter/usage.mdx

Lines changed: 158 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import FlutterResponse from "@site/src/common/sdk/pnp/_userinfo_response.mdx";
1313

1414
### `login(LoginParams)`
1515

16-
Trigger login flow will navigate the user to a browser model allowing the user to login into the service. You can pass in the supported providers to
17-
the login method for specific social logins such as GOOGLE, APPLE, FACEBOOK, etc., and do whitelabel login. The `login` function takes in
16+
Trigger login flow will navigate the user to a browser model allowing the user to login into the
17+
service. You can pass in the supported providers to the login method for specific social logins such
18+
as GOOGLE, APPLE, FACEBOOK, etc., and do whitelabel login. The `login` function takes in
1819
`LoginParams` as a required input.
1920

2021
#### Arguments
@@ -82,12 +83,13 @@ class LoginParams {
8283

8384
### `getPrivkey()`
8485

85-
Use getPrivkey() to get the private key of the user. The method returns an EVM compatible private key which can be used to sign transactions on EVM
86-
compatible chains.
86+
Use getPrivkey() to get the private key of the user. The method returns an EVM compatible private
87+
key which can be used to sign transactions on EVM compatible chains.
8788

8889
### `getEd25519PrivKey()`
8990

90-
Use getEd25519PrivKey() to get the Ed25519 private key of the user. This private key can be used to sign transactions on Solana.
91+
Use getEd25519PrivKey() to get the Ed25519 private key of the user. This private key can be used to
92+
sign transactions on Solana.
9193

9294
### `getUserInfo()`
9395

@@ -344,7 +346,8 @@ final Web3AuthResponse response = await Web3AuthFlutter.login(
344346

345347
## Selecting Curve
346348

347-
The `LoginParams` class has a `curve` parameter. This parameter can be used to select the elliptic curve to use for the signature.
349+
The `LoginParams` class has a `curve` parameter. This parameter can be used to select the elliptic
350+
curve to use for the signature.
348351

349352
```dart
350353
final Web3AuthResponse response = await Web3AuthFlutter.login(LoginParams(
@@ -436,70 +439,174 @@ final Web3AuthResponse response = await Web3AuthFlutter.login(LoginParams(
436439

437440
### `logout()`
438441

439-
This method will logout the user and remove the session id from the device. The user will need to login again to use the dApp next time the dApp is
440-
opened.
442+
This method will logout the user and remove the session id from the device. The user will need to
443+
login again to use the dApp next time the dApp is opened.
441444

442445
```dart
443446
await Web3AuthFlutter.logout();
444447
```
445448

446449
:::tip sample-app
447450

448-
Get started with a sample app found [here](/examples?product=Plug+and+Play&sdk=Plug+and+Play+Flutter+SDK).
451+
Get started with a sample app found
452+
[here](/examples?product=Plug+and+Play&sdk=Plug+and+Play+Flutter+SDK).
449453

450454
:::
451455

452-
## Triggering Login exceptions
456+
## Enable MFA for a user
453457

454-
### `setResultUrl()`
458+
The `enableMFA` method is used to trigger MFA setup flow for users. The method takes `LoginParams`
459+
which will used during custom verifiers. If you are using default login providers, you don't need to
460+
pass `LoginParams`. If you are using custom jwt verifiers, you need to pass the JWT token in
461+
`loginParams` as well.
455462

456-
This method will trigger login exceptions for Android. For iOS, you don't need this method to trigger the login exceptions. The Android SDK uses the
457-
custom tabs and from current implementation of chrome custom tab, it's not possible to add a listener directly to chrome custom tab close button and
458-
trigger login exceptions.
463+
```dart title="Usage"
464+
try {
465+
await Web3AuthFlutter.enableMFA();
466+
} on UserCancelledException {
467+
log("User cancelled.");
468+
} catch(e) {
469+
log("Unknown exception occurred");
470+
}
471+
```
472+
473+
## Launch Wallet Services
474+
475+
The `launchWalletServices` method launches a WebView which allows you to use the templated wallet UI
476+
services. The method takes `ChainConfig` as the required input. Wallet Services is currently only
477+
available for EVM chains.
478+
479+
:::note Minimum Scale plan required
480+
481+
Access to Wallet Services is gated. You can use this feature in the development environment for
482+
free. The minimum [pricing plan](https://web3auth.io/pricing.html) to use this feature in a
483+
production environment is the **Scale Plan**.
459484

460-
Hence, it's necessary to user `setResultUrl` method in your login screen to trigger exceptions.
485+
:::
486+
487+
### Arguments
488+
489+
`ChainConfig`
490+
491+
<Tabs
492+
defaultValue="table"
493+
values={[
494+
{ label: "Table", value: "table" },
495+
{ label: "Class", value: "class" },
496+
]}
497+
>
498+
499+
<TabItem value="table">
500+
501+
| Parameter | Description |
502+
| ------------------- | --------------------------------------------------------------------------------------------------------------------------- |
503+
| `chainNamespace` | Custom configuration for your preferred blockchain. As of now only EVM supported. Default value is `ChainNamespace.eip155`. |
504+
| `decimals?` | Number of decimals for the currency ticker. Default value is 18, and accepts `int` as value. |
505+
| `blockExplorerUrl?` | Blockchain's explorer URL. (eg: `https://etherscan.io`) |
506+
| `chainId` | The chain id of the selected blockchain in hex `String`. |
507+
| `displayName?` | Display Name for the chain. |
508+
| `logo?` | Logo for the selected `chainNamespace` & `chainId`. |
509+
| `rpcTarget` | RPC Target URL for the selected `chainNamespace` & `chainId`. |
510+
| `ticker?` | Default currency ticker of the network (e.g: `ETH`) |
511+
| `tickerName?` | Name for currency ticker (e.g: `Ethereum`) |
512+
513+
</TabItem>
514+
515+
<TabItem value="class">
461516

462517
```dart
463-
class LoginScreen extends State<T> with WidgetsBindingObserver {
518+
class ChainConfig {
519+
final ChainNamespace chainNamespace;
520+
final int? decimals;
521+
final String? blockExplorerUrl;
522+
final String chainId;
523+
final String? displayName;
524+
final String? logo;
525+
final String rpcTarget;
526+
final String? ticker;
527+
final String? tickerName;
528+
529+
ChainConfig({
530+
this.chainNamespace = ChainNamespace.eip155,
531+
this.decimals = 18,
532+
this.blockExplorerUrl,
533+
required this.chainId,
534+
this.displayName,
535+
this.logo,
536+
required this.rpcTarget,
537+
this.ticker,
538+
this.tickerName,
539+
});
464540
465-
@override
466-
void initState() {
467-
super.initState();
468-
// highlight-next-line
469-
WidgetsBinding.instance.addObserver(this);
541+
Map<String, dynamic> toJson() {
542+
return {
543+
'chainNamespace': chainNamespace.name,
544+
'decimals': decimals,
545+
'blockExplorerUrl': blockExplorerUrl,
546+
'chainId': chainId,
547+
'displayName': displayName,
548+
'logo': logo,
549+
'rpcTarget': rpcTarget,
550+
'ticker': ticker,
551+
'tickerName': tickerName
552+
};
470553
}
554+
}
555+
```
471556

472-
@override
473-
void dispose() {
474-
super.dispose();
475-
// highlight-next-line
476-
WidgetsBinding.instance.removeObserver(this);
477-
}
557+
</TabItem>
558+
</Tabs>
478559

479-
// highlight-start
480-
@override
481-
void didChangeAppLifecycleState(final AppLifecycleState state) {
482-
// This is important to trigger the user cancellation on Android.
483-
if (state == AppLifecycleState.resumed) {
484-
Web3AuthFlutter.setResultUrl();
485-
}
486-
}
487-
// highlight-end
560+
```dart title="Usage"
561+
try {
562+
await Web3AuthFlutter.launchWalletServices(
563+
ChainConfig(
564+
chainId: "0x1",
565+
rpcTarget: "https://mainnet.infura.io/v3/$key",
566+
),
567+
);
568+
} on UserCancelledException {
569+
log("User cancelled.");
570+
} catch(e) {
571+
log("Unknown exception occurred");
572+
}
573+
```
488574

489-
@override
490-
Widget build(BuildContext context) {
491-
// Your UI code
492-
}
575+
## Request signature
493576

494-
Future<void> _login() async {
495-
try {
496-
await Web3AuthFlutter.login(LoginParams(loginProvider: Provider.google));
497-
} on UserCancelledException {
498-
log("User cancelled.");
499-
} on UnKnownException {
500-
log("Unknown exception occurred");
501-
} catch (e) {
502-
log(e.toString());
503-
}
504-
}
577+
The `request` method facilitates the use of templated transaction screens for signing transactions.
578+
Upon successful completion, you can retrieve the signature for the request using the
579+
`getSignResponse` static method.
580+
581+
Please check the list of [JSON RPC methods](docs.metamask.io/wallet/reference/json-rpc-api/), noting
582+
that the request method currently supports only the signing methods.
583+
584+
### Arguments
585+
586+
| Arguments | Description |
587+
| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
588+
| `method` | JSON RPC method name in `String`. Currently, the request method only supports the singing methods. |
589+
| `requestParams` | Parameters for the corresponding method. The parameters should be in the list and correct sequence. Take a look at [RPC methods](<[https://docs.metamask.io/wallet/reference/json-rpc-api/](https://docs.metamask.io/wallet/reference/json-rpc-api/)>) to know more. |
590+
591+
### Usage
592+
593+
```dart title="Usage"
594+
595+
try {
596+
List<dynamic> params = [];
597+
params.add("Hello, Web3Auth from Flutter!");
598+
params.add("<User Address in Hex>");
599+
600+
await Web3AuthFlutter.request(
601+
"personal_sign",
602+
params,
603+
);
604+
} on UserCancelledException {
605+
log("User cancelled.");
606+
} catch(e) {
607+
log("Unknown exception occurred");
608+
}
609+
610+
final signResponse = await Web3AuthFlutter.getSignResponse();
611+
log(signResponse.toString())
505612
```

0 commit comments

Comments
 (0)