-
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.
fix: Disable send button on invalid to address
- Loading branch information
1 parent
2b888d5
commit 6372232
Showing
3 changed files
with
29 additions
and
13 deletions.
There are no files selected for viewing
30 changes: 24 additions & 6 deletions
30
...es/canonical-bridge-widget/src/modules/aggregator/adapters/meson/hooks/useTronContract.ts
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 |
---|---|---|
@@ -1,21 +1,39 @@ | ||
import { useState } from 'react'; | ||
import { useEffect } from 'react'; | ||
import { useCallback } from 'react'; | ||
|
||
import { useAppSelector } from '@/modules/store/StoreProvider'; | ||
import { useTronWeb } from '@/core/hooks/useTronWeb'; | ||
|
||
export const useTronContract = () => { | ||
const tronWeb = useTronWeb(); | ||
const [isTronContract, setIsTronContract] = useState<null | boolean>(null); | ||
const toAccount = useAppSelector((state) => state.transfer.toAccount); | ||
|
||
const isTronContractInfo = async (address: string) => { | ||
if (!tronWeb) return; | ||
const isTronContractInfo = useCallback(async () => { | ||
if (!tronWeb || !toAccount?.address) return; | ||
try { | ||
const contractInfo = await tronWeb.trx.getContract(address); | ||
return !!contractInfo?.bytecode; | ||
const contractInfo = await tronWeb.trx.getContract(toAccount?.address); | ||
setIsTronContract(!!contractInfo?.bytecode); | ||
} catch (error) { | ||
// eslint-disable-next-line no-console | ||
console.log(error); | ||
setIsTronContract(false); | ||
return false; | ||
} | ||
}; | ||
}, [toAccount, tronWeb]); | ||
|
||
useEffect(() => { | ||
let mount = true; | ||
if (mount) { | ||
isTronContractInfo(); | ||
} | ||
return () => { | ||
mount = false; | ||
}; | ||
}, [toAccount, isTronContractInfo]); | ||
|
||
return { | ||
isTronContractInfo, | ||
isTronContract, | ||
}; | ||
}; |
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