Skip to content

Commit

Permalink
Merge pull request #33 from router-protocol/revert-31-remove/near
Browse files Browse the repository at this point in the history
Revert "remove: near"
  • Loading branch information
jayeshbhole-rp authored Dec 26, 2024
2 parents adb83bf + 7166f32 commit 3add320
Show file tree
Hide file tree
Showing 32 changed files with 2,982 additions and 73 deletions.
47 changes: 47 additions & 0 deletions example-next/src/app/wallets/mynearwallet/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use client';

import { useConnect, useWallets } from '@tangled3/react';
import { useEffect } from 'react';

export default function NearPage() {
const { connect, isLoading, error } = useConnect();
const wallets = useWallets();

const getNearContractId = (chainType: unknown) => {
// TODO: add contractId for both 'testnet' & 'mainnet'
if (chainType === 'near') {
return 'usdt.tether-token.near'; // For testnet: 'routetoken.i-swap.testnet'
}
};

useEffect(() => {
if (wallets.near.length > 0) {
connect(
{ walletId: 'my-near-wallet', chainType: 'near', nearContractId: getNearContractId('near') },
{
onSuccess: () => {
window.location.href = '/';
},
onError: (err) => {
console.error('Failed to connect:', err);
},
},
);
}
}, [wallets]);

if (isLoading) {
return <div>Connecting to wallet...</div>;
}

if (error) {
return <div>Error connecting to wallet: {error.message}</div>;
}

return (
<div>
<h1 className='text-lg font-semibold'>Oh, I see you're trying to connect to My Near Wallet.</h1>
<h2 className='text-center text-neutral-300 mt-2'>Please wait...</h2>
</div>
);
}
1 change: 1 addition & 0 deletions example-next/src/components/Providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const Providers = ({ children }: { children: ReactNode }) => {
twaReturnUrl: `${window.location.origin}/` as `${string}://${string}`,
projectId: '41980758771052df3f01be0a46f172a5',
tonconnectManifestUrl: `${window.location.origin}/tonconnect-manifest.json`,
nearNetwork: 'mainnet',
bitcoinNetwork: 'mainnet',
}}
>
Expand Down
31 changes: 14 additions & 17 deletions example-next/src/components/Tokens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,128 +63,125 @@ const tokens: TokenMetadata[] = [
name: 'OSMO',
symbol: 'OSMO',
chainId: 'osmosis-1',
isNative: true,
},
{
address: ETH_ADDRESS,
decimals: 18,
name: 'Ether',
symbol: 'ETH',
chainId: '1',
isNative: true,
},
{
address: '',
decimals: 18,
name: 'Polygon MATIC',
symbol: 'MATIC',
chainId: '137',
isNative: true,
},
{
address: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
decimals: 6,
name: 'USDC',
symbol: 'USDC',
chainId: '42161',
isNative: false,
},
{
address: SOL_ADDRESS,
decimals: 9,
name: 'Solana SOL',
symbol: 'SOL',
chainId: 'solana',
isNative: true,
},
{
address: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
decimals: 6,
name: 'USDC',
symbol: 'USDC',
chainId: 'solana',
isNative: false,
},
{
address: 'So11111111111111111111111111111111111111112',
decimals: 9,
name: 'Wrapped SOL',
symbol: 'WSOL',
chainId: 'solana',
isNative: false,
},
{
address: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB',
decimals: 6,
name: 'USDT',
symbol: 'USDT',
chainId: 'solana',
isNative: false,
},
{
address: ETH_ADDRESS,
decimals: 6,
name: 'Tron TRX',
symbol: 'TRX',
chainId: '728126428',
isNative: true,
},
{
address: 'TEkxiTehnzSmSe2XqrBj4w32RUN966rdz8',
decimals: 6,
name: 'Tron USDC',
symbol: 'USDC',
chainId: '728126428',
isNative: false,
},
{
address: ETH_ADDRESS,
decimals: 9,
name: 'Toncoin',
symbol: 'TON',
chainId: '-239',
isNative: true,
},
{
address: 'EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs',
decimals: 6,
name: 'Tether USD',
symbol: 'USDT',
chainId: '-239',
isNative: false,
},
{
address: ETH_ADDRESS,
decimals: 8,
name: 'Bitcoin',
symbol: 'BTC',
chainId: 'bitcoin',
isNative: true,
},

{
address: ETH_ADDRESS,
decimals: 24,
name: 'NEAR',
symbol: 'NEAR',
chainId: '397',
},
{
address: 'usdt.tether-token.near',
decimals: 6,
name: 'Tether USD',
symbol: 'USDt',
chainId: '397',
},
{
address: '0x2::sui::SUI',
decimals: 9,
name: 'Sui Token',
symbol: 'SUI',
chainId: 'sui',
isNative: true,
},
{
address: '0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN',
decimals: 6,
name: 'Tether USD',
symbol: 'USDT',
chainId: 'sui',
isNative: false,
},
{
address: '0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC',
decimals: 6,
name: 'USDC',
symbol: 'USDC',
chainId: 'sui',
isNative: false,
},
];

Expand Down
11 changes: 10 additions & 1 deletion example-next/src/components/WalletList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ const WalletList = () => {
const wallets = useWallets();
const { connect } = useConnect();

const getNearContractId = (chainType: unknown) => {
// TODO: add contractId for both 'testnet' & 'mainnet'
if (chainType === 'near') {
return 'usdt.tether-token.near'; // For testnet: 'routetoken.i-swap.testnet'
}
};

return (
<div className='max-h-[60rem] overflow-scroll bg-neutral-900'>
<h2 className='text-xl font-bold sticky top-0 bg-black'>WALLETS</h2>
Expand Down Expand Up @@ -41,7 +48,9 @@ const WalletList = () => {
<td className='px-4 py-2'>
{wallet.installed ? (
<button
onClick={() => connect({ walletId: wallet.id, chainType })}
onClick={() =>
connect({ walletId: wallet.id, chainType, nearContractId: getNearContractId(chainType) })
}
className='bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded'
>
connect
Expand Down
1 change: 1 addition & 0 deletions example/src/components/Providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const Providers = ({ children }: { children: ReactNode }) => {

twaReturnUrl: `${window.location.origin}/` as `${string}://${string}`,
projectId: '41980758771052df3f01be0a46f172a5',
nearNetwork: 'mainnet',
tonconnectManifestUrl: `${window.location.origin}/tonconnect-manifest.json`,
bitcoinNetwork: 'mainnet',
}}
Expand Down
12 changes: 0 additions & 12 deletions example/src/components/Tokens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,95 +63,83 @@ const tokens: TokenMetadata[] = [
name: 'OSMO',
symbol: 'OSMO',
chainId: 'osmosis-1',
isNative: true,
},
{
address: ETH_ADDRESS,
decimals: 18,
name: 'Ether',
symbol: 'ETH',
chainId: '1',
isNative: true,
},
{
address: '',
decimals: 18,
name: 'Polygon MATIC',
symbol: 'MATIC',
chainId: '137',
isNative: true,
},
{
address: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
decimals: 6,
name: 'USDC',
symbol: 'USDC',
chainId: '42161',
isNative: false,
},
{
address: SOL_ADDRESS,
decimals: 9,
name: 'Solana SOL',
symbol: 'SOL',
chainId: 'solana',
isNative: true,
},
{
address: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
decimals: 6,
name: 'USDC',
symbol: 'USDC',
chainId: 'solana',
isNative: false,
},
{
address: 'So11111111111111111111111111111111111111112',
decimals: 9,
name: 'Wrapped SOL',
symbol: 'WSOL',
chainId: 'solana',
isNative: false,
},
{
address: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB',
decimals: 6,
name: 'USDT',
symbol: 'USDT',
chainId: 'solana',
isNative: false,
},
{
address: ETH_ADDRESS,
decimals: 6,
name: 'Tron TRX',
symbol: 'TRX',
chainId: '728126428',
isNative: true,
},
{
address: 'TEkxiTehnzSmSe2XqrBj4w32RUN966rdz8',
decimals: 6,
name: 'Tron USDC',
symbol: 'USDC',
chainId: '728126428',
isNative: false,
},
{
address: ETH_ADDRESS,
decimals: 9,
name: 'Toncoin',
symbol: 'TON',
chainId: '-239',
isNative: true,
},
{
address: 'EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs',
decimals: 6,
name: 'Tether USD',
symbol: 'USDT',
chainId: '-239',
isNative: false,
},
];

Expand Down
7 changes: 7 additions & 0 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
"@cosmos-kit/xdefi": "^2.10.2",
"@mysten/dapp-kit": "^0.14.14",
"@mysten/sui": "^1.4.0",
"@near-js/providers": "latest",
"@near-wallet-selector/core": "^8.9.13",
"@near-wallet-selector/ethereum-wallets": "^8.9.13",
"@near-wallet-selector/my-near-wallet": "^8.9.13",
"@near-wallet-selector/near-mobile-wallet": "^8.9.13",
"@near-wallet-selector/wallet-connect": "^8.9.13",
"@routerprotocol/router-chain-sdk-ts": "0.8.70-beta-0.2",
"@safe-global/safe-apps-sdk": "^9.0.0",
"@solana/spl-token": "^0.4.8",
Expand All @@ -56,6 +62,7 @@
"@tronweb3/tronwallet-adapters": "^1.2.1",
"@wagmi/core": "^2.11.0",
"detect-browser": "^5.3.0",
"near-api-js": "^5.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"tronweb": "6.0.0-beta.4",
Expand Down
17 changes: 16 additions & 1 deletion packages/react/src/actions/getBalances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { multicall } from '@wagmi/core';
import { Address as EVMAddress, erc20Abi } from 'viem';
import { trc20Abi } from '../constants/abi/trc20.js';
import { tronMulticallAbi } from '../constants/abi/tronMulticall.js';
import { ChainData, ConnectionOrConfig } from '../types/index.js';
import { ChainData, ConnectionOrConfig, OtherChainData } from '../types/index.js';
import { viewMethodOnNear } from './near/readCalls.js';

export const getBalances = async (
tokens: { address: string }[],
Expand Down Expand Up @@ -119,5 +120,19 @@ export const getBalances = async (
return balances;
}

if (chain.type === 'near') {
const balances: Record<string, bigint> = {};

for (const token of tokens) {
balances[token.address] = BigInt(
await viewMethodOnNear(chain as OtherChainData<'near'>, token.address, 'ft_balance_of', {
account_id: account,
}),
);
}

return balances;
}

throw new Error('Unsupported chain type');
};
Loading

0 comments on commit 3add320

Please sign in to comment.