如何深度链接 react native dapp 与 testnet btc 钱包?

问题描述 投票:0回答:0

我们正在尝试使用深度链接将比特币测试网钱包与 React 原生 dapp 集成。这样,当用户尝试发送 btc 时,他将被定向到比特币测试网钱包,一旦提交交易,用户将被重定向回本地 dapp。

尝试了以下代码示例:

意图使用:

 <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="myapp" />
        </intent-filter>

使用的深层链接:

bitcoin:${bitcoinAddress}?amount=${amount}&label=${label}&message=${message}&r=${encodeURIComponent(
      redirectUrl
    )}&callback=${encodeURIComponent(callbackUrl)}

使用的钱包应用程序: https://play.google.com/store/apps/details?id=de.schildbach.wallet_test&hl=en&gl=US

import React, { AppState,useEffect } from "react";
import { Linking, View, Button } from "react-native";

const App = () => {
  const onPressHandler = () => {
    const bitcoinAddress = "2NCXR2f6QsrUf4Kfpz99bctNA96vUw9j4bP";
    const amount = "0.000001";
    const label = "Test transaction";
    const message = "This is a test transaction";
    const callbackUrl = "myapp://transaction_callback";
    const redirectUrl = "myapp://redirect_back";

    // Create the deep link URL with the callback and redirect URLs
    const deepLinkUrl = `bitcoin:${bitcoinAddress}?amount=${amount}&label=${label}&message=${message}&r=${encodeURIComponent(
      redirectUrl
    )}&callback=${encodeURIComponent(callbackUrl)}`;

    // Open the deep link URL in the user's Bitcoin wallet app
    Linking.openURL(deepLinkUrl);
  };

  function handleUrl(url) {
    // Handle the deep link URL here
    console.log('Received deep link:', url);
  }
  
  function handleAppStateChange(appState) {
    if (appState === 'active') {
      Linking.getInitialURL().then(url => {
        console.log("test herrr")
        handleUrl(url)
      });
    }
  }

  useEffect(() => {
    AppState.addEventListener('change', handleAppStateChange);
    return () => AppState.removeEventListener('change', handleAppStateChange);

  }, []);

  return (
    // your app code here
    <View>
      <Text>test</Text>
      <Button title="Press me" onPress={onPressHandler} color="#841584" />
    </View>
  );
};

export default App;

上面的代码重定向但是为 getInitialUrl 方法返回一个空的 url 并且不调用任何监听器,是否有任何其他钱包支持重定向回 dapp 并支持测试网?

android react-native deep-linking bitcoin bitcoin-testnet
© www.soinside.com 2019 - 2024. All rights reserved.