From 36472e1c7c5a9b35b5d888855d537b87372c70ed Mon Sep 17 00:00:00 2001 From: Evgeny Kuzyakov Date: Tue, 10 Oct 2023 09:41:51 -0700 Subject: [PATCH] WIP. Ability to do meta-txs for premium accounts --- src/App.js | 33 +++++++++++++++++-------------- src/data/wrappedSelector.js | 39 +++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 15 deletions(-) create mode 100644 src/data/wrappedSelector.js diff --git a/src/App.js b/src/App.js index 61564f66..c609102f 100644 --- a/src/App.js +++ b/src/App.js @@ -32,6 +32,7 @@ import { NavigationWrapper } from "./components/navigation/NavigationWrapper"; import { NetworkId, Widgets } from "./data/widgets"; import { useEthersProviderContext } from "./data/web3"; import SignInPage from "./pages/SignInPage"; +import { wrapWalletSelector } from "./data/wrappedSelector"; export const refreshAllowanceObj = {}; const documentationHref = "https://social.near-docs.io/"; @@ -56,21 +57,23 @@ function App(props) { initNear && initNear({ networkId: NetworkId, - selector: setupWalletSelector({ - network: NetworkId, - modules: [ - setupNearWallet(), - setupMyNearWallet(), - setupSender(), - setupHereWallet(), - setupMeteorWallet(), - setupNeth({ - gas: "300000000000000", - bundle: false, - }), - setupNightly(), - ], - }), + selector: wrapWalletSelector( + setupWalletSelector({ + network: NetworkId, + modules: [ + setupNearWallet(), + setupMyNearWallet(), + setupSender(), + setupHereWallet(), + setupMeteorWallet(), + setupNeth({ + gas: "300000000000000", + bundle: false, + }), + setupNightly(), + ], + }) + ), customElements: { Link: (props) => { if (!props.to && props.href) { diff --git a/src/data/wrappedSelector.js b/src/data/wrappedSelector.js new file mode 100644 index 00000000..66f220a9 --- /dev/null +++ b/src/data/wrappedSelector.js @@ -0,0 +1,39 @@ +import { NetworkId } from "./widgets"; + +const MainnetSocialDbContractName = "social.near"; + +export async function wrapWalletSelector(selector) { + selector = await selector; + return { + ...selector, + wallet: async () => { + const wallet = await selector.wallet(); + return { + ...wallet, + signAndSendTransaction: async ({ receiverId, actions }) => { + // TODO: isPremium + const accountId = + selector.store.getState()?.accounts?.[0]?.accountId ?? null; + const isPremium = true; + if ( + NetworkId === "mainnet" && + isPremium && + receiverId === MainnetSocialDbContractName && + actions.length === 1 && + actions[0].type === "FunctionCall" && + actions[0].params.methodName === "set" && + actions[0].params.deposit === "0" + ) { + const [_bytes, signedTransaction] = await wallet.signTransaction({ + receiverId, + actions, + }); + console.log("SENDING SIGNED TRANSACTION", signedTransaction); + // return wallet.sendTransaction(signedTransaction); + } + // return wallet.signAndSendTransaction(receiverId, actions); + }, + }; + }, + }; +}