账户在[payable]方法中收到一定数量的余额后重定向页面?

Redirect the page after the account received some amount of balance in [payable] method?

当我使用payable方式时,页面跳转至钱包审批金额,但跳转后returns到旧页面,跳转后下方代码不是[=23] =].

这里是 rust 合约函数:

#[payable]
pub fn add_liquidity(&mut self, tokens: u128, account_id: AccountId) -> u128 {
        let amount = env::attached_deposit();
}

这里是reactjs代码:

onSubmit={async (values, actions) => {
  try {
        const data = await nearvar.contract.add_liquidity({"tokens": values.buy.toString(), "account_id": "amiyarust.testnet"}, 95000000000000, 500)
        // Page redirects here. Code below is not run. 
        actions.setSubmitting(false)
        history.push(`/hello`)
    } catch (e) {
       console.error(e)
   }

我想 运行 history.push(`/hello`) 重定向后。
但它会刷新页面,并再次呈现表单。 怎么解决?

您必须在重定向之前在 localStorage 中存储一些内容。

例如您预计在重定向之前帐户会发生什么情况?

类似于他们当前的余额,您还希望它增加 1 N。

然后他们被重定向回您的页面,您应该检查这种情况,然后继续您的其余代码。

这里有一个例子:

https://github.com/near-examples/nearnames/blob/54dd7dd1c6adca4688c76c78db3ea6bd10ed2a13/src/state/near.js#L93-L110

具体来说: https://github.com/near-examples/nearnames/blob/54dd7dd1c6adca4688c76c78db3ea6bd10ed2a13/src/state/near.js#L106

在此处重新阅读重定向: https://github.com/near-examples/nearnames/blob/54dd7dd1c6adca4688c76c78db3ea6bd10ed2a13/src/state/near.js#L55

所以这个应用程序“知道”待处理的交易(应该创建的帐户),然后当用户被重定向时,应用程序检查帐户是否真的是通过 TX 创建的。

然后你可以显示这些链接等...