Skip to content

Commit

Permalink
feat: support blocto.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew54068 committed Aug 21, 2023
1 parent 2e8660b commit fd554d1
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 13 deletions.
3 changes: 2 additions & 1 deletion example/components/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { MetaMask } from '@web3-react/metamask'
import type { Network } from '@web3-react/network'
import type { WalletConnect } from '@web3-react/walletconnect'
import type { WalletConnect as WalletConnectV2 } from '@web3-react/walletconnect-v2'
import type { BloctoConnector } from '@blocto/web3-react-connector'

import { getName } from '../utils'
import { Accounts } from './Accounts'
Expand All @@ -13,7 +14,7 @@ import { ConnectWithSelect } from './ConnectWithSelect'
import { Status } from './Status'

interface Props {
connector: MetaMask | WalletConnect | WalletConnectV2 | CoinbaseWallet | Network | GnosisSafe
connector: MetaMask | WalletConnect | WalletConnectV2 | CoinbaseWallet | Network | GnosisSafe | BloctoConnector
activeChainId: ReturnType<Web3ReactHooks['useChainId']>
chainIds?: ReturnType<Web3ReactHooks['useChainId']>[]
isActivating: ReturnType<Web3ReactHooks['useIsActivating']>
Expand Down
4 changes: 3 additions & 1 deletion example/components/ProviderExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import { hooks as metaMaskHooks, metaMask } from '../connectors/metaMask'
import { hooks as networkHooks, network } from '../connectors/network'
import { hooks as walletConnectHooks, walletConnect } from '../connectors/walletConnect'
import { hooks as walletConnectV2Hooks, walletConnectV2 } from '../connectors/walletConnectV2'
import { hooks as bloctoHooks , bloctoSDK } from '../connectors/bloctoSdk'
import { getName } from '../utils'

const connectors: [MetaMask | WalletConnect | WalletConnectV2 | CoinbaseWallet | Network, Web3ReactHooks][] = [
const connectors: [bloctoSDK | MetaMask | WalletConnect | WalletConnectV2 | CoinbaseWallet | Network, Web3ReactHooks][] = [
[bloctoSDK, bloctoHooks],
[metaMask, metaMaskHooks],
[walletConnect, walletConnectHooks],
[walletConnectV2, walletConnectV2Hooks],
Expand Down
36 changes: 36 additions & 0 deletions example/components/connectorCards/BloctoCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { useState } from 'react'
import { TESTNET_CHAINS } from '../../chains'
import { bloctoSDK, hooks } from '../../connectors/bloctoSdk'
import { Card } from '../Card'

const CHAIN_IDS = Object.keys(TESTNET_CHAINS).map(Number)

const { useChainId, useAccounts, useIsActivating, useIsActive, useProvider, useENSNames } = hooks

export default function BloctoCard() {
const chainId = useChainId()
const accounts = useAccounts()
const isActivating = useIsActivating()

const isActive = useIsActive()

const provider = useProvider()
const ENSNames = useENSNames(provider)

const [error, setError] = useState(undefined)

return (
<Card
connector={bloctoSDK}
activeChainId={chainId}
chainIds={CHAIN_IDS}
isActivating={isActivating}
isActive={isActive}
error={error}
setError={setError}
accounts={accounts}
provider={provider}
ENSNames={ENSNames}
/>
)
}
14 changes: 14 additions & 0 deletions example/connectors/bloctoSdk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { BloctoConnector } from '@blocto/web3-react-connector'
import { initializeConnector } from '@web3-react/core'
import { URLS } from '../chains'

export const [bloctoSDK, hooks] = initializeConnector<BloctoConnector>(
(actions) =>
new BloctoConnector({
actions,
options: {
chainId: 1,
rpc: URLS[1][0],
},
})
)
1 change: 1 addition & 0 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"start": "next dev"
},
"dependencies": {
"@blocto/web3-react-connector": "^1.0.0",
"@ethersproject/bignumber": "^5.6.0",
"@ethersproject/experimental": "^5.6.0",
"@ethersproject/providers": "^5.6.0",
Expand Down
7 changes: 2 additions & 5 deletions example/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ import MetaMaskCard from '../components/connectorCards/MetaMaskCard'
import NetworkCard from '../components/connectorCards/NetworkCard'
import WalletConnectV2Card from '../components/connectorCards/WalletConnectV2Card'
import ProviderExample from '../components/ProviderExample'
import BloctoCard from '../components/connectorCards/BloctoCard'

export default function Home() {
return (
<>
<ProviderExample />
<div style={{ display: 'flex', flexFlow: 'wrap', fontFamily: 'sans-serif' }}>
<MetaMaskCard />
<WalletConnectV2Card />
<CoinbaseWalletCard />
<NetworkCard />
<GnosisSafeCard />
<BloctoCard />
</div>
</>
)
Expand Down
2 changes: 2 additions & 0 deletions example/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Network } from '@web3-react/network'
import type { Connector } from '@web3-react/types'
import { WalletConnect as WalletConnect } from '@web3-react/walletconnect'
import { WalletConnect as WalletConnectV2 } from '@web3-react/walletconnect-v2'
import { BloctoConnector } from '@blocto/web3-react-connector'

export function getName(connector: Connector) {
if (connector instanceof MetaMask) return 'MetaMask'
Expand All @@ -13,5 +14,6 @@ export function getName(connector: Connector) {
if (connector instanceof CoinbaseWallet) return 'Coinbase Wallet'
if (connector instanceof Network) return 'Network'
if (connector instanceof GnosisSafe) return 'Gnosis Safe'
if (connector instanceof BloctoConnector) return 'Blocto'
return 'Unknown'
}
47 changes: 41 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,24 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==

"@blocto/sdk@^0.5.5":
version "0.5.5"
resolved "https://registry.yarnpkg.com/@blocto/sdk/-/sdk-0.5.5.tgz#807b9eaeee924c3eb0c5517c6b32891025f1f6b0"
integrity sha512-u7bbAYmYDCf0QWvXleVOTeGFRbo8evT3uacsLJ6dv01HspmLDKZWjFyu7i3ARebJTpenHvwM78XHV7KTvBqTRg==
dependencies:
bs58 "^5.0.0"
buffer "^6.0.3"
eip1193-provider "^1.0.1"
js-sha3 "^0.8.0"

"@blocto/web3-react-connector@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@blocto/web3-react-connector/-/web3-react-connector-1.0.0.tgz#22c62918c260fe2df5a8fbe1f79deef685998689"
integrity sha512-p3lo7K4Y86P50d6LxbxbSiN4ungg1wNmU85F0OEYDUK8NW8l/opG2EeeodFYSOo+MB7BgiaGMN9m+vPzrn+4pQ==
dependencies:
"@blocto/sdk" "^0.5.5"
"@web3-react/types" "^8.1.2-beta.0"

"@coinbase/wallet-sdk@^3.3.0":
version "3.3.0"
resolved "https://registry.yarnpkg.com/@coinbase/wallet-sdk/-/wallet-sdk-3.3.0.tgz#e77383bce1388e5367dc35f8309702e73be47503"
Expand Down Expand Up @@ -3547,6 +3565,11 @@ base-x@^3.0.2:
dependencies:
safe-buffer "^5.0.1"

base-x@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/base-x/-/base-x-4.0.0.tgz#d0e3b7753450c73f8ad2389b5c018a4af7b2224a"
integrity sha512-FuwxlW4H5kh37X/oW59pwTzzTKRzfrrQwhmyspRM7swOEZcHtDZSCt45U6oKgtuFE+WYPblePMVIPR4RZrh/hw==

base64-js@^1.3.1:
version "1.5.1"
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a"
Expand Down Expand Up @@ -3677,6 +3700,13 @@ bs58@^4.0.0:
dependencies:
base-x "^3.0.2"

bs58@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/bs58/-/bs58-5.0.0.tgz#865575b4d13c09ea2a84622df6c8cbeb54ffc279"
integrity sha512-r+ihvQJvahgYT50JD05dyJNKlmmSlMoOGwn1lCcEzanPglg7TxYjioQUYehQ9mAR/+hOSd2jRc/Z2y5UxBymvQ==
dependencies:
base-x "^4.0.0"

bs58check@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/bs58check/-/bs58check-2.1.2.tgz#53b018291228d82a5aa08e7d796fdafda54aebfc"
Expand Down Expand Up @@ -3833,11 +3863,16 @@ camelcase@^6.2.0:
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.3.0.tgz#5685b95eb209ac9c0c177467778c9c84df58ba9a"
integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==

caniuse-lite@^1.0.30001286, caniuse-lite@^1.0.30001406:
caniuse-lite@^1.0.30001286:
version "1.0.30001451"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001451.tgz#2e197c698fc1373d63e1406d6607ea4617c613f1"
integrity sha512-XY7UbUpGRatZzoRft//5xOa69/1iGJRBlrieH6QYrkKLIFn3m7OVEJ81dSrKoy2BnKsdbX5cLrOispZNYo9v2w==

caniuse-lite@^1.0.30001406:
version "1.0.30001519"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001519.tgz#3e7b8b8a7077e78b0eb054d69e6edf5c7df35601"
integrity sha512-0QHgqR+Jv4bxHMp8kZ1Kn8CH55OikjKJ6JmKkZYP1F3D7w+lnFXF70nG5eNfsZS89jadi5Ywy5UCSKLAglIRkg==

chalk@^2.0.0:
version "2.4.2"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424"
Expand Down Expand Up @@ -4489,7 +4524,7 @@ eastasianwidth@^0.2.0:
resolved "https://registry.yarnpkg.com/eastasianwidth/-/eastasianwidth-0.2.0.tgz#696ce2ec0aa0e6ea93a397ffcf24aa7840c827cb"
integrity sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==

[email protected]:
[email protected], eip1193-provider@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/eip1193-provider/-/eip1193-provider-1.0.1.tgz#420d29cf4f6c443e3f32e718fb16fafb250637c3"
integrity sha512-kSuqwQ26d7CzuS/t3yRXo2Su2cVH0QfvyKbr2H7Be7O5YDyIq4hQGCNTo5wRdP07bt+E2R/8nPCzey4ojBHf7g==
Expand Down Expand Up @@ -6719,7 +6754,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/js-sha256/-/js-sha256-0.9.0.tgz#0b89ac166583e91ef9123644bd3c5334ce9d0966"
integrity sha512-sga3MHh9sgQN2+pJ9VYZ+1LPwXOxuBJBA5nrR5/ofPfuiJBE2hnjsaN8se8JznOmGLN2p49Pe5U/ttafcs/apA==

[email protected]:
[email protected], js-sha3@^0.8.0:
version "0.8.0"
resolved "https://registry.yarnpkg.com/js-sha3/-/js-sha3-0.8.0.tgz#b9b7a5da73afad7dedd0f8c463954cbde6818840"
integrity sha512-gF1cRrHhIzNfToc802P800N8PpXS+evLLXfsVpowqmAFR9uwbi89WvXg2QspOmXL8QL86J4T1EpFu+yUkwJY3Q==
Expand Down Expand Up @@ -7473,9 +7508,9 @@ [email protected], mute-stream@~0.0.4:
integrity sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==

nanoid@^3.3.4:
version "3.3.4"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.4.tgz#730b67e3cd09e2deacf03c027c81c9d9dbc5e8ab"
integrity sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==
version "3.3.6"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.6.tgz#443380c856d6e9f9824267d960b4236ad583ea4c"
integrity sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==

natural-compare-lite@^1.4.0:
version "1.4.0"
Expand Down

0 comments on commit fd554d1

Please sign in to comment.