diff --git a/packages/example/components/LogsContainer.tsx b/packages/example/components/LogsContainer.tsx index 869321fc..1d9af991 100644 --- a/packages/example/components/LogsContainer.tsx +++ b/packages/example/components/LogsContainer.tsx @@ -65,7 +65,7 @@ export const LogsContainer = ({ bridge }: { bridge?: JsBridgeBase } = {}) => { background: 'black', position: 'relative', color: 'white', - height: 300, + height: 340, overflow: 'auto', }} > diff --git a/packages/example/components/PageLayout.tsx b/packages/example/components/PageLayout.tsx new file mode 100644 index 00000000..650e76d6 --- /dev/null +++ b/packages/example/components/PageLayout.tsx @@ -0,0 +1,27 @@ +import Link from 'next/link'; +import styles from '../styles/PageLayout.module.css'; +import { LogsContainer } from './LogsContainer'; + +export type PageLayoutProps = { + children?: React.ReactNode; + title: string; +}; + +function PageLayout({ children, title }: PageLayoutProps) { + return ( +
+
+ + ← Back + +

{title}

+
+
{children}
+
+ +
+
+ ); +} + +export default PageLayout; diff --git a/packages/example/components/aptosMartian/AptosExample.tsx b/packages/example/components/aptosMartian/AptosExample.tsx index 634e7416..2272cc81 100644 --- a/packages/example/components/aptosMartian/AptosExample.tsx +++ b/packages/example/components/aptosMartian/AptosExample.tsx @@ -204,7 +204,7 @@ export default function App() { const getTransaction = async () => { const res = await provider.getTransaction( - '0xbeb1f8c4e66bf0f58afca8c83338fd9a54490d46ce25fe9c8674b67f1e7bbd3a', + '0x407c189992aa2b5a25b3645a3dc6a8b5c9ec2792d214ab9a04b7acc6b7465a00', ); console.log('[getTransaction]', res); }; diff --git a/packages/example/components/sui/SuiExample.tsx b/packages/example/components/sui/SuiExample.tsx deleted file mode 100644 index 4dbd147d..00000000 --- a/packages/example/components/sui/SuiExample.tsx +++ /dev/null @@ -1,267 +0,0 @@ -import React from 'react'; -import { useState, useEffect, useMemo } from 'react'; -import { ProviderSui } from '@onekeyfe/onekey-sui-provider'; - -import { DAppList } from '../dappList/DAppList'; -import { dapps } from './dapps.config'; -import { JsonRpcProvider, MoveCallTransaction, Connection } from '@mysten/sui.js'; -import { buildTransfer } from './utils'; - -declare global { - interface Window { - // @ts-expect-error - suiWallet: ProviderSui; - } -} - -const useProvider = () => { - const [provider, setProvider] = useState(); - - useEffect(() => { - const injectedProvider = window.suiWallet as ProviderSui; - const suiProvider = - injectedProvider || - new ProviderSui({ - // use mock api provider bridge for development - // bridge: new CustomBridge(), - }); - setProvider(suiProvider); - }, []); - - return provider; -}; - -const INIT_MOVE_CALL: MoveCallTransaction = { - kind: 'MoveCall', - target: `0x0000000000000000000000000000000000000002::devnet_nft::mint`, - typeArguments: [], - arguments: [], -}; - -export default function App() { - const provider = useProvider(); - - const [network, setNetwork] = useState('TestNet'); - const [connected, setConnected] = useState(false); - const [address, setAddress] = useState(null); - - const [moveCall, setMoveCall] = useState(INIT_MOVE_CALL); - - const rpcProvider = useMemo(() => { - if (network.toLowerCase() === 'testnet') { - return new JsonRpcProvider( - new Connection({ - fullnode: 'https://fullnode.testnet.sui.io', - faucet: 'https://faucet.testnet.sui.io/gas', - }), - ); - } else { - return new JsonRpcProvider( - new Connection({ - fullnode: 'https://fullnode.devnet.sui.io', - faucet: 'https://faucet.devnet.sui.io/gas', - }), - ); - } - }, [network]); - - useEffect(() => { - if (!provider) return; - // try to eagerly connect - // provider.connect().catch((err) => { - // err; - // // fail silently - // }); - - try { - provider.on('connect', (address: string) => { - setConnected(true); - setAddress(address); - console.log(`suiWallet.on [connect] ${address}`); - }); - } catch (e) { - // ignore - } - try { - provider.on('disconnect', () => { - setAddress(null); - setConnected(false); - console.log('suiWallet.on [disconnect] 👋'); - }); - } catch (e) { - // ignore - } - try { - provider.on('networkChange', (network: string) => { - setNetwork(network); - console.log(`suiWallet.on [networkChange] ${network}`); - }); - } catch (e) { - // ignore - } - try { - provider.on('accountChanged', (address: string) => { - setAddress(address); - setConnected(!!address); - console.log(`suiWallet.on [accountChange] ${address}`); - }); - } catch (e) { - // ignore - } - return () => { - void provider.disconnect(); - }; - }, [provider]); - - if (!provider) { - return

Could not find a provider

; - } - - const hasPermissions = async () => { - try { - const has = await provider.hasPermissions(); - console.log('[hasPermissions]', has); - } catch (err) { - console.warn(err); - console.log(`[error] hasPermissions: ${JSON.stringify(err)}`); - } - }; - - const requestPermissions = async () => { - try { - const has = await provider.requestPermissions(); - console.log('[requestPermissions]', has); - return has; - } catch (err) { - console.warn(err); - console.log(`[error] requestPermissions: ${JSON.stringify(err)}`); - } - }; - - const getAccounts = async () => { - try { - const accounts = await provider.getAccounts(); - console.log('[getAccounts]', accounts); - return accounts; - } catch (err) { - console.warn(err); - console.log(`[error] getAccounts: ${JSON.stringify(err)}`); - } - }; - - const connectWallet = async () => { - try { - const has = await requestPermissions(); - if (has) { - const accounts = await getAccounts(); - setAddress(accounts[0]?.address ?? null); - setNetwork(network); - setConnected(true); - - console.log('[connectWallet] account', accounts, network); - } else { - console.log('[error] connectWallet', has, network); - } - } catch (err) { - console.warn(err); - console.log(`[error] connectWallet: ${JSON.stringify(err)}`); - } - }; - - const requestSuiFromFaucet = async () => { - try { - const faucet = await rpcProvider.requestSuiFromFaucet(address); - console.log('[requestSuiFromFaucet] faucet success:', faucet); - } catch (err) { - console.warn(err); - console.log(`[error] requestSuiFromFaucet: ${JSON.stringify(err)}`); - } - }; - - const disconnectWallet = async () => { - try { - await provider.disconnect(); - } catch (err) { - console.warn(err); - console.log(`[error] disconnect: ${JSON.stringify(err)}`); - } - }; - - const signAndExecuteTransaction = async () => { - try { - const transfer = await buildTransfer(rpcProvider, address, "0xe40a5a0133cac4e9059f58f9d2074a3386d631390e40eadb43d2606e8975f3eb", '100000'); - // const res: unknown = await provider.signAndExecuteTransactionBlock({ - // transactionBlock: transfer, - // }); - - // console.log('[signAndExecuteTransaction]', res); - } catch (err) { - console.warn(err); - console.log(`[error] signAndExecuteTransaction: ${JSON.stringify(err)}`); - } - }; - - return ( -
- - {!provider && ( - - Install OneKey Extension → - - )} -
- {provider && connected ? ( - <> -
-
-                Network:{' '}
-                
-              
-
Connected as: {address}
- -
- -
- - - - - - -
-
-
-
-                {/**/}
-                {/**/}
-              
-