Feature #1480: Handle rpc calls from apps SDK (#1519)

* sdk version update

* point sdk to a newer commit

* Update iframe message handler

* ConfirmTransactionModal tweaks to support params

* handle sendTransactionsWithParams, display safeTxGas in app tx modal

* new sdk version

* yarn lock update

* install libudev in travis

* update sdk version

* Estimating safeTxGas for Safe Apps Txs WIP

* safetxgas estimation warning wip

* gas estimation in confirm transaction modal

* yarn lock update

* update sdk version

* add handler for rpc calls

* use send method

* update sdk version

* dep bump

* wip

* update sdk

* remove unused interface and console.log

* remove async, tweak check for send func

Co-authored-by: Daniel Sanchez <daniel.sanchez@gnosis.pm>
Co-authored-by: nicolas <nicosampler@users.noreply.github.com>
This commit is contained in:
Mikhail Mikheev 2020-10-26 13:53:01 +04:00 committed by GitHub
parent 5f3a9ef1a9
commit 1c53167a9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 892 additions and 36 deletions

View File

@ -163,7 +163,7 @@
]
},
"dependencies": {
"@gnosis.pm/safe-apps-sdk": "https://github.com/gnosis/safe-apps-sdk#a6c168b",
"@gnosis.pm/safe-apps-sdk": "https://github.com/gnosis/safe-apps-sdk.git#3f0689f",
"@gnosis.pm/safe-contracts": "1.1.1-dev.2",
"@gnosis.pm/safe-react-components": "https://github.com/gnosis/safe-react-components.git#70e57bdd1e0fd5dfdf5768076577c1e000b5fe28",
"@gnosis.pm/util-contracts": "2.0.6",

View File

@ -19,6 +19,7 @@ import {
safeNameSelector,
safeParamAddressFromStateSelector,
} from 'src/logic/safe/store/selectors'
import { web3ReadOnly } from 'src/logic/wallets/getWeb3'
import { SafeApp } from 'src/routes/safe/components/Apps/types.d'
type InterfaceMessageProps<T extends InterfaceMessageIds> = {
@ -38,10 +39,6 @@ interface CustomMessageEvent extends MessageEvent {
}
}
interface InterfaceMessageRequest extends InterfaceMessageProps<InterfaceMessageIds> {
requestId: number | string
}
const NETWORK_NAME = getNetworkName()
const useIframeMessageHandler = (
@ -75,7 +72,7 @@ const useIframeMessageHandler = (
messageId: SDKMessageIds,
messagePayload: SDKMessageToPayload[typeof messageId],
requestId: RequestId,
) => {
): void => {
if (!messageId) {
console.error('ThirdPartyApp: A message was received without message id.')
return
@ -104,6 +101,36 @@ const useIframeMessageHandler = (
break
}
case SDK_MESSAGES.RPC_CALL: {
const payload = messagePayload as SDKMessageToPayload['RPC_CALL']
if (
web3ReadOnly.currentProvider !== null &&
typeof web3ReadOnly.currentProvider !== 'string' &&
'send' in web3ReadOnly.currentProvider
) {
web3ReadOnly.currentProvider?.send?.(
{
jsonrpc: '2.0',
method: payload?.call,
params: payload?.params,
id: '1',
},
(err, res) => {
if (!err) {
const rpcCallMsg = {
messageId: INTERFACE_MESSAGES.RPC_CALL_RESPONSE,
data: res,
}
sendMessageToIframe(rpcCallMsg, requestId)
}
},
)
}
break
}
case SDK_MESSAGES.SAFE_APP_SDK_INITIALIZED: {
const safeInfoMessage = {
messageId: INTERFACE_MESSAGES.ON_SAFE_INFO,

889
yarn.lock

File diff suppressed because it is too large Load Diff