From 940861b3ca0a4f1af84e3c46ddff37d178d3524d Mon Sep 17 00:00:00 2001 From: ByteZhang Date: Fri, 6 Sep 2024 11:39:20 +0800 Subject: [PATCH] chore: ton scam dapp connect --- .../example/components/chains/scdo/rpc.ts | 1 + .../example/components/chains/ton/example.tsx | 59 ++++++++++++++----- .../public/scam-tonconnect-manifest.json | 7 +++ 3 files changed, 51 insertions(+), 16 deletions(-) create mode 100644 packages/example/public/scam-tonconnect-manifest.json diff --git a/packages/example/components/chains/scdo/rpc.ts b/packages/example/components/chains/scdo/rpc.ts index 95bc28b0b..7f75a27f7 100644 --- a/packages/example/components/chains/scdo/rpc.ts +++ b/packages/example/components/chains/scdo/rpc.ts @@ -1,6 +1,7 @@ import type { AxiosInstance } from 'axios'; import Axios from 'axios'; +// https://scdo-project.gitbook.io/scdo-wiki/developer/api/rpc export class ScdoNodeClient { public readonly axios: AxiosInstance; diff --git a/packages/example/components/chains/ton/example.tsx b/packages/example/components/chains/ton/example.tsx index 76e238f78..a84ed4fd8 100644 --- a/packages/example/components/chains/ton/example.tsx +++ b/packages/example/components/chains/ton/example.tsx @@ -12,6 +12,9 @@ import { import InfoLayout from '../../InfoLayout'; import params from './params'; import { TonProofDemoApi } from './TonProofDemoApi'; +import { Switch } from '../../ui/switch'; + +const TON_SCAM_DAPP_ENABLE_KEY = 'ton_scam_dapp_enable'; export function Example() { const userFriendlyAddress = useTonAddress(); @@ -19,11 +22,28 @@ export function Example() { const wallet = useTonWallet(); const [tonConnectUI, setOptions] = useTonConnectUI(); + const enable = localStorage.getItem(TON_SCAM_DAPP_ENABLE_KEY); + return ( <> +
+

伪装欺诈模式

+ { + if (tonConnectUI.connected) { + await tonConnectUI?.disconnect(); + TonProofDemoApi.reset(); + } + if (checked) { + localStorage.setItem(TON_SCAM_DAPP_ENABLE_KEY, 'true'); + } else { + localStorage.removeItem(TON_SCAM_DAPP_ENABLE_KEY); + } + window.location.reload(); + }} /> +
{userFriendlyAddress &&

userFriendlyAddress: {userFriendlyAddress}

} {rawAddress &&

rawAddress: {rawAddress}

} {wallet?.device?.appName &&

Wallet AppName: {wallet?.device?.appName}

} @@ -126,22 +146,29 @@ export function Example() { } export default function App() { + + const enable = localStorage.getItem(TON_SCAM_DAPP_ENABLE_KEY); + + const manifestUrl = enable ? "https://dapp-example.onekeytest.com/scam-tonconnect-manifest.json" : "https://dapp-example.onekeytest.com/tonconnect-manifest.json"; + return ( - - {/* */} - - + <> + + {/* */} + + + ); } diff --git a/packages/example/public/scam-tonconnect-manifest.json b/packages/example/public/scam-tonconnect-manifest.json new file mode 100644 index 000000000..125a5016b --- /dev/null +++ b/packages/example/public/scam-tonconnect-manifest.json @@ -0,0 +1,7 @@ +{ + "url": "https://app.ston.fi/", + "name": "STON.fi", + "iconUrl": "https://static.ston.fi/logo/external-logo.jpg", + "termsOfUseUrl": "https://ston.fi/terms", + "privacyPolicyUrl": "https://ston.fi/privacy" +} \ No newline at end of file