Skip to content

Commit

Permalink
Merge pull request #1307 from blocknative/release/2.13.0
Browse files Browse the repository at this point in the history
Release 2.13.0
  • Loading branch information
lnbc1QWFyb24 authored Oct 11, 2022
2 parents 4d34a3f + 9e93f1b commit d5e22f5
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/issue-to-notion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ jobs:
-H 'Authorization: Bearer '"$NOTION_TOKEN"'' \
-H "Content-Type: application/json" \
-H "Notion-Version: 2022-02-22" \
--data '{"parent":{"type":"database_id","database_id":"'"$DATABASE_ID"'"},"icon":{"type":"emoji","emoji":"🐛"},"properties":{"Name":{"type":"title","title":[{"type":"text","text":{"content":"'"$(echo $TITLE | tr '"' "'")"'"}}]},"Assigned":{"people":['${people:0:-1}']},"Status":{"select":{"name":"'"$STATUS"'"}},"Flag":{"multi_select":[{"name":"'"$FLAG"'"}]},"Type":{"multi_select":[{"name":"bug"}]},"Project":{"multi_select":[{"name":"'"$PROJECT_NAME"'"}]}},"children":[{"object":"block","type":"bookmark","bookmark":{"url":"'"$ISSUE_URL"'"}}]}'
--data '{"parent":{"type":"database_id","database_id":"'"$DATABASE_ID"'"},"icon":{"type":"emoji","emoji":"🐛"},"properties":{"Name":{"type":"title","title":[{"type":"text","text":{"content":"'"$(echo $TITLE | tr '"' "'")"'"}}]},"Assigned":{"people":['${people:0:-1}']},"Status":{"select":{"name":"'"$STATUS"'"}},"Flag":{"multi_select":[{"name":"'"$FLAG"'"}]},"Database":{"multi_select":[{"name":"'"$DATABASE_NAME"'"}]},"Type":{"multi_select":[{"name":"bug"}]},"Project":{"multi_select":[{"name":"'"$PROJECT_NAME"'"}]}},"children":[{"object":"block","type":"bookmark","bookmark":{"url":"'"$ISSUE_URL"'"}}]}'
env:
NOTION_TOKEN: ${{ secrets.NOTION_TOKEN }}
STATE: ${{ github.event.issue.state }}
ISSUE_URL: ${{ github.event.issue.html_url }}
TITLE: ${{ github.event.issue.title }}
FLAG: Github
DATABASE_NAME: Product
STATUS: Backlog
# Product Work Board
DATABASE_ID: 69f0e513a59d445b87a1baed729c75c5
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web3-onboard-monorepo",
"version": "2.12.0",
"version": "2.13.0",
"private": true,
"workspaces": {
"packages": [
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@web3-onboard/core",
"version": "2.8.5",
"version": "2.9.0",
"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.",
"keywords": [
"Ethereum",
Expand Down
83 changes: 70 additions & 13 deletions packages/core/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import { fromEventPattern, Observable } from 'rxjs'
import { filter, takeUntil, take, share, switchMap } from 'rxjs/operators'
import partition from 'lodash.partition'
import { providers } from 'ethers'
import { weiToEth } from '@web3-onboard/common'
import { disconnectWallet$ } from './streams.js'
import { updateAccount, updateWallet } from './store/actions.js'
import { validEnsChain } from './utils.js'
import disconnect from './disconnect.js'
import { state } from './store/index.js'
import { getBlocknativeSdk } from './services.js'

import type {
ChainId,
Expand All @@ -14,14 +21,14 @@ import type {
SelectAccountsRequest
} from '@web3-onboard/common'

import { weiToEth } from '@web3-onboard/common'
import { disconnectWallet$ } from './streams.js'
import type { Account, Address, Balances, Ens, WalletState } from './types.js'
import { updateAccount, updateWallet } from './store/actions.js'
import { validEnsChain } from './utils.js'
import disconnect from './disconnect.js'
import { state } from './store/index.js'
import { getBlocknativeSdk } from './services.js'
import type {
Account,
Address,
Balances,
Ens,
WalletPermission,
WalletState
} from './types.js'

export const ethersProviders: {
[key: string]: providers.StaticJsonRpcProvider
Expand Down Expand Up @@ -112,6 +119,17 @@ export function trackWallet(

// when account changed, set it to first account and subscribe to events
accountsChanged$.subscribe(async ([address]) => {
// sync accounts with internal state
// in the case of an account has been manually disconnected
try {
await syncWalletConnectedAccounts(label)
} catch (error) {
console.warn(
'Web3Onboard: Error whilst trying to sync connected accounts:',
error
)
}

// no address, then no account connected, so disconnect wallet
// this could happen if user locks wallet,
// or if disconnects app from wallet
Expand Down Expand Up @@ -180,11 +198,12 @@ export function trackWallet(
const balanceProm = getBalance(address, chain)
const account = accounts.find(account => account.address === address)

const ensProm = account.ens
? Promise.resolve(account.ens)
: validEnsChain(connectedWalletChain.id)
? getEns(address, chain)
: Promise.resolve(null)
const ensProm =
account && account.ens
? Promise.resolve(account.ens)
: validEnsChain(connectedWalletChain.id)
? getEns(address, chain)
: Promise.resolve(null)

return Promise.all([Promise.resolve(address), balanceProm, ensProm])
})
Expand Down Expand Up @@ -390,3 +409,41 @@ export function addNewChain(
]
})
}

export async function getPermissions(
provider: EIP1193Provider
): Promise<WalletPermission[]> {
try {
const permissions = (await provider.request({
method: 'wallet_getPermissions'
})) as WalletPermission[]

return Array.isArray(permissions) ? permissions : []
} catch (error) {
return []
}
}

export async function syncWalletConnectedAccounts(
label: WalletState['label']
): Promise<void> {
const wallet = state.get().wallets.find(wallet => wallet.label === label)
const permissions = await getPermissions(wallet.provider)
const accountsPermissions = permissions.find(
({ parentCapability }) => parentCapability === 'eth_accounts'
)

if (accountsPermissions) {
const { value: connectedAccounts } = accountsPermissions.caveats.find(
({ type }) => type === 'restrictReturnedAccounts'
) || { value: null }

if (connectedAccounts) {
const syncedAccounts = wallet.accounts.filter(({ address }) =>
connectedAccounts.includes(address)
)

updateWallet(wallet.label, { ...wallet, accounts: syncedAccounts })
}
}
}
12 changes: 12 additions & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,15 @@ export type DeviceNotBrowser = {
os: null
browser: null
}

export type WalletPermission = {
id: string
parentCapability: string
invoker: string
caveats: {
type: string
value: string[]
}[]

date: number
}
2 changes: 1 addition & 1 deletion packages/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"dependencies": {
"@web3-onboard/coinbase": "^2.1.3",
"@web3-onboard/core": "^2.8.5",
"@web3-onboard/core": "^2.9.0",
"@web3-onboard/dcent": "^2.2.1",
"@web3-onboard/fortmatic": "^2.0.14",
"@web3-onboard/gas": "^2.1.3",
Expand Down

0 comments on commit d5e22f5

Please sign in to comment.