This repository has been archived by the owner on Jun 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: flask 10.17 snap breaking change fix (#206)
* fix: flask 10.17 snap breaking change fix * lint onRpcRequest fix * manifest
- Loading branch information
Showing
6 changed files
with
236 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,92 @@ | ||
import "./snap"; | ||
import { EmptyMetamaskState, Wallet } from "./interfaces"; | ||
import { getAddress } from "./rpc/getAddress"; | ||
import { exportPrivateKey } from "./rpc/exportPrivateKey"; | ||
import { getPublicKey } from "./rpc/getPublicKey"; | ||
import { getApi } from "./filecoin/api"; | ||
import { LotusRpcApi } from "./filecoin/types"; | ||
import { getBalance } from "./rpc/getBalance"; | ||
import { configure } from "./rpc/configure"; | ||
import { getMessages } from "./rpc/getMessages"; | ||
import { signMessage, signMessageRaw } from "./rpc/signMessage"; | ||
import { sendMessage } from "./rpc/sendMessage"; | ||
import { estimateMessageGas } from "./rpc/estimateMessageGas"; | ||
|
||
declare let wallet: Wallet; | ||
|
||
const apiDependentMethods = [ | ||
"fil_getBalance", | ||
"fil_signMessage", | ||
"fil_sendMessage", | ||
"fil_getGasForMessage", | ||
"fil_configure", | ||
]; | ||
// eslint-disable-next-line | ||
module.exports.onRpcRequest = (async ({ origin, request }: { origin: string, request: any }) => { | ||
|
||
const state = await wallet.request({ | ||
method: "snap_manageState", | ||
params: ["get"], | ||
}); | ||
|
||
if (!state) { | ||
// initialize state if empty and set default config | ||
await wallet.request({ | ||
method: "snap_manageState", | ||
params: ["update", EmptyMetamaskState()], | ||
}); | ||
} | ||
|
||
let api: LotusRpcApi; | ||
// initialize lotus RPC api if needed | ||
// eslint-disable-next-line | ||
if (apiDependentMethods.indexOf(request.method) >= 0) { | ||
api = await getApi(wallet); | ||
} | ||
// eslint-disable-next-line | ||
switch (request.method) { | ||
case "fil_configure": { | ||
const resp = await configure( | ||
wallet, | ||
// eslint-disable-next-line | ||
request.params.configuration.network, | ||
// eslint-disable-next-line | ||
request.params.configuration | ||
); | ||
api = resp.api; | ||
return resp.snapConfig; | ||
} | ||
case "fil_getAddress": | ||
return await getAddress(wallet); | ||
case "fil_getPublicKey": | ||
return await getPublicKey(wallet); | ||
case "fil_exportPrivateKey": | ||
return exportPrivateKey(wallet); | ||
case "fil_getBalance": { | ||
const balance = await getBalance(wallet, api); | ||
return balance; | ||
} | ||
case "fil_getMessages": | ||
return getMessages(wallet); | ||
case "fil_signMessage": | ||
// eslint-disable-next-line | ||
return await signMessage(wallet, api, request.params.message); | ||
case "fil_signMessageRaw": | ||
// eslint-disable-next-line | ||
return await signMessageRaw(wallet, request.params.message); | ||
case "fil_sendMessage": | ||
// eslint-disable-next-line | ||
return await sendMessage(wallet, api, request.params.signedMessage); | ||
case "fil_getGasForMessage": | ||
return await estimateMessageGas( | ||
wallet, | ||
api, | ||
// eslint-disable-next-line | ||
request.params.message, | ||
// eslint-disable-next-line | ||
request.params.maxFee | ||
); | ||
default: | ||
throw new Error("Unsupported RPC method"); | ||
} | ||
// eslint-disable-next-line | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.