Skip to content

Commit

Permalink
feat: Support tg wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
wenty22 committed Dec 2, 2024
1 parent 960fdfc commit 86426c0
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 49 deletions.
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
20 changes: 10 additions & 10 deletions packages/walletkit/__dev__/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ const config: WalletKitConfig = {
// 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 Down
2 changes: 1 addition & 1 deletion packages/walletkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"wagmi": "^2"
},
"dependencies": {
"@binance/w3w-wagmi-connector-v2": "1.2.4-alpha.0",
"@binance/w3w-wagmi-connector-v2": "^1.2.3",
"@metamask/jazzicon": "^2",
"@solana/wallet-adapter-react": "^0",
"@solana/wallet-adapter-wallets": "^0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { WalletOption } from './WalletOption';
import { BaseWallet } from '@/core/configs/types';
import { useWalletKit } from '@/core/providers/WalletKitProvider/context';
import { clsWallets, clsNoWalletButton } from './styles.css';
import { isTMA } from '@/core/base/utils/mobile';
import { Reload } from '../Reload';

export function GridLayout(props: { visibleWallets: BaseWallet[] }) {
const { visibleWallets } = props;
Expand All @@ -18,18 +20,24 @@ export function GridLayout(props: { visibleWallets: BaseWallet[] }) {
{visibleWallets?.map((w, index) => <WalletOption key={index} wallet={w} />)}
</ModalBody>

{!options.hideNoWalletCTA && (
{isTMA() ? (
<ModalFooter>
<Button
as="a"
className={cx('wk-nowallet-button', clsNoWalletButton)}
href={options.walletDownloadUrl}
target="_blank"
rel="noopener"
>
<WalletIcon />I don’t have a wallet
</Button>
<Reload />
</ModalFooter>
) : (
!options.hideNoWalletCTA && (
<ModalFooter>
<Button
as="a"
className={cx('wk-nowallet-button', clsNoWalletButton)}
href={options.walletDownloadUrl}
target="_blank"
rel="noopener"
>
<WalletIcon />I don’t have a wallet
</Button>
</ModalFooter>
)
)}
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { useWalletKit } from '@/core/providers/WalletKitProvider/context';
import { clsWallets, clsNoWalletLink } from './styles.css';
import { WalletOption } from './WalletOption';
import { BaseWallet } from '@/core/configs/types';
import { isTMA } from '@/core/base/utils/mobile';
import { Reload } from '../Reload';

export function ListLayout(props: { visibleWallets: BaseWallet[] }) {
const { visibleWallets } = props;
Expand All @@ -18,15 +20,21 @@ export function ListLayout(props: { visibleWallets: BaseWallet[] }) {
{visibleWallets?.map((w, index) => <WalletOption key={index} wallet={w} />)}
</ModalBody>

{!options.hideNoWalletCTA && (
{isTMA() ? (
<ModalFooter>
<Link
className={cx('wk-nowallet-link', clsNoWalletLink)}
href={options.walletDownloadUrl}
>
<WalletIcon />I don’t have a wallet
</Link>
<Reload />
</ModalFooter>
) : (
!options.hideNoWalletCTA && (
<ModalFooter>
<Link
className={cx('wk-nowallet-link', clsNoWalletLink)}
href={options.walletDownloadUrl}
>
<WalletIcon />I don’t have a wallet
</Link>
</ModalFooter>
)
)}
</>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Box } from '@/core/base/components/Box';

import { cx } from '@/core/base/utils/css';
import { clsContent, clsReloadBtn } from './style.css';
import { Link } from '@/core/base/components/Link';

export function Reload() {
return (
<Box className={cx('wk-reload-wrapper', clsContent)}>
No response on wallet?
<Box>
<Link
className={cx('wk-reload', clsReloadBtn)}
onClick={() => {
window.location.reload();
}}
>
Reload
</Link>
</Box>
</Box>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { style } from '@vanilla-extract/css';

export const clsContent = style({
fontSize: '16px',
lineHeight: '24px',
display: 'flex',
alignItems: 'center',
width: '100%',
justifyContent: 'center',
});

export const clsReloadBtn = style({
width: '100%',
marginLeft: '4px',
textDecoration: 'underline',
cursor: 'pointer',
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isMobile, isTMA } from '@/core/base/utils/mobile';
import { isMobile, isPC, isTMA } from '@/core/base/utils/mobile';
import { UseWalletRenderProps } from '@/core/hooks/useWalletRender';
import { useConnectModal } from '@/core/modals/ConnectModal/context';
import { ViewRoutes } from '@/core/modals/ConnectModal/RouteProvider';
Expand Down Expand Up @@ -84,7 +84,7 @@ export function SetEvmWalletClickRef(props: SetEvmWalletClickRefProps) {
disconnect();
clearTimeout(timerRef.current);

const useSDK = [binanceWeb3Wallet().id].includes(walletId);
const useSDK = [binanceWeb3Wallet().id].includes(walletId) && isPC();
const delay = useSDK ? 0 : 300;

const handleJumping = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { binanceWeb3WalletConfig } from '@/core/configs/binanceWeb3Wallet';
import { EvmWallet } from '../types';
import { BinanceW3WParameters, getWagmiConnectorV2 } from '@binance/w3w-wagmi-connector-v2';
import { isAndroid, isTMA } from '@/core/base/utils/mobile';

export interface BinanceWeb3WalletOptions extends Partial<EvmWallet> {
connectorOptions?: BinanceW3WParameters;
Expand All @@ -21,8 +22,12 @@ export function binanceWeb3Wallet(props: BinanceWeb3WalletOptions = {}): EvmWall
getDeepLink() {
return undefined;
},
getUri() {
return undefined;
getUri(uri) {
let encodedUri = encodeURIComponent(uri);
if (isTMA() && isAndroid()) {
encodedUri = encodeURIComponent(encodedUri);
}
return `https://app.binance.com/cedefi/wc?uri=${encodedUri}`;
},
getCreateConnectorFn() {
const connector = getWagmiConnectorV2();
Expand Down
34 changes: 17 additions & 17 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 86426c0

Please sign in to comment.