-
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.
* update benefits list * update navbar urls * implement validation of user's USDC polygon balance * Hide 'Select Chain' button * show available usdc/usdc.e balance * update yarnlock file * Make naming more generic --------- Co-authored-by: Torsten Stüber <15174476+TorstenStueber@users.noreply.github.com>
- Loading branch information
1 parent
6fff196
commit b54fbfe
Showing
9 changed files
with
209 additions
and
116 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
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,23 @@ | ||
import { InputTokenDetails } from '../../constants/tokenConfig'; | ||
import { useInputTokenBalance } from '../../hooks/useInputTokenBalance'; | ||
|
||
interface UserBalanceProps { | ||
token: InputTokenDetails; | ||
} | ||
|
||
export const UserBalance = ({ token }: UserBalanceProps) => { | ||
const inputTokenBalance = useInputTokenBalance({ fromToken: token }); | ||
|
||
return ( | ||
<p className="mt-1 text-right"> | ||
Available:{' '} | ||
{inputTokenBalance === undefined ? ( | ||
'N/A' | ||
) : ( | ||
<> | ||
<span className="bold">{inputTokenBalance}</span> {token.assetSymbol} | ||
</> | ||
)} | ||
</p> | ||
); | ||
}; |
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,34 @@ | ||
[ | ||
{ | ||
"inputs": [{ "internalType": "address", "name": "account", "type": "address" }], | ||
"name": "balanceOf", | ||
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], | ||
"stateMutability": "view", | ||
"type": "function", | ||
"constant": true | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "decimals", | ||
"outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }], | ||
"stateMutability": "view", | ||
"type": "function", | ||
"constant": true | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "symbol", | ||
"outputs": [{ "internalType": "string", "name": "", "type": "string" }], | ||
"stateMutability": "view", | ||
"type": "function", | ||
"constant": true | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "totalSupply", | ||
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], | ||
"stateMutability": "view", | ||
"type": "function", | ||
"constant": true | ||
} | ||
] |
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,22 @@ | ||
import { formatUnits } from 'viem'; | ||
import { useAccount, useReadContract } from 'wagmi'; | ||
|
||
import erc20ABI from '../contracts/ERC20'; | ||
import { InputTokenDetails } from '../constants/tokenConfig'; | ||
import { multiplyByPowerOfTen } from '../helpers/contracts'; | ||
import Big from 'big.js'; | ||
|
||
export const useInputTokenBalance = ({ fromToken }: { fromToken: InputTokenDetails }): string | undefined => { | ||
const { address } = useAccount(); | ||
|
||
const { data: balance }: { data: bigint | undefined } = useReadContract({ | ||
address: fromToken.erc20AddressSourceChain, | ||
abi: erc20ABI, | ||
functionName: 'balanceOf', | ||
args: [address], | ||
}); | ||
|
||
return address === undefined || balance === undefined | ||
? undefined | ||
: multiplyByPowerOfTen(Big(balance.toString()), -fromToken.decimals).toFixed(2, 0); | ||
}; |
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.