Skip to content

Commit 820cf00

Browse files
Adamj1232gesquincaleightktlnbc1QWFyb24
authored
Feat: Private/custom rpc flow (#1704)
* RPC protect workflow acting as expected maybe some styling issues * Working as expected, added configs for rpc url and displaying protect button * fix text color for dark mode * Refine background colors * Refine verbiage and remove placeholder for link * Remove box shadow from AC section * Bump versions accordingly * Rename rpc update func * Cleanup type prop comments * Refine state get in maximized * update modal styles - use theme vars - remove rpc specific css vars - adjust spacing - remove unused css classes * Update packages/core/src/provider.ts * Add disableProtectRPC to accountCenterInit validation * Update docs for AccountCenter diableProtectRPC * Update packages/core/src/index.ts Co-authored-by: Kat Leight <33187102+leightkt@users.noreply.github.com> * Add small null check for secondary tokens * Update rpc * Update rpc again * yarnit * Update rpc url * Add localstore check if RPC has been added * Add dismissall of modal after confirm * Update localstore call * Remove localstore check * Update packages/core/src/views/connect/Index.svelte Co-authored-by: Aaron <abarnard@protonmail.com> * Prettier * Remove square brackets from docs --------- Co-authored-by: Gustavo Esquinca <g.esq.ca@gmail.com> Co-authored-by: Kat Leight <33187102+leightkt@users.noreply.github.com> Co-authored-by: Aaron <abarnard@protonmail.com>
1 parent 7d5c42f commit 820cf00

File tree

56 files changed

+656
-180
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+656
-180
lines changed

docs/src/routes/docs/[...1]overview/[...1]introduction/+page.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ web3-onboard supports all EVM networks. Supporting a new network is simply a mat
5151
- Moonriver
5252
- All other EVM network
5353

54-
### [Optional] Use an API key to fetch real time transaction data, balances & gas
54+
### Optional - Use an API key to fetch real time transaction data, balances & gas
5555

5656
Using a Blocknative API key with web3-onboard on the free plan will allow you to gain the benefits of Blocknative balance & transaction services. Blocknative has a free forever plan you can always use.
5757

docs/src/routes/docs/[...1]overview/[...2]contribution-guide/+page.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ If an issue does not already exist, follow the template instructions to create a
1919

2020
Once an issue is created, a Web3 Onboard maintainer will review and respond typically within a few days to share next steps.
2121

22-
## [Pull Requests 🗂️]
22+
## Pull Requests 🗂️
2323

2424
To create a new feature or change in Web3 Onboard, fork the repo and make a pull request on the [develop branch](https://github.com/blocknative/web3-onboard/tree/develop) to have your changes merged in and released as part of the official packages.
2525

@@ -39,7 +39,7 @@ Example : Adding a new injected wallet to the `injected` package -
3939
Example 2 : Bug fix within the `core` package -
4040
[Core package.json](https://github.com/blocknative/web3-onboard/blob/8531a73d69365f7d584320f1c4b97a5d90f1c34e/packages/core/package.json#L3) changes: `"version": "2.9.1-alpha.1",` --> `"version": "2.9.1-alpha.2",`
4141

42-
## [How can I add a new wallet? 💳]
42+
## How can I add a new wallet? 💳
4343

4444
To add a new wallet to the official Web3 Onboard packages and repo, create a [pull request](#pull-requests-🗂️). Web3 Onboard does not require a wallet to be a part of the main code, so a separate wallet module can be created without any changes to the Web3Onboard codebase. Your PR must include a detailed README for the package, keeping in mind that this README is the the first point of contact for dapp devs looking to implement your wallet.
4545

@@ -57,7 +57,7 @@ Otherwise, if the wallet you are adding requires dependencies and initialization
5757

5858
If you cannot write the code yourself to add a new wallet, create a new feature request issue to be considered by the maintainers and other contributors in the community.
5959

60-
## [Documentation Contributions 📄]
60+
## Documentation Contributions 📄
6161

6262
If you contribute to the code, you should definitely document appropriately.
6363

@@ -71,11 +71,11 @@ PRs for adding/updating a wallet should include a README (new or updated) for th
7171

7272
We highly encourage the community to help us improve the web3-onboard docs! If you have any questions don't hesitate to reach out.
7373

74-
## [Feedback 💬]
74+
## Feedback 💬
7575

7676
Did you have trouble integrating? Could the docs be improved? Have a new Feature request?
7777
Jump in our [Discord](https://discord.com/invite/KZaBVME) and share your feedback.
7878

79-
## [Support 🤓]
79+
## Support 🤓
8080

8181
For general questions about how to use Web3 Onboard please first check out our [docs](../../overview/introduction.md#features), then head to our [Discord](https://discord.com/invite/KZaBVME) for support from the Blocknative team.

docs/src/routes/docs/[...3]modules/[...1]core/+page.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ type Chain = {
145145
icon?: string // the icon to represent the chain
146146
publicRpcUrl?: string // an optional public RPC used when adding a new chain config to the wallet
147147
blockExplorerUrl?: string // also used when adding a new config to the wallet
148-
secondaryTokens?: SecondaryTokens[] // An optional array of tokens (max of 5) to be available to the dapp in the app state object per wallet within the wallet account and displayed in Account Center (if enabled)
148+
secondaryTokens?: SecondaryTokens[] // An optional array of tokens (max of 5) to be available to the dapp in the app state object per wallet within the wallet account and displayed in Account Center (if enabled)
149149
}
150150

151151
interface SecondaryTokens {
@@ -368,7 +368,13 @@ type AccountCenter = {
368368
position?: AccountCenterPosition // default: 'bottomRight'
369369
expanded?: boolean // default: true
370370
minimal?: boolean // enabled by default for mobile
371-
371+
/**
372+
* false by default - This allows removal of the
373+
* Enable Transaction Protection' button within the Account Center
374+
* expanded when set to true
375+
* Can be set as a global for Account Center or per interface (desktop/mobile)
376+
*/
377+
hideTransactionProtectionBtn?: boolean
372378
/**
373379
* @deprecated Use top level containerElements property
374380
* with the accountCenter prop set to the desired container El. See documentation below
@@ -379,6 +385,13 @@ type AccountCenter = {
379385
type AccountCenterOptions = {
380386
desktop: Omit<AccountCenter, 'expanded'>
381387
mobile: Omit<AccountCenter, 'expanded'>
388+
/**
389+
* false by default - This allows removal of the
390+
* Enable Transaction Protection' button within the Account Center
391+
* expanded when set to true
392+
* Can be set as a global for Account Center or per interface (desktop/mobile)
393+
*/
394+
hideTransactionProtectionBtn?: boolean
382395
}
383396

384397
type AccountCenterPosition = 'topRight' | 'bottomRight' | 'bottomLeft' | 'topLeft'

packages/cede-store/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@
7070
},
7171
"dependencies": {
7272
"@cedelabs/providers": "^0.0.7",
73-
"@web3-onboard/common": "^2.3.2"
73+
"@web3-onboard/common": "^2.3.3-alpha.1"
7474
}
7575
}

packages/coinbase/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/coinbase",
3-
"version": "2.2.3",
3+
"version": "2.2.4-alpha.1",
44
"description": "Coinbase SDK wallet module for connecting to Web3-Onboard. Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardised spec compliant web3 providers for all supported wallets, framework agnostic modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.",
55
"keywords": [
66
"Ethereum",
@@ -59,6 +59,6 @@
5959
},
6060
"dependencies": {
6161
"@coinbase/wallet-sdk": "^3.6.0",
62-
"@web3-onboard/common": "^2.3.2"
62+
"@web3-onboard/common": "^2.3.3-alpha.1"
6363
}
6464
}

packages/common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/common",
3-
"version": "2.3.2",
3+
"version": "2.3.3-alpha.1",
44
"description": "Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardised spec compliant web3 providers for all supported wallets, framework agnostic modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.",
55
"keywords": [
66
"Ethereum",

packages/common/src/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,11 @@ export interface Chain {
421421
providerConnectionInfo?: ConnectionInfo
422422
/* An optional public RPC used when adding a new chain config to the wallet */
423423
publicRpcUrl?: string
424+
/** An optional protected RPC URL - Defaults to Blocknative's private and
425+
* protected RPC to allow users to update the chain RPC within their wallet,
426+
* specifically for private RPCs that protect user transactions
427+
*/
428+
protectedRpcUrl?: string
424429
/* Also used when adding a new config to the wallet */
425430
blockExplorerUrl?: string
426431
}

packages/common/src/validation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export const chainValidation = Joi.object({
4949
icon: Joi.string(),
5050
color: Joi.string(),
5151
publicRpcUrl: Joi.string(),
52+
protectedRpcUrl: Joi.string(),
5253
blockExplorerUrl: Joi.string(),
5354
providerConnectionInfoValidation
5455
})

packages/core/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,13 @@ type AccountCenter = {
335335
type AccountCenterOptions = {
336336
desktop: Omit<AccountCenter, 'expanded'>
337337
mobile: Omit<AccountCenter, 'expanded'>
338+
/**
339+
* false by default - This allows removal of the
340+
* Enable Transaction Protection' button within the Account Center
341+
* expanded when set to true
342+
* Can be set as a global for Account Center or per interface (desktop/mobile)
343+
*/
344+
hideTransactionProtectionBtn?: boolean
338345
}
339346

340347
type AccountCenterPosition =

packages/core/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/core",
3-
"version": "2.18.1-alpha.2",
3+
"version": "2.19.0-alpha.1",
44
"description": "Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardized spec compliant web3 providers for all supported wallets, framework agnostic modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.",
55
"keywords": [
66
"Ethereum",
@@ -85,7 +85,7 @@
8585
"typescript": "^4.5.5"
8686
},
8787
"dependencies": {
88-
"@web3-onboard/common": "^2.3.2",
88+
"@web3-onboard/common": "^2.3.3-alpha.1",
8989
"bignumber.js": "^9.0.0",
9090
"bnc-sdk": "^4.6.7",
9191
"bowser": "^2.11.0",

packages/core/src/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ export const STORAGE_KEYS = {
3636
}
3737

3838
export const MOBILE_WINDOW_WIDTH = 768
39+
40+
export const BN_PROTECT_RPC_URL = 'https://rpc.blocknative.com/protect'

packages/core/src/i18n/en.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,19 @@
5656
"description": "Are you sure that you would like to disconnect all your wallets?",
5757
"confirm": "Confirm",
5858
"cancel": "Cancel"
59+
},
60+
"confirmTransactionProtection": {
61+
"heading": "Enable Transaction Protection",
62+
"description": "Protect RPC Endpoints hide your transactions from front-running and sandwich bots to reduce unfavorable transaction settlement from slippage.",
63+
"enable": "Enable",
64+
"dismiss": "Dismiss"
5965
}
6066
},
6167
"accountCenter": {
6268
"connectAnotherWallet": "Connect another Wallet",
6369
"disconnectAllWallets": "Disconnect all Wallets",
6470
"currentNetwork": "Current Network",
71+
"enableTransactionProtection": "Enable Transaction Protection",
6572
"appInfo": "App Info",
6673
"learnMore": "Learn More",
6774
"gettingStartedGuide": "Getting Started Guide",
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default `<svg width="14" height="18" viewBox="0 0 14 18" fill="none" xmlns="http://www.w3.org/2000/svg">
2+
<path d="M6.99998 17.3125C5.05553 16.8264 3.45831 15.6979 2.20831 13.9271C0.958313 12.1562 0.333313 10.2153 0.333313 8.10417V3.14583L6.99998 0.645833L13.6666 3.14583V8.10417C13.6666 10.2153 13.0416 12.1562 11.7916 13.9271C10.5416 15.6979 8.94442 16.8264 6.99998 17.3125ZM5.12498 12.3333H8.87498C9.05553 12.3333 9.20484 12.2743 9.3229 12.1562C9.44095 12.0382 9.49998 11.8889 9.49998 11.7083V8.79167C9.49998 8.61111 9.44095 8.46181 9.3229 8.34375C9.20484 8.22569 9.05553 8.16667 8.87498 8.16667H8.66665V7.33333C8.66665 6.875 8.50345 6.48264 8.17706 6.15625C7.85067 5.82986 7.45831 5.66667 6.99998 5.66667C6.54165 5.66667 6.14928 5.82986 5.8229 6.15625C5.49651 6.48264 5.33331 6.875 5.33331 7.33333V8.16667H5.12498C4.94442 8.16667 4.79512 8.22569 4.67706 8.34375C4.55901 8.46181 4.49998 8.61111 4.49998 8.79167V11.7083C4.49998 11.8889 4.55901 12.0382 4.67706 12.1562C4.79512 12.2743 4.94442 12.3333 5.12498 12.3333ZM5.95831 8.16667V7.33333C5.95831 7.05556 6.06248 6.82292 6.27081 6.63542C6.47915 6.44792 6.7222 6.35417 6.99998 6.35417C7.27776 6.35417 7.52081 6.44792 7.72915 6.63542C7.93748 6.82292 8.04165 7.05556 8.04165 7.33333V8.16667H5.95831Z" fill="#929BED"/>
3+
</svg>
4+
`

packages/core/src/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ import { state } from './store/index.js'
55
import { reset$, wallets$ } from './streams.js'
66
import initI18N from './i18n/index.js'
77
import App from './views/Index.svelte'
8-
import type { ConnectModalOptions, InitOptions, Notify, Theme } from './types.js'
8+
import type {
9+
ConnectModalOptions,
10+
InitOptions,
11+
Notify,
12+
Theme
13+
} from './types.js'
914
import { APP_INITIAL_STATE, STORAGE_KEYS } from './constants.js'
1015
import { configuration, updateConfiguration } from './configuration.js'
1116
import updateBalances from './update-balances.js'
@@ -117,19 +122,21 @@ function init(options: InitOptions): OnboardAPI {
117122
if (typeof connect !== undefined) {
118123
updateConnectModal(connect)
119124
}
120-
121125
// update accountCenter
122126
if (typeof accountCenter !== 'undefined') {
123127
let accountCenterUpdate
128+
const { hideTransactionProtectionBtn } = accountCenter
124129

125130
if (device.type === 'mobile') {
126131
accountCenterUpdate = {
127132
...APP_INITIAL_STATE.accountCenter,
133+
hideTransactionProtectionBtn,
128134
...(accountCenter.mobile ? accountCenter.mobile : {})
129135
}
130136
} else if (accountCenter.desktop) {
131137
accountCenterUpdate = {
132138
...APP_INITIAL_STATE.accountCenter,
139+
hideTransactionProtectionBtn,
133140
...accountCenter.desktop
134141
}
135142
}

packages/core/src/provider.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,31 @@ export function addNewChain(
471471
})
472472
}
473473

474+
export function updateChainRPC(
475+
provider: EIP1193Provider,
476+
chain: Chain,
477+
rpcUrl: string
478+
): Promise<unknown> {
479+
return provider.request({
480+
method: 'wallet_addEthereumChain',
481+
params: [
482+
{
483+
chainId: chain.id,
484+
chainName: chain.label,
485+
nativeCurrency: {
486+
name: chain.label,
487+
symbol: chain.token,
488+
decimals: 18
489+
},
490+
rpcUrls: [rpcUrl],
491+
blockExplorerUrls: chain.blockExplorerUrl
492+
? [chain.blockExplorerUrl]
493+
: undefined
494+
}
495+
]
496+
})
497+
}
498+
474499
export async function getPermissions(
475500
provider: EIP1193Provider
476501
): Promise<WalletPermission[]> {

packages/core/src/types.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,13 @@ export type NotificationPosition = CommonPositions
263263

264264
export type AccountCenter = {
265265
enabled: boolean
266+
/**
267+
* false by default - This allows removal of the
268+
* Enable Transaction Protection' button within the Account Center
269+
* expanded when set to true
270+
* Can be set as a global for Account Center or per interface (desktop/mobile)
271+
*/
272+
hideTransactionProtectionBtn?: boolean
266273
position?: AccountCenterPosition
267274
expanded?: boolean
268275
minimal?: boolean
@@ -276,6 +283,13 @@ export type AccountCenter = {
276283
export type AccountCenterOptions = {
277284
desktop: Omit<AccountCenter, 'expanded'>
278285
mobile: Omit<AccountCenter, 'expanded'>
286+
/**
287+
* false by default - This allows removal of the
288+
* Enable Transaction Protection' button within the Account Center
289+
* expanded when set to true
290+
* Can be set as a global for Account Center or per interface (desktop/mobile)
291+
*/
292+
hideTransactionProtectionBtn?: boolean
279293
}
280294

281295
export type ContainerElements = {

packages/core/src/validation.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,16 @@ const accountCenterInitOptions = Joi.object({
168168
enabled: Joi.boolean(),
169169
position: commonPositions,
170170
minimal: Joi.boolean(),
171-
containerElement: Joi.string()
171+
containerElement: Joi.string(),
172+
hideTransactionProtectionBtn: Joi.boolean()
172173
})
173174

174175
const accountCenter = Joi.object({
175176
enabled: Joi.boolean(),
176177
position: commonPositions,
177178
expanded: Joi.boolean(),
178179
minimal: Joi.boolean(),
180+
hideTransactionProtectionBtn: Joi.boolean(),
179181
containerElement: Joi.string()
180182
})
181183

@@ -216,7 +218,8 @@ const initOptions = Joi.object({
216218
apiKey: Joi.string(),
217219
accountCenter: Joi.object({
218220
desktop: accountCenterInitOptions,
219-
mobile: accountCenterInitOptions
221+
mobile: accountCenterInitOptions,
222+
hideTransactionProtectionBtn: Joi.boolean()
220223
}),
221224
notify: [notifyOptions, notify],
222225
gas: Joi.object({
@@ -263,6 +266,7 @@ const setChainOptions = Joi.object({
263266
rpcUrl: Joi.string(),
264267
label: Joi.string(),
265268
token: Joi.string(),
269+
protectedRpcUrl: Joi.string(),
266270
secondaryTokens: Joi.array().max(5).items(secondaryTokenValidation).optional()
267271
})
268272

0 commit comments

Comments
 (0)