You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Notify can be used to deliver custom DApp notifications by passing a `CustomNotification` object to the `customNotification` action. This will return an `UpdateNotification` type.
218
-
This `UpdateNotification` will return an `update` function that can be passed a new `CustomNotification` to update the existing notification.
219
-
The `customNotification` method also returns a `dismiss` method that is called without any parameters to dismiss the notification.
message: 'This is a custom DApp pending notification to use however you want',
225
-
autoDismiss: 0
226
-
})
227
-
setTimeout(
228
-
() =>
229
-
update({
230
-
eventCode: 'dbUpdateSuccess',
231
-
message: 'Updated status for custom notification',
232
-
type: 'success',
233
-
autoDismiss: 8000
234
-
}),
235
-
4000
236
-
)
237
-
```
238
-
239
216
### Initialization Example
240
217
241
218
Putting it all together, here is an example initialization with the injected wallet modules:
@@ -551,7 +528,7 @@ unsubscribe()
551
528
552
529
A limited subset of internal actions are exposed to update the Onboard state.
553
530
554
-
**setWalletModules**
531
+
**`setWalletModules`**
555
532
For updating the wallets that are displayed in the wallet selection modal. This can be used if the wallets you want to support is conditional on another user action within your app. The `setWalletModules` action is called with an updated array of wallets (the same wallets that are passed in on initialization)
You may decide to get updated balances for connected wallets after a user action by calling the `updatedBalances` function, which expects a conditional array of addresses.
564
+
**`updateBalances`**
565
+
You may decide to get updated balances for connected wallets after a user action by calling the `updatedBalances` function, which expects a conditional array of addresses:
589
566
590
-
```
567
+
```javascript
591
568
onboard.state.actions.updateBalances() // update all balances for all connected addresses
592
569
onboard.state.actions.updateBalances(['0xfdadfadsadsadsadasdsa']) // update balance for one address
Onboard will automatically detect the browser locale at runtime, but if you would like to update it manually you can call the `setLocale` function:
578
+
579
+
```javascript
580
+
onboard.state.actions.setLocal('fr_FR')
581
+
```
582
+
583
+
**`updateNotify`**
584
+
If you need to update your notify configuration after initialization, you can do that by calling the `updateNotify` function:
585
+
586
+
```javascript
587
+
onboard.state.actions.updateNotify({
588
+
desktop: {
589
+
enabled:true,
590
+
transactionHandler:transaction=> {
591
+
console.log({ transaction })
592
+
if (transaction.eventCode==='txPool') {
593
+
return {
594
+
type:'success',
595
+
message:'Your transaction from #1 DApp is in the mempool'
596
+
}
597
+
}
598
+
},
599
+
position:'bottomLeft'
600
+
},
601
+
mobile: {
602
+
enabled:true,
603
+
transactionHandler:transaction=> {
604
+
console.log({ transaction })
605
+
if (transaction.eventCode==='txPool') {
606
+
return {
607
+
type:'success',
608
+
message:'Your transaction from #1 DApp is in the mempool'
609
+
}
610
+
}
611
+
},
612
+
position:'topRight'
613
+
}
614
+
})
615
+
```
616
+
617
+
**`customNotification`**
618
+
Notify can be used to deliver custom DApp notifications by passing a `CustomNotification` object to the `customNotification` action. This will return an `UpdateNotification` type.
619
+
This `UpdateNotification` will return an `update` function that can be passed a new `CustomNotification` to update the existing notification.
620
+
The `customNotification` method also returns a `dismiss` method that is called without any parameters to dismiss the notification.
message: 'This is a custom DApp pending notification to use however you want',
626
+
autoDismiss: 0
627
+
})
628
+
setTimeout(
629
+
() =>
630
+
update({
631
+
eventCode: 'dbUpdateSuccess',
632
+
message: 'Updated status for custom notification',
633
+
type: 'success',
634
+
autoDismiss: 8000
635
+
}),
636
+
4000
637
+
)
638
+
```
639
+
640
+
**`updateAccountCenter`**
641
+
If you need to update your Account Center configuration after initialization, you can call the `updateAccountCenter` function with the new configuration
642
+
643
+
```typescript
644
+
onboard.state.actions.updateAccountCenter({
645
+
desktop: {
646
+
position: 'topRight',
647
+
enabled: true,
648
+
minimal: true
649
+
},
650
+
mobile: {
651
+
position: 'topRight',
652
+
enabled: true,
653
+
minimal: true
654
+
}
655
+
})
656
+
```
657
+
658
+
**`setPrimaryWallet`**
659
+
The primary wallet (first in the list of connected wallets) and primary account (first in the list of connected accounts for a wallet) can be set by using the `setPrimaryWallet` function. The wallet that is to be set needs to be passed in for the first parameter and if you would like to set the primary account, the address of that account also needs to be passed in:
660
+
661
+
```typescript
662
+
// set the second wallet in the wallets array as the primary
// set the second wallet in the wallets array as the primary wallet
666
+
// as well as setting the third account in that wallet as the primary account
667
+
onboard.state.actions.setPrimaryWallet(
668
+
wallets[1],
669
+
wallets[1].accounts[2].address
670
+
)
671
+
```
672
+
599
673
## Setting the User's Chain/Network
600
674
601
675
When initializing Onboard you define a list of chains/networks that your app supports. If you would like to prompt the user to switch to one of those chains, you can use the `setChain` method on an initialized instance of Onboard:
0 commit comments