Skip to content

Commit e013ece

Browse files
impl: integration into existing package
1 parent 0184045 commit e013ece

File tree

11 files changed

+279
-2
lines changed

11 files changed

+279
-2
lines changed

.circleci/config.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,13 @@ jobs:
448448
working_directory: ~/web3-onboard-monorepo/packages/particle-network
449449
steps:
450450
- node-build-steps
451-
451+
build-finoaconnect:
452+
docker:
453+
- image: cimg/node:18.0.0
454+
working_directory: ~/web3-onboard-monorepo/packages/finoaconnect
455+
steps:
456+
- node-build-steps
457+
452458
# Build staging/Alpha releases
453459
build-staging-core:
454460
docker:
@@ -732,6 +738,12 @@ jobs:
732738
working_directory: ~/web3-onboard-monorepo/packages/particle-network
733739
steps:
734740
- node-staging-build-steps
741+
build-finoaconnect:
742+
docker:
743+
- image: cimg/node:18.0.0
744+
working_directory: ~/web3-onboard-monorepo/packages/finoaconnect
745+
steps:
746+
- node-build-steps
735747

736748
workflows:
737749
version: 2
@@ -1018,3 +1030,9 @@ workflows:
10181030
<<: *deploy_production_filters
10191031
- build-staging-particle:
10201032
<<: *deploy_staging_filters
1033+
finoaconnect:
1034+
jobs:
1035+
- build-finoaconnect:
1036+
<<: *deploy_production_filters
1037+
- build-staging-finoaconnect:
1038+
<<: *deploy_staging_filters

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ For full documentation, check out the README.md for each package or the [docs pa
126126
- [Frame](packages/frame/README.md)
127127
- [Blocto](packages/blocto/README.md)
128128
- [Particle Network](packages/particle-network/README.md)
129+
- [FinoaConnect](packages/finoaconnect/README.md)
129130

130131
**Hardware Wallets**
131132

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
title: FinoaConnect
3+
---
4+
5+
## Wallet module for connecting FinoaConnect SDK to web3-onboard
6+
7+
## Install
8+
9+
<Tabs values={['yarn', 'npm']}>
10+
<TabPanel value="yarn">
11+
12+
```sh copy
13+
yarn add @web3-onboard/core @web3-onboard/finoaconnect
14+
```
15+
16+
</TabPanel>
17+
<TabPanel value="npm">
18+
19+
```sh copy
20+
npm install @web3-onboard/core @web3-onboard/finoaconnect
21+
```
22+
23+
</TabPanel>
24+
</Tabs>
25+
26+
## Usage
27+
28+
```typescript
29+
import Onboard from '@web3-onboard/core'
30+
import finoaConnectModule from '@web3-onboard/finoaconnect'
31+
32+
// initialize the module with options
33+
const finoaConnect = finoaConnectModule()
34+
35+
const onboard = Onboard({
36+
// ... other Onboard options
37+
wallets: [
38+
finoaConnect
39+
//... other wallets
40+
]
41+
})
42+
43+
const connectedWallets = await onboard.connectWallet()
44+
console.log(connectedWallets)
45+
```

packages/demo/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"@web3-onboard/coinbase": "^2.2.7",
3737
"@web3-onboard/dcent": "^2.2.7",
3838
"@web3-onboard/enkrypt": "^2.0.3",
39+
"@web3-onboard/finoaconnect": "1.0.0-alpha.1",
3940
"@web3-onboard/fortmatic": "^2.0.18",
4041
"@web3-onboard/frame": "^2.0.2",
4142
"@web3-onboard/frontier": "^2.0.3",

packages/demo/src/App.svelte

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import venlyModule from '@web3-onboard/venly'
3636
import bitgetModule from '@web3-onboard/bitget'
3737
import particleAuthModule from '@web3-onboard/particle-network'
38+
import finoaConnectModule from '@web3-onboard/finoaconnect'
3839
import capsuleModule, {
3940
Environment,
4041
OAuthMethod,
@@ -175,6 +176,7 @@
175176
const cedeStore = cedeStoreModule()
176177
const blocto = bloctoModule()
177178
const tallyho = tallyHoModule()
179+
const finoaConnect = finoaConnectModule()
178180
179181
const trezorOptions = {
180182
email: 'test@test.com',
@@ -268,7 +270,8 @@
268270
arcanaAuth,
269271
blocto,
270272
venly,
271-
particle
273+
particle,
274+
finoaConnect
272275
],
273276
// transactionPreview,
274277
gas,

packages/finoaconnect/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# @web3-onboard/finoaconnect
2+
3+
## Wallet module for connecting FinoaConnect SDK to web3-onboard
4+
5+
#### Install
6+
7+
`npm i @web3-onboard/core @web3-onboard/finoaconnect`
8+
9+
## Usage
10+
11+
```typescript
12+
import Onboard from '@web3-onboard/core';
13+
import finoaConnectModule from '@web3-onboard/finoaconnect';
14+
15+
const onboard = Onboard({
16+
// ... other Onboard options
17+
wallets: [
18+
finoaConnectModule()
19+
//... other wallets
20+
]
21+
})
22+
23+
const connectedWallets = await onboard.connectWallet()
24+
console.log(connectedWallets)
25+
```

packages/finoaconnect/package.json

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"name": "@web3-onboard/finoaconnect",
3+
"version": "1.0.0-alpha.1",
4+
"description": "FinoaConnect enables DApp users to use Finoa's Institutional Custody services.",
5+
"keywords": [
6+
"Ethereum",
7+
"Web3",
8+
"EVM",
9+
"dapp",
10+
"Multichain",
11+
"Wallet",
12+
"Transaction",
13+
"Provider",
14+
"Hardware Wallet",
15+
"Notifications",
16+
"React",
17+
"Svelte",
18+
"Vue",
19+
"Next",
20+
"Nuxt",
21+
"MetaMask",
22+
"Coinbase",
23+
"WalletConnect",
24+
"Ledger",
25+
"Trezor",
26+
"Connect Wallet",
27+
"Ethereum Hooks",
28+
"Blocknative",
29+
"Mempool",
30+
"pending",
31+
"confirmed",
32+
"Injected Wallet",
33+
"Crypto",
34+
"Crypto Wallet",
35+
"Tally Ho",
36+
"FinoaConnect"
37+
],
38+
"repository": {
39+
"type": "git",
40+
"url": "https://github.com/blocknative/web3-onboard.git",
41+
"directory": "packages/finoaconnect"
42+
},
43+
"homepage": "https://onboard.blocknative.com",
44+
"bugs": "https://github.com/blocknative/web3-onboard/issues",
45+
"module": "dist/index.js",
46+
"browser": "dist/index.js",
47+
"main": "dist/index.js",
48+
"type": "module",
49+
"typings": "dist/index.d.ts",
50+
"files": [
51+
"dist"
52+
],
53+
"scripts": {
54+
"build": "tsc",
55+
"dev": "tsc -w",
56+
"type-check": "tsc --noEmit"
57+
},
58+
"devDependencies": {
59+
"typescript": "5.1.6"
60+
},
61+
"dependencies": {
62+
"@finoa/finoa-connect-sdk": "^1.0.2",
63+
"@web3-onboard/core": "^2.20.4"
64+
}
65+
66+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export async function request(url: string, call: object): Promise<any> {
2+
// SOURCE: https://github.com/blocknative/web3-onboard/blob/ddfb620c62202b24adfe41994037d9609a697e0d/packages/hw-common/src/index.ts
3+
const response = await fetch(url, {
4+
method: 'POST',
5+
headers: {
6+
'Content-Type': 'application/json'
7+
},
8+
body: JSON.stringify({
9+
jsonrpc: '2.0',
10+
id: '42',
11+
...call
12+
})
13+
})
14+
const json = await response.json()
15+
if ('error' in json) {
16+
throw json.error
17+
}
18+
return json.result
19+
}

packages/finoaconnect/src/icon.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default `
2+
<?xml version="1.0" encoding="utf-8"?>
3+
<svg width="24" height="24" fill="none" xmlns="http://www.w3.org/2000/svg">
4+
<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>
5+
</svg>
6+
`

packages/finoaconnect/src/index.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { FinoaEIP1193Provider } from '@finoa/finoa-connect-sdk'
2+
import type { Chain, WalletInit } from '@web3-onboard/common'
3+
4+
export interface FinoaWalletOption {
5+
url?: string
6+
labelSuffix?: string
7+
}
8+
9+
function finoaConnect(option?: string | FinoaWalletOption): WalletInit {
10+
const { url, labelSuffix }: FinoaWalletOption =
11+
typeof option === 'string' ? { url: option } : !option ? {} : option
12+
13+
return () => {
14+
return {
15+
label: `Finoa Wallet${labelSuffix == null ? '' : ' - ' + labelSuffix}`,
16+
getIcon: async () => (await import('./icon')).default,
17+
getInterface: async ({ chains }) => {
18+
const {
19+
FinoaEIP1193Provider,
20+
FinoaBrowserClient,
21+
UnsupportedRequestError
22+
} = await import('@finoa/finoa-connect-sdk')
23+
24+
const { request } = await import('./fetch-rpc')
25+
26+
const client = new FinoaBrowserClient({
27+
windowUrl: url
28+
})
29+
const provider = new FinoaEIP1193Provider({
30+
client
31+
})
32+
33+
const proxyProvider = new Proxy(provider, {
34+
get(target, property: keyof FinoaEIP1193Provider) {
35+
const source = target[property]
36+
if (property === 'request') {
37+
return async function (
38+
this: FinoaEIP1193Provider,
39+
...args: Parameters<FinoaEIP1193Provider['request']>
40+
) {
41+
try {
42+
return await (source as FinoaEIP1193Provider['request']).call(
43+
this,
44+
...args
45+
)
46+
} catch (err) {
47+
if (err instanceof UnsupportedRequestError) {
48+
let chain: Chain | undefined
49+
try {
50+
const chainIdN = BigInt(err.chainId)
51+
chain = chains.find(
52+
chain => BigInt(chain.id) === chainIdN
53+
)
54+
} catch {
55+
/* empty */
56+
}
57+
if (chain?.rpcUrl == null) {
58+
throw err
59+
}
60+
return await request(chain.rpcUrl, ...args)
61+
}
62+
throw err
63+
}
64+
}
65+
}
66+
return source
67+
}
68+
})
69+
70+
return {
71+
provider: proxyProvider
72+
}
73+
}
74+
}
75+
}
76+
}
77+
78+
export default finoaConnect

packages/finoaconnect/tsconfig.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"include": ["src/**/*"],
4+
5+
"compilerOptions": {
6+
"outDir": "dist",
7+
"rootDir": "src",
8+
"declaration": true,
9+
"declarationDir": "dist",
10+
"allowSyntheticDefaultImports": true,
11+
"paths": {
12+
"*": ["./src/*", "./node_modules/*"]
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)