-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from router-protocol/near
Near wallets integration
- Loading branch information
Showing
34 changed files
with
4,073 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { providers } from 'near-api-js'; | ||
import { OtherChainData } from '../../types/index.js'; | ||
|
||
export const THIRTY_TGAS = '30000000000000'; | ||
export const NO_DEPOSIT = '0'; | ||
|
||
export function getNearProvider(chain: OtherChainData<'near'>) { | ||
return new providers.JsonRpcProvider({ url: chain.rpcUrls.default.http[0] }); | ||
} | ||
|
||
export async function viewMethodOnNear(chain: OtherChainData<'near'>, token: string, method: string, args = {}) { | ||
const provider = getNearProvider(chain); | ||
|
||
try { | ||
let res = await provider.query({ | ||
request_type: 'call_function', | ||
account_id: token, | ||
method_name: method, | ||
args_base64: Buffer.from(JSON.stringify(args)).toString('base64'), | ||
finality: 'optimistic', | ||
}); | ||
res = JSON.parse(Buffer.from(res.result).toString()); | ||
return res; | ||
} catch (error) { | ||
console.error('Error calling viewMethodOnNear:', error); | ||
throw error; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.