Skip to content

Commit

Permalink
trigger eth_requestAccounts when wallet_switchEthereumChain and t…
Browse files Browse the repository at this point in the history
…here's no active session (#15)
  • Loading branch information
estebanmino committed May 6, 2024
1 parent 586aa46 commit 649c82f
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 50 deletions.
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "@rainbow-me/provider",
"version": "0.0.7",
"version": "0.0.12",
"main": "dist/index.js",
"license": "MIT",
"files": [
"dist/**/*"
],
"scripts": {
"prepare": "yarn build",
"build": "tsc",
"test": "./scripts/tests.sh",
"lint": "eslint --cache --max-warnings 0",
Expand All @@ -28,7 +29,7 @@
"jsdom": "24.0.0",
"prettier": "3.2.4",
"typescript": "5.3.3",
"vitest": "1.3.1"
"vitest": "1.6.0"
},
"dependencies": {
"@ethersproject/abstract-provider": "5.7.0",
Expand All @@ -37,5 +38,8 @@
"@metamask/eth-sig-util": "7.0.1",
"eventemitter3": "5.0.1",
"viem": "1.21.4"
},
"resolutions": {
"vite": "5.1.7"
}
}
9 changes: 8 additions & 1 deletion src/handleProviderRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,14 @@ export const handleProviderRequest = ({
const supportedChainId = isSupportedChain?.(
Number(proposedChain.chainId),
);
if (!supportedChainId || !activeSession) {
if (!activeSession) {
(await messengerProviderRequest({
method: 'eth_requestAccounts',
id,
params,
meta,
})) as { address: Address; chainId: number };
} else if (!supportedChainId) {
onSwitchEthereumChainNotSupported?.({
proposedChain,
callbackOptions: meta,
Expand Down
94 changes: 47 additions & 47 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -746,44 +746,44 @@
resolved "https://registry.yarnpkg.com/@ungap/structured-clone/-/structured-clone-1.2.0.tgz#756641adb587851b5ccb3e095daf27ae581c8406"
integrity sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==

"@vitest/expect@1.3.1":
version "1.3.1"
resolved "https://registry.yarnpkg.com/@vitest/expect/-/expect-1.3.1.tgz#d4c14b89c43a25fd400a6b941f51ba27fe0cb918"
integrity sha512-xofQFwIzfdmLLlHa6ag0dPV8YsnKOCP1KdAeVVh34vSjN2dcUiXYCD9htu/9eM7t8Xln4v03U9HLxLpPlsXdZw==
"@vitest/expect@1.6.0":
version "1.6.0"
resolved "https://registry.yarnpkg.com/@vitest/expect/-/expect-1.6.0.tgz#0b3ba0914f738508464983f4d811bc122b51fb30"
integrity sha512-ixEvFVQjycy/oNgHjqsL6AZCDduC+tflRluaHIzKIsdbzkLn2U/iBnVeJwB6HsIjQBdfMR8Z0tRxKUsvFJEeWQ==
dependencies:
"@vitest/spy" "1.3.1"
"@vitest/utils" "1.3.1"
"@vitest/spy" "1.6.0"
"@vitest/utils" "1.6.0"
chai "^4.3.10"

"@vitest/runner@1.3.1":
version "1.3.1"
resolved "https://registry.yarnpkg.com/@vitest/runner/-/runner-1.3.1.tgz#e7f96cdf74842934782bfd310eef4b8695bbfa30"
integrity sha512-5FzF9c3jG/z5bgCnjr8j9LNq/9OxV2uEBAITOXfoe3rdZJTdO7jzThth7FXv/6b+kdY65tpRQB7WaKhNZwX+Kg==
"@vitest/runner@1.6.0":
version "1.6.0"
resolved "https://registry.yarnpkg.com/@vitest/runner/-/runner-1.6.0.tgz#a6de49a96cb33b0e3ba0d9064a3e8d6ce2f08825"
integrity sha512-P4xgwPjwesuBiHisAVz/LSSZtDjOTPYZVmNAnpHHSR6ONrf8eCJOFRvUwdHn30F5M1fxhqtl7QZQUk2dprIXAg==
dependencies:
"@vitest/utils" "1.3.1"
"@vitest/utils" "1.6.0"
p-limit "^5.0.0"
pathe "^1.1.1"

"@vitest/snapshot@1.3.1":
version "1.3.1"
resolved "https://registry.yarnpkg.com/@vitest/snapshot/-/snapshot-1.3.1.tgz#193a5d7febf6ec5d22b3f8c5a093f9e4322e7a88"
integrity sha512-EF++BZbt6RZmOlE3SuTPu/NfwBF6q4ABS37HHXzs2LUVPBLx2QoY/K0fKpRChSo8eLiuxcbCVfqKgx/dplCDuQ==
"@vitest/snapshot@1.6.0":
version "1.6.0"
resolved "https://registry.yarnpkg.com/@vitest/snapshot/-/snapshot-1.6.0.tgz#deb7e4498a5299c1198136f56e6e0f692e6af470"
integrity sha512-+Hx43f8Chus+DCmygqqfetcAZrDJwvTj0ymqjQq4CvmpKFSTVteEOBzCusu1x2tt4OJcvBflyHUE0DZSLgEMtQ==
dependencies:
magic-string "^0.30.5"
pathe "^1.1.1"
pretty-format "^29.7.0"

"@vitest/spy@1.3.1":
version "1.3.1"
resolved "https://registry.yarnpkg.com/@vitest/spy/-/spy-1.3.1.tgz#814245d46d011b99edd1c7528f5725c64e85a88b"
integrity sha512-xAcW+S099ylC9VLU7eZfdT9myV67Nor9w9zhf0mGCYJSO+zM2839tOeROTdikOi/8Qeusffvxb/MyBSOja1Uig==
"@vitest/spy@1.6.0":
version "1.6.0"
resolved "https://registry.yarnpkg.com/@vitest/spy/-/spy-1.6.0.tgz#362cbd42ccdb03f1613798fde99799649516906d"
integrity sha512-leUTap6B/cqi/bQkXUu6bQV5TZPx7pmMBKBQiI0rJA8c3pB56ZsaTbREnF7CJfmvAS4V2cXIBAh/3rVwrrCYgw==
dependencies:
tinyspy "^2.2.0"

"@vitest/utils@1.3.1":
version "1.3.1"
resolved "https://registry.yarnpkg.com/@vitest/utils/-/utils-1.3.1.tgz#7b05838654557544f694a372de767fcc9594d61a"
integrity sha512-d3Waie/299qqRyHTm2DjADeTaNdNSVsnwHPWrs20JMpjh6eiVq7ggggweO8rc4arhf6rRkWuHKwvxGvejUXZZQ==
"@vitest/utils@1.6.0":
version "1.6.0"
resolved "https://registry.yarnpkg.com/@vitest/utils/-/utils-1.6.0.tgz#5c5675ca7d6f546a7b4337de9ae882e6c57896a1"
integrity sha512-21cPiuGMoMZwiOHa2i4LXkMkMkCGzA+MVFV70jRwHo95dL4x/ts5GZhML1QWuy7yfp3WzK3lRvZi3JnXTYqrBw==
dependencies:
diff-sequences "^29.6.3"
estree-walker "^3.0.3"
Expand Down Expand Up @@ -2249,10 +2249,10 @@ tinybench@^2.5.1:
resolved "https://registry.yarnpkg.com/tinybench/-/tinybench-2.6.0.tgz#1423284ee22de07c91b3752c048d2764714b341b"
integrity sha512-N8hW3PG/3aOoZAN5V/NSAEDz0ZixDSSt5b/a05iqtpgfLWMSVuCo7w0k2vVvEjdrIoeGqZzweX2WlyioNIHchA==

tinypool@^0.8.2:
version "0.8.2"
resolved "https://registry.yarnpkg.com/tinypool/-/tinypool-0.8.2.tgz#84013b03dc69dacb322563a475d4c0a9be00f82a"
integrity sha512-SUszKYe5wgsxnNOVlBYO6IC+8VGWdVGZWAqUxp3UErNBtptZvWbwyUOyzNL59zigz2rCA92QiL3wvG+JDSdJdQ==
tinypool@^0.8.3:
version "0.8.4"
resolved "https://registry.yarnpkg.com/tinypool/-/tinypool-0.8.4.tgz#e217fe1270d941b39e98c625dcecebb1408c9aa8"
integrity sha512-i11VH5gS6IFeLY3gMBQ00/MmLncVP7JLXOw1vlgkytLmJK7QnEr7NXf0LBdxfmNPAeyetukOk0bOYrJrFGjYJQ==

tinyspy@^2.2.0:
version "2.2.1"
Expand Down Expand Up @@ -2364,38 +2364,38 @@ [email protected]:
isows "1.0.3"
ws "8.13.0"

vite-node@1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/vite-node/-/vite-node-1.3.1.tgz#a93f7372212f5d5df38e945046b945ac3f4855d2"
integrity sha512-azbRrqRxlWTJEVbzInZCTchx0X69M/XPTCz4H+TLvlTcR/xH/3hkRqhOakT41fMJCMzXTu4UvegkZiEoJAWvng==
vite-node@1.6.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/vite-node/-/vite-node-1.6.0.tgz#2c7e61129bfecc759478fa592754fd9704aaba7f"
integrity sha512-de6HJgzC+TFzOu0NTC4RAIsyf/DY/ibWDYQUcuEA84EMHhcefTUGkjFHKKEJhQN4A+6I0u++kr3l36ZF2d7XRw==
dependencies:
cac "^6.7.14"
debug "^4.3.4"
pathe "^1.1.1"
picocolors "^1.0.0"
vite "^5.0.0"

vite@^5.0.0:
version "5.1.4"
resolved "https://registry.yarnpkg.com/vite/-/vite-5.1.4.tgz#14e9d3e7a6e488f36284ef13cebe149f060bcfb6"
integrity sha512-n+MPqzq+d9nMVTKyewqw6kSt+R3CkvF9QAKY8obiQn8g1fwTscKxyfaYnC632HtBXAQGc1Yjomphwn1dtwGAHg==
vite@5.1.7, vite@^5.0.0:
version "5.1.7"
resolved "https://registry.yarnpkg.com/vite/-/vite-5.1.7.tgz#9f685a2c4c70707fef6d37341b0e809c366da619"
integrity sha512-sgnEEFTZYMui/sTlH1/XEnVNHMujOahPLGMxn1+5sIT45Xjng1Ec1K78jRP15dSmVgg5WBin9yO81j3o9OxofA==
dependencies:
esbuild "^0.19.3"
postcss "^8.4.35"
rollup "^4.2.0"
optionalDependencies:
fsevents "~2.3.3"

vitest@1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/vitest/-/vitest-1.3.1.tgz#2d7e9861f030d88a4669392a4aecb40569d90937"
integrity sha512-/1QJqXs8YbCrfv/GPQ05wAZf2eakUPLPa18vkJAKE7RXOKfVHqMZZ1WlTjiwl6Gcn65M5vpNUB6EFLnEdRdEXQ==
dependencies:
"@vitest/expect" "1.3.1"
"@vitest/runner" "1.3.1"
"@vitest/snapshot" "1.3.1"
"@vitest/spy" "1.3.1"
"@vitest/utils" "1.3.1"
vitest@1.6.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/vitest/-/vitest-1.6.0.tgz#9d5ad4752a3c451be919e412c597126cffb9892f"
integrity sha512-H5r/dN06swuFnzNFhq/dnz37bPXnq8xB2xB5JOVk8K09rUtoeNN+LHWkoQ0A/i3hvbUKKcCei9KpbxqHMLhLLA==
dependencies:
"@vitest/expect" "1.6.0"
"@vitest/runner" "1.6.0"
"@vitest/snapshot" "1.6.0"
"@vitest/spy" "1.6.0"
"@vitest/utils" "1.6.0"
acorn-walk "^8.3.2"
chai "^4.3.10"
debug "^4.3.4"
Expand All @@ -2407,9 +2407,9 @@ [email protected]:
std-env "^3.5.0"
strip-literal "^2.0.0"
tinybench "^2.5.1"
tinypool "^0.8.2"
tinypool "^0.8.3"
vite "^5.0.0"
vite-node "1.3.1"
vite-node "1.6.0"
why-is-node-running "^2.2.2"

w3c-xmlserializer@^5.0.0:
Expand Down

0 comments on commit 649c82f

Please sign in to comment.