File tree 1 file changed +13
-1
lines changed 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change 1
1
import { USDC_ADDRESS , BASE_CHAIN_ID } from './constants/index' ;
2
2
3
+ export const formatUsdcAmount = ( amount : number ) => {
4
+ // Convert to 6 decimal places, remove decimal point
5
+ const rawAmount = Math . round ( amount * 1_000_000 ) ;
6
+ // Convert to scientific notation if it ends in zeros
7
+ const trailingZeros = ( rawAmount . toString ( ) . match ( / 0 + $ / ) || [ '' ] ) [ 0 ] . length ;
8
+ if ( trailingZeros > 0 ) {
9
+ return `${ rawAmount / 10 ** trailingZeros } e${ trailingZeros } ` ;
10
+ }
11
+ return rawAmount . toString ( ) ;
12
+ }
13
+
3
14
export const GeneratePaymentLink = ( amount : number , address : string ) : string => {
4
- return `ethereum:${ USDC_ADDRESS } @${ BASE_CHAIN_ID } /transfer?value=${ amount } e10&address=${ address } ` ;
15
+ const amountAsUsdc = formatUsdcAmount ( amount ) ;
16
+ return `ethereum:${ USDC_ADDRESS } @${ BASE_CHAIN_ID } /transfer?value=${ amountAsUsdc } &address=${ address } ` ;
5
17
}
6
18
7
19
export const copyToClipboard = ( text : string , toast :any ) : void => {
You can’t perform that action at this time.
0 commit comments