Skip to content

Commit

Permalink
fix: all unsupported methods to return error code 4200
Browse files Browse the repository at this point in the history
  • Loading branch information
finoaamukherjee committed Jun 6, 2024
1 parent c42ec26 commit 9729859
Show file tree
Hide file tree
Showing 4 changed files with 3,629 additions and 38 deletions.
38 changes: 19 additions & 19 deletions docs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2564,10 +2564,10 @@
utf-8-validate "^6.0.3"
uuid "^8.3.2"

"@metamask/sdk-communication-layer@0.18.5":
version "0.18.5"
resolved "https://registry.yarnpkg.com/@metamask/sdk-communication-layer/-/sdk-communication-layer-0.18.5.tgz#4d153512172e6d0ff940f8ff6c50c2796ba49ceb"
integrity sha512-WMf9oJa3rAimjCXMAaaRVFPD0Q6dfZR0r9037KCpD5g9SlVh+TeMISfdQCEKAyhXP3d4CGxmp/Kib8C3mn2YLw==
"@metamask/sdk-communication-layer@0.20.2":
version "0.20.2"
resolved "https://registry.yarnpkg.com/@metamask/sdk-communication-layer/-/sdk-communication-layer-0.20.2.tgz#7f7fd334b2d26abd1a5a1ec1ffadf823a9589344"
integrity sha512-TN+whYbCClFSkx52Ild1RcjoRyz8YZgwNvZeooIcZIvCfBM6U9W5273KGiY7WLc/oO4KKmFk17d7vMO4gNvhhw==
dependencies:
bufferutil "^4.0.8"
date-fns "^2.29.3"
Expand All @@ -2588,10 +2588,10 @@
react-dom "^18.2.0"
react-i18next "^13.2.2"

"@metamask/sdk-install-modal-web@0.18.5":
version "0.18.5"
resolved "https://registry.yarnpkg.com/@metamask/sdk-install-modal-web/-/sdk-install-modal-web-0.18.5.tgz#f074f0c9a9c4d7272004ebf9792ce816418f13e0"
integrity sha512-Wygc0dgr1PwIA/Sg9WW9QWAsQr4G2GV6iveXt2xw8VKW/9cRORWqYukH1NZLr71hBKzi9AKYBU54Tk5Dfg41zg==
"@metamask/sdk-install-modal-web@0.20.2":
version "0.20.2"
resolved "https://registry.yarnpkg.com/@metamask/sdk-install-modal-web/-/sdk-install-modal-web-0.20.2.tgz#1cf0eb3c26291de7598190878fa9a893c4eb2d66"
integrity sha512-0QiaZhV15AGdN1zU2jfTI32eC3YkwEpzDfR9+oiZ9bd2G72c6lYBhTsmDGUd01aP6A+bqJR5PjI8Wh2AWtoLeA==
dependencies:
qr-code-styling "^1.6.0-rc.1"

Expand Down Expand Up @@ -2626,15 +2626,15 @@
util "^0.12.4"
uuid "^8.3.2"

"@metamask/sdk@^0.18.6":
version "0.18.6"
resolved "https://registry.yarnpkg.com/@metamask/sdk/-/sdk-0.18.6.tgz#ac6cfb80d35b179ee6efd9b2b2f6b67e27422e0a"
integrity sha512-ZT8e4BrcWrm44apLb412WR0fDsgeaS8UlI1c0wKRUPu1w/UntpXuUVO+EaY8WDlnOPAiAsjyqWKey64/DfvbXQ==
"@metamask/sdk@^0.20.3":
version "0.20.3"
resolved "https://registry.yarnpkg.com/@metamask/sdk/-/sdk-0.20.3.tgz#73851d68ffe5d45c1872c024182922530b187b7a"
integrity sha512-HZ9NwA+LxiXzuy0YWbWsuD4xejQtp85bhcCAf8UgpA/0dOyF3RS4dKDdBBXSyRgk3RWPjeJgHxioaH4CmBmiRA==
dependencies:
"@metamask/onboarding" "^1.0.1"
"@metamask/providers" "^15.0.0"
"@metamask/sdk-communication-layer" "0.18.5"
"@metamask/sdk-install-modal-web" "0.18.5"
"@metamask/sdk-communication-layer" "0.20.2"
"@metamask/sdk-install-modal-web" "0.20.2"
"@types/dom-screen-wake-lock" "^1.0.0"
bowser "^2.9.0"
cross-fetch "^4.0.0"
Expand Down Expand Up @@ -5380,12 +5380,12 @@
magic-sdk "^8.1.0"
rxjs "^7.5.2"

"@web3-onboard/metamask@^2.0.6":
version "2.0.6"
resolved "https://registry.yarnpkg.com/@web3-onboard/metamask/-/metamask-2.0.6.tgz#9dd59a88e16fa27754f29b54b4656b31ab6e3159"
integrity sha512-hxOdsqEtvohkYSisXqq7CizECmT7o+Qt6Z4zFfB7fgxcKa80mMmN0sgS3kAa3jl7nQ/JuJbhpNZsInbNN5HFnA==
"@web3-onboard/metamask@^2.0.7-alpha.1":
version "2.0.7-alpha-1"
resolved "https://registry.yarnpkg.com/@web3-onboard/metamask/-/metamask-2.0.7-alpha-1.tgz#62dd1616eb6441cf01983ff60ad9448d2ad729bc"
integrity sha512-B2n03aiwwawndyhp8PYOb9wzJrgLLPEtKmwwODnUF15i6dbiqnUVZQDEEg6T00UEKyN/hPzVR7uQbYnH6rLIaA==
dependencies:
"@metamask/sdk" "^0.18.6"
"@metamask/sdk" "^0.20.3"
"@web3-onboard/common" "^2.3.3"

"@web3-onboard/mew-wallet@^2.0.4":
Expand Down
24 changes: 10 additions & 14 deletions packages/finoaconnect/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FinoaEIP1193Provider } from '@finoa/finoa-connect-sdk'
import type { Chain, WalletInit } from '@web3-onboard/common'
import { ProviderRpcError, ProviderRpcErrorCode, type Chain, type 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.
Expand Down Expand Up @@ -42,26 +42,22 @@ function finoaConnect(option?: string | FinoaWalletOption): WalletInit {
this: FinoaEIP1193Provider,
...args: Parameters<FinoaEIP1193Provider['request']>
) {

// if (args[0].method === "eth_getBalance") {
// return ("0xDE0B6B3A7640000")
// }

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 new ProviderRpcError({
code: ProviderRpcErrorCode.UNSUPPORTED_METHOD,
message: `FinoaConnect Provider does not support the requested method: ${args[0].method}`
})
}
throw err
}
Expand Down
Loading

0 comments on commit 9729859

Please sign in to comment.