-
Notifications
You must be signed in to change notification settings - Fork 537
Integration of FinoaConnect wallet connector service into Web3Onboard #2188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Adamj1232
merged 29 commits into
thirdweb-dev:develop
from
finoaamukherjee:feature/finoa-web3-onboard-integration
Aug 14, 2024
Merged
Changes from 8 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
e013ece
impl: integration into existing package
finoaamukherjee 95532ce
Update packages/finoaconnect/package.json
Adamj1232 5f5f8ea
Update packages/demo/package.json
Adamj1232 b1584db
Update .circleci/config.yml
Adamj1232 92ecbe6
fix: added comments and mock examplers in packages//README
finoaamukherjee abc102a
chore: update comment on unhandled error
finoaamukherjee ebdb835
Update +page.md
Adamj1232 bbd8052
Update README.md
Adamj1232 054e8c6
Update packages/finoaconnect/README.md
Adamj1232 73585bb
Update docs/src/routes/docs/[...4]wallets/[...36]finoaconnect/+page.md
Adamj1232 1e02ea2
Merge branch 'develop' into feature/finoa-web3-onboard-integration
Adamj1232 1f8234a
fix: renamed icon name to FinoaConnect and added finoaconnect to serv…
finoaamukherjee 4988b23
fix: update typescript version in finoaconnect package
finoaamukherjee c42ec26
Merge branch 'develop' into feature/finoa-web3-onboard-integration
Adamj1232 9729859
fix: all unsupported methods to return error code 4200
finoaamukherjee 4432f6a
chore: cleaned up commented code and unnecessary lock files
finoaamukherjee 5eef9f9
Merge branch 'develop' into feature/finoa-web3-onboard-integration
finoaamukherjee eaf2d7b
chore: removed unused code
finoaamukherjee deb91bc
Merge branch 'develop' into feature/finoa-web3-onboard-integration
Adamj1232 ff4ce6a
Merge branch 'develop' into feature/finoa-web3-onboard-integration
Adamj1232 4f62901
Merge branch 'develop' into feature/finoa-web3-onboard-integration
Adamj1232 3d17e9c
Merge branch 'develop' into feature/finoa-web3-onboard-integration
Adamj1232 0e9836a
Merge branch 'blocknative:develop' into feature/finoa-web3-onboard-in…
finoaamukherjee c4f3485
Merge branch 'develop' into feature/finoa-web3-onboard-integration
Adamj1232 e5d4ab8
Merge branch 'develop' into feature/finoa-web3-onboard-integration
Adamj1232 5e9f04e
Merge branch 'develop' into feature/finoa-web3-onboard-integration
finoaamukherjee 55ef4ce
fix: updated finoaconnect sdk version
finoaamukherjee 6d8ab05
Merge branch 'develop' into feature/finoa-web3-onboard-integration
Adamj1232 5506f27
Merge in upstream and yarn
Adamj1232 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
docs/src/routes/docs/[...4]wallets/[...36]finoaconnect/+page.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
--- | ||
title: FinoaConnect | ||
--- | ||
|
||
## Wallet module for connecting FinoaConnect SDK to web3-onboard | ||
|
||
## Install | ||
|
||
<Tabs values={['yarn', 'npm']}> | ||
<TabPanel value="yarn"> | ||
|
||
```sh copy | ||
yarn add @web3-onboard/core @web3-onboard/finoaconnect | ||
``` | ||
|
||
</TabPanel> | ||
<TabPanel value="npm"> | ||
|
||
```sh copy | ||
npm install @web3-onboard/core @web3-onboard/finoaconnect | ||
``` | ||
|
||
</TabPanel> | ||
</Tabs> | ||
|
||
## Usage | ||
|
||
Optional initialization object | ||
```typescript | ||
/** Optional object provided to the initiation of the wallet connector. | ||
* When not included, the wallet connector service connects to FinoaConnect production systems. | ||
* @field {url} URL of the FinoaConnect backend systems to be used | ||
* @field {labelSuffix} arbitrary string label to denote the context of the URL field */ | ||
export interface FinoaWalletOption { | ||
url?: string | ||
labelSuffix?: string | ||
} | ||
Adamj1232 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
```typescript | ||
import Onboard from '@web3-onboard/core' | ||
import finoaConnectModule from '@web3-onboard/finoaconnect' | ||
|
||
// initialize the module with options | ||
const finoaConnect = finoaConnectModule() | ||
|
||
const onboard = Onboard({ | ||
// ... other Onboard options | ||
wallets: [ | ||
finoaConnect | ||
//... other wallets | ||
] | ||
}) | ||
|
||
const connectedWallets = await onboard.connectWallet() | ||
console.log(connectedWallets) | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# @web3-onboard/finoaconnect | ||
|
||
## Wallet module for connecting FinoaConnect SDK to web3-onboard | ||
|
||
#### Install | ||
|
||
`npm i @web3-onboard/core @web3-onboard/finoaconnect` | ||
|
||
## Usage | ||
|
||
Adamj1232 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Optional initialization object | ||
```typescript | ||
/** Optional object provided to the initiation of the wallet connector. | ||
* When not included, the wallet connector service connects to FinoaConnect production systems. | ||
* @field {url} URL of the FinoaConnect backend systems to be used | ||
* @field {labelSuffix} arbitrary string label to denote the context of the URL field */ | ||
export interface FinoaWalletOption { | ||
url?: string | ||
labelSuffix?: string | ||
} | ||
Adamj1232 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
```typescript | ||
import Onboard from '@web3-onboard/core'; | ||
import finoaConnectModule from '@web3-onboard/finoaconnect'; | ||
|
||
const onboard = Onboard({ | ||
// ... other Onboard options | ||
wallets: [ | ||
finoaConnectModule() | ||
//... other wallets | ||
] | ||
}) | ||
|
||
// alternatively to connect to a localised development environment | ||
const onboard = Onboard({ | ||
// ... other Onboard options | ||
wallets: [ | ||
finoaConnectModule([ | ||
{ | ||
labelSuffix: 'localhost', | ||
url: 'http://localhost:8080', | ||
} | ||
]) | ||
//... other wallets | ||
] | ||
}) | ||
|
||
const connectedWallets = await onboard.connectWallet() | ||
console.log(connectedWallets) | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{ | ||
"name": "@web3-onboard/finoaconnect", | ||
"version": "2.0.0-alpha.1", | ||
"description": "FinoaConnect enables DApp users to use Finoa's Institutional Custody services.", | ||
"keywords": [ | ||
"Ethereum", | ||
"Web3", | ||
"EVM", | ||
"dapp", | ||
"Multichain", | ||
"Wallet", | ||
"Transaction", | ||
"Provider", | ||
"Hardware Wallet", | ||
"Notifications", | ||
"React", | ||
"Svelte", | ||
"Vue", | ||
"Next", | ||
"Nuxt", | ||
"MetaMask", | ||
"Coinbase", | ||
"WalletConnect", | ||
"Ledger", | ||
"Trezor", | ||
"Connect Wallet", | ||
"Ethereum Hooks", | ||
"Blocknative", | ||
"Mempool", | ||
"pending", | ||
"confirmed", | ||
"Injected Wallet", | ||
"Crypto", | ||
"Crypto Wallet", | ||
"Tally Ho", | ||
"FinoaConnect" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/blocknative/web3-onboard.git", | ||
"directory": "packages/finoaconnect" | ||
}, | ||
"homepage": "https://onboard.blocknative.com", | ||
"bugs": "https://github.com/blocknative/web3-onboard/issues", | ||
"module": "dist/index.js", | ||
"browser": "dist/index.js", | ||
"main": "dist/index.js", | ||
"type": "module", | ||
"typings": "dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "tsc", | ||
"dev": "tsc -w", | ||
"type-check": "tsc --noEmit" | ||
}, | ||
"devDependencies": { | ||
"typescript": "5.1.6" | ||
finoaamukherjee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
"dependencies": { | ||
"@finoa/finoa-connect-sdk": "^1.0.2", | ||
"@web3-onboard/core": "^2.20.4" | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export async function request(url: string, call: object): Promise<any> { | ||
// SOURCE: https://github.com/blocknative/web3-onboard/blob/ddfb620c62202b24adfe41994037d9609a697e0d/packages/hw-common/src/index.ts | ||
const response = await fetch(url, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify({ | ||
jsonrpc: '2.0', | ||
id: '42', | ||
...call | ||
}) | ||
}) | ||
const json = await response.json() | ||
if ('error' in json) { | ||
throw json.error | ||
} | ||
return json.result | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default ` | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<svg width="24" height="24" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
<path fill-rule="evenodd" clip-rule="evenodd" d="M4.029 0A4.029 4.029 0 0 0 0 4.029V19.97A4.029 4.029 0 0 0 4.029 24H19.97A4.029 4.029 0 0 0 24 19.971V4.03A4.029 4.029 0 0 0 19.971 0H4.03ZM9.71 15.252a2.277 2.277 0 0 0 2.275 2.273 2.277 2.277 0 0 0 1.668-3.818l-1.668-1.668-1.363-1.362-2.488-2.489 2.068-2.067 2.005-2.004L13.5 5.41l-2.71 2.71 1.196 1.194 2.208-2.17.719.716.646.644-2.212 2.172 1.696 1.696a4.198 4.198 0 0 1-3.057 7.081 4.205 4.205 0 0 1-4.203-4.2c0-1.061.397-2.073 1.117-2.852l.937-.937 1.363 1.362-.91.91c-.364.394-.58.942-.58 1.517Z" fill="#32C6A1"></path> | ||
</svg> | ||
` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { FinoaEIP1193Provider } from '@finoa/finoa-connect-sdk' | ||
import type { Chain, WalletInit } from '@web3-onboard/common' | ||
|
||
/** Optional object provided to the initiation of the wallet connector. | ||
* When not included, the wallet connector service connects to FinoaConnect production systems. | ||
* @field {url} URL of the FinoaConnect backend systems to be used | ||
* @field {labelSuffix} arbitrary string label to denote the context of the URL field */ | ||
export interface FinoaWalletOption { | ||
Adamj1232 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
url?: string | ||
labelSuffix?: string | ||
} | ||
|
||
function finoaConnect(option?: string | FinoaWalletOption): WalletInit { | ||
const { url, labelSuffix }: FinoaWalletOption = | ||
typeof option === 'string' ? { url: option } : !option ? {} : option | ||
|
||
return () => { | ||
return { | ||
label: `Finoa Wallet${labelSuffix == null ? '' : ' - ' + labelSuffix}`, | ||
getIcon: async () => (await import('./icon')).default, | ||
getInterface: async ({ chains }) => { | ||
const { | ||
FinoaEIP1193Provider, | ||
FinoaBrowserClient, | ||
UnsupportedRequestError | ||
} = await import('@finoa/finoa-connect-sdk') | ||
|
||
const { request } = await import('./fetch-rpc') | ||
|
||
const client = new FinoaBrowserClient({ | ||
windowUrl: url | ||
}) | ||
const provider = new FinoaEIP1193Provider({ | ||
client | ||
}) | ||
|
||
const proxyProvider = new Proxy(provider, { | ||
get(target, property: keyof FinoaEIP1193Provider) { | ||
const source = target[property] | ||
if (property === 'request') { | ||
return async function ( | ||
this: FinoaEIP1193Provider, | ||
...args: Parameters<FinoaEIP1193Provider['request']> | ||
) { | ||
try { | ||
return await (source as FinoaEIP1193Provider['request']).call( | ||
this, | ||
...args | ||
) | ||
} catch (err) { | ||
if (err instanceof UnsupportedRequestError) { | ||
let chain: Chain | undefined | ||
try { | ||
const chainIdN = BigInt(err.chainId) | ||
chain = chains.find( | ||
chain => BigInt(chain.id) === chainIdN | ||
) | ||
} catch { | ||
/* Not handled: the chain id in the error is not a valid one */ | ||
} | ||
if (chain?.rpcUrl == null) { | ||
throw err | ||
} | ||
return await request(chain.rpcUrl, ...args) | ||
} | ||
throw err | ||
} | ||
} | ||
} | ||
return source | ||
} | ||
}) | ||
|
||
return { | ||
provider: proxyProvider | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
export default finoaConnect |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"include": ["src/**/*"], | ||
|
||
"compilerOptions": { | ||
"outDir": "dist", | ||
"rootDir": "src", | ||
"declaration": true, | ||
"declarationDir": "dist", | ||
"allowSyntheticDefaultImports": true, | ||
"paths": { | ||
"*": ["./src/*", "./node_modules/*"] | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.