Skip to content

Commit

Permalink
feat: Support tg wallet (#249)
Browse files Browse the repository at this point in the history
* feat: Support solana on mobile

* chore: update versions (alpha) (#225)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* fix: Add deeplink for tw solana on mobile

* chore: update versions (alpha) (#226)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* fix: Add phantom deeplink

* fix: Add deelink for phantom

* chore: update versions (alpha) (#227)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* fix: Update tron dependencies

* chore: update versions (alpha) (#230)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* fix: Fix an issue where solana is disconnected when trust evm wallet is disconnected

* chore: update versions (alpha) (#231)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* feat: Update demo

* fix: Fix the trust wallet will automatically connect when the page loaded

* chore: update versions (alpha) (#232)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* fix: Fix the trust wallet will automatically connect when the page loaded

* docs: Add change log

* chore: update versions (alpha) (#233)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* fix: Use window.trustwallet as TW provider to avoid conflicts

* chore: update versions (alpha) (#234)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* fix: Fix trust issue

* chore: update versions (alpha) (#235)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* fix: Fix binance web3 wallet successfully detected trustwallet on mobile

* chore: update versions (alpha) (#236)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* feat: Support tg wallet

* feat: Support tg wallet

* feat: Support tg wallet

* chore: update versions (alpha) (#237)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* feat: Add new wallet

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 30, 2024
1 parent 9d8e31f commit ca1ae96
Show file tree
Hide file tree
Showing 65 changed files with 3,768 additions and 319 deletions.
5 changes: 5 additions & 0 deletions .changeset/big-donuts-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@node-real/walletkit': patch
---

Support solana on mobile
5 changes: 5 additions & 0 deletions .changeset/chilled-pots-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@node-real/walletkit': patch
---

Fix binance web3 wallet successfully detected trustwallet on mobile
5 changes: 5 additions & 0 deletions .changeset/few-guests-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@node-real/walletkit': patch
---

Fix trust issue
5 changes: 5 additions & 0 deletions .changeset/fuzzy-sheep-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@node-real/walletkit': patch
---

Add new wallet
5 changes: 5 additions & 0 deletions .changeset/happy-countries-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@node-real/walletkit': patch
---

Update tron dependencies
5 changes: 5 additions & 0 deletions .changeset/happy-jobs-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@node-real/walletkit': patch
---

Fix an issue where solana is disconnected when trust evm wallet is disconnected
5 changes: 5 additions & 0 deletions .changeset/itchy-hats-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@node-real/walletkit': patch
---

Add deeplink for tw solana on mobile
5 changes: 5 additions & 0 deletions .changeset/little-panthers-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@node-real/walletkit': patch
---

Fix the trust wallet will automatically connect when the page loaded
5 changes: 5 additions & 0 deletions .changeset/nervous-horses-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@node-real/walletkit': patch
---

Fix the trust wallet will automatically connect when the page loaded
5 changes: 5 additions & 0 deletions .changeset/pink-carrots-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@node-real/walletkit': patch
---

Use window.trustwallet as TW provider to avoid conflicts
23 changes: 23 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"mode": "pre",
"tag": "alpha",
"initialVersions": {
"example-nextjs": "0.0.1",
"example-vite": "0.0.1",
"@node-real/walletkit": "2.4.0",
"website": "0.0.1"
},
"changesets": [
"big-donuts-push",
"chilled-pots-chew",
"few-guests-melt",
"happy-countries-exercise",
"happy-jobs-hope",
"itchy-hats-applaud",
"little-panthers-tickle",
"nervous-horses-study",
"pink-carrots-jam",
"slimy-books-turn",
"wise-days-juggle"
]
}
5 changes: 5 additions & 0 deletions .changeset/slimy-books-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@node-real/walletkit': patch
---

Add deelink for phantom
5 changes: 5 additions & 0 deletions .changeset/wise-days-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@node-real/walletkit': minor
---

Support tg
4 changes: 2 additions & 2 deletions examples/nextjs/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ const config: WalletKitConfig = {
evmConfig: defaultEvmConfig({
autoConnect: true,
initialChainId: 1,
walletConnectProjectId: 'e68a1816d39726c2afabf05661a32767',
walletConnectProjectId: '518ee55b46bc23b5b496b03b1322aa13',
wallets: [metaMask(), trustWallet(), walletConnect()],
chains: [mainnet] as any,
chains: [mainnet],
}),
};

Expand Down
7 changes: 4 additions & 3 deletions examples/vite/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import '@node-real/walletkit/styles.css';
import {
ConnectModal,
useConnectModal,
WalletKitConfig,
WalletKitProvider,
} from '@node-real/walletkit';
import { defaultEvmConfig, metaMask, trustWallet, walletConnect } from '@node-real/walletkit/evm';
import { defaultEvmConfig, trustWallet, metaMask, walletConnect } from '@node-real/walletkit/evm';
import { mainnet } from 'viem/chains';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { useAccount, useDisconnect } from 'wagmi';
Expand All @@ -18,9 +19,9 @@ const config: WalletKitConfig = {
evmConfig: defaultEvmConfig({
autoConnect: true,
initialChainId: 1,
walletConnectProjectId: 'e68a1816d39726c2afabf05661a32767',
walletConnectProjectId: '518ee55b46bc23b5b496b03b1322aa13',
wallets: [metaMask(), trustWallet(), walletConnect()],
chains: [mainnet] as any,
chains: [mainnet],
}),
};

Expand Down
1 change: 0 additions & 1 deletion examples/vite/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import '@node-real/walletkit/styles.css';
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App.tsx';
Expand Down
1 change: 1 addition & 0 deletions examples/vite/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import react from '@vitejs/plugin-react';

// https://vitejs.dev/config/
export default defineConfig({
base: './',
plugins: [react()],
build: {
minify: false,
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"ci:version": "pnpm changeset version && cp README.md packages/walletkit/README.md",
"ci:publish": "pnpm changeset publish",
"ci:alpha-version": "pnpm ci:enter && pnpm ci:version",
"ci:stable-version": "pnpm ci:exit && pnpm ci:version"
"ci:stable-version": "pnpm ci:exit && pnpm ci:version",
"gh-pages": "pnpm build && pnpm --F example-vite build && gh-pages -d examples/vite/dist"
},
"devDependencies": {
"@changesets/cli": "^2.27.10",
Expand All @@ -30,6 +31,7 @@
"eslint-plugin-react-refresh": "^0.3.5",
"husky": "^8.0.3",
"lint-staged": "^15.2.10",
"prettier": "^3.3.3"
"prettier": "^3.3.3",
"gh-pages": "~6.2.0"
}
}
114 changes: 72 additions & 42 deletions packages/walletkit/__dev__/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ import {
defaultSolanaConfig,
useSolanaWallet,
} from '@/solana/index';
import { bsc, mainnet } from 'viem/chains';
import { bsc, mainnet, dfk } from 'viem/chains';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { useAccount, useDisconnect } from 'wagmi';
import { useAccount, useConnectors, useDisconnect } from 'wagmi';
import { defaultTronConfig, tronLink, useTronWallet } from '@/tron/index';
import { uxuyWallet } from '@/evm/wallets/uxuyWallet';
import { useEvmSwitchChain } from '@/evm/hooks/useEvmSwitchChain';
import { codexFieldWallet } from '@/evm/wallets/codexFieldWallet';
import { SwitchNetworkModal } from '@/core/modals/SwitchNetworkModal';

new VConsole();
Expand All @@ -47,32 +50,35 @@ const config: WalletKitConfig = {
evmConfig: defaultEvmConfig({
autoConnect: true,
initialChainId: 1,
walletConnectProjectId: 'e68a1816d39726c2afabf05661a32767',
chains: [mainnet, bsc],
walletConnectProjectId: '518ee55b46bc23b5b496b03b1322aa13',
chains: [mainnet, bsc, dfk],
wallets: [
metaMask(),
trustWallet(),
bitgetWallet(),
coinbaseWallet(),
binanceWeb3Wallet(),
trustWallet(),
walletConnect(),
uxuyWallet(),
codexFieldWallet(),
metaMask(),

tokenPocket(),
okxWallet(),
// bitgetWallet(),
// coinbaseWallet(),

mathWallet(),
walletConnect(),
// tokenPocket(),
// okxWallet(),

// mathWallet(),
],
}),
solanaConfig: defaultSolanaConfig({
autoConnect: true,
rpcUrl: 'https://solana-rpc.debridge.finance',
wallets: [solanaTrustWallet(), solanaPhantomWallet()],
}),
tronConfig: defaultTronConfig({
autoConnect: true,
initialChainId: '0xcd8690dc',
wallets: [tronLink()],
}),
// solanaConfig: defaultSolanaConfig({
// autoConnect: true,
// rpcUrl: 'https://solana-rpc.debridge.finance',
// wallets: [solanaTrustWallet(), solanaPhantomWallet()],
// }),
// tronConfig: defaultTronConfig({
// autoConnect: true,
// initialChainId: '0xcd8690dc',
// wallets: [tronLink()],
// }),
};

export default function App() {
Expand All @@ -91,32 +97,56 @@ function ConnectButton() {
const { onOpen } = useConnectModal();
const { onOpen: openSwitchNetwork } = useSwitchNetworkModal();

const { address } = useAccount();
const { address, chainId } = useAccount();
const { disconnect } = useDisconnect();
const { publicKey, disconnect: solanaDisconnect } = useSolanaWallet();
const { address: tronAddress, disconnect: tronDisconnect } = useTronWallet();
const { switchChain } = useEvmSwitchChain();

const connectors = useConnectors();

connectors?.forEach((e) => {
console.log(e.id);
});

return (
<>
<button
onClick={() =>
onOpen({
action: 'add-network',
evmConfig: {
initialChainId: 56,
},
tronConfig: {
initialChainId: '0xcd8690dc',
},
onConnected(params) {
console.log(params, '====xx');
},
})
}
>
connect
</button>
<button onClick={() => openSwitchNetwork()}>switch network</button>
<div>
<button
onClick={() =>
onOpen({
action: 'add-network',
evmConfig: {
initialChainId: 56,
},
tronConfig: {
initialChainId: '0xcd8690dc',
},
})
}
>
connect
</button>
<button
onClick={() => {
switchChain({
chainId: 1,
});
}}
>
switch 1
</button>
<button
onClick={() => {
switchChain({
chainId: 56,
});
}}
>
switch 56
</button>
</div>
<div>chain id: {chainId}</div>
<div>
evm address:{address} <button onClick={() => disconnect()}>disconnect</button>
</div>
Expand Down
7 changes: 6 additions & 1 deletion packages/walletkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,20 @@
"wagmi": "^2"
},
"dependencies": {
"@binance/w3w-wagmi-connector-v2": "^1.2.3",
"@metamask/jazzicon": "^2",
"@solana/wallet-adapter-react": "^0",
"@solana/wallet-adapter-wallets": "^0",
"@solana/web3.js": "^1",
"@tronweb3/tronwallet-abstract-adapter": "^1",
"@tronweb3/tronwallet-adapter-react-hooks": "^1",
"@tronweb3/tronwallet-adapter-tronlink": "^1.1.11",
"@uxuycom/web3-tg-sdk": "^0.1.5",
"buffer": "^6.0.3",
"codexfield-wallet-connector": "^0.1.44",
"qrcode": "^1",
"tronweb": "~6.0.0"
"tronweb": "~6.0.0",
"vite-plugin-css-injected-by-js": "^3.5.2"
},
"devDependencies": {
"@types/qrcode": "^1.5.5",
Expand Down
8 changes: 8 additions & 0 deletions packages/walletkit/src/core/base/utils/mobile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ export function isMobile(): boolean {
return isAndroid() || isIOS();
}

export function isPC(): boolean {
return !isMobile();
}

export function isBrowser(): boolean {
return !isTMA();
}

// telegram mini app
export function isTMA(): boolean {
if (typeof window === 'undefined') {
Expand Down
Loading

0 comments on commit ca1ae96

Please sign in to comment.