@@ -56,10 +56,10 @@ const demoPolygonAddress = '0xabc123DemoPolygonAddress';
56
56
const buyFromAddress = 'NQ04 JG63 HYXL H3QF PPNA 7ED7 426M 3FQE FHE5' ;
57
57
58
58
// We keep this as our global/final balance, which should result from the transactions
59
- const nimInitialBalance = 140_418_00000 ; // 14,041,800,000 - 14 april, 2018. 5 decimals.
60
- const btcInitialBalance = 1_0000000 ; // 1 BTC (8 decimals)
61
- const usdtInitialBalance = 5_000_000000 ; // 5000 USDT (6 decimals)
62
- const usdcInitialBalance = 3_000_000000 ; // 3000 USDC (6 decimals)
59
+ const nimInitialBalance = 140_418 * 1e5 ; // 14,041,800,000 - 14 april, 2018. 5 decimals.
60
+ const btcInitialBalance = 0.0025 * 1e8 ; // 1 BTC (8 decimals)
61
+ const usdtInitialBalance = 514.83 * 1e6 ; // 5000 USDT (6 decimals)
62
+ const usdcInitialBalance = 357.38 * 1e6 ; // 3000 USDC (6 decimals)
63
63
64
64
// Swaps
65
65
const onGoingSwaps = new Map < string , SetupSwapArgs > ( ) ;
@@ -126,6 +126,12 @@ function insertCustomDemoStyles() {
126
126
*/
127
127
function rewriteDemoRoutes ( ) {
128
128
demoRouter . beforeEach ( ( to , _from , next ) => {
129
+ if ( to . path . startsWith ( '/receive/' ) && ! to . path . startsWith ( '/receive/nim' ) ) {
130
+ return next ( {
131
+ path : `/${ DemoModal . Fallback } ` ,
132
+ query : { ...to . query , [ DEMO_PARAM ] : '' } ,
133
+ } )
134
+ }
129
135
// Redirect certain known paths to the Buy demo modal
130
136
if ( to . path === '/buy' ) {
131
137
return next ( {
@@ -154,6 +160,7 @@ function setupSingleMutationObserver() {
154
160
disableSwapTriggers ( processedElements ) ;
155
161
enableSellAndSwapModals ( processedElements ) ;
156
162
obfuscateAddresses ( processedElements ) ;
163
+ observeReceiveModal ( processedElements ) ;
157
164
} ;
158
165
159
166
// Create one mutation observer for all DOM modifications
@@ -1897,7 +1904,7 @@ function obfuscateAddresses(processedElements: WeakSet<HTMLElement>) {
1897
1904
1898
1905
// Process NIM address displays: obfuscate address chunks beyond the first three.
1899
1906
const nimAddressElements = document . querySelectorAll ( '.copyable.address-display' ) as NodeListOf < HTMLElement > ;
1900
- nimAddressElements . forEach ( el =>
1907
+ nimAddressElements . forEach ( ( el ) =>
1901
1908
processElement ( el , ( element ) => {
1902
1909
const chunks = element . querySelectorAll ( '.chunk' ) ;
1903
1910
for ( let i = 3 ; i < chunks . length ; i ++ ) {
@@ -1906,27 +1913,63 @@ function obfuscateAddresses(processedElements: WeakSet<HTMLElement>) {
1906
1913
chunk . textContent = 'XXXX' ;
1907
1914
if ( space ) chunk . appendChild ( space ) ;
1908
1915
}
1909
- } )
1916
+ } ) ,
1910
1917
) ;
1911
1918
1912
1919
// Process short address displays: change the last chunk of the short address.
1913
1920
const shortAddressElements = document . querySelectorAll ( '.tooltip.interactive-short-address.is-copyable' ) as NodeListOf < HTMLElement > ;
1914
- shortAddressElements . forEach ( el =>
1921
+ shortAddressElements . forEach ( ( el ) =>
1915
1922
processElement ( el , ( element ) => {
1916
1923
const lastChunk = element . querySelector ( '.short-address .address:last-child' ) ;
1917
1924
if ( lastChunk ) {
1918
1925
lastChunk . textContent = 'xxxx' ;
1919
1926
}
1920
- } )
1927
+ } ) ,
1921
1928
) ;
1922
1929
1923
1930
// Process tooltip boxes inside short address displays.
1924
1931
const tooltipBoxElements = document . querySelectorAll ( '.tooltip.interactive-short-address.is-copyable .tooltip-box' ) as NodeListOf < HTMLElement > ;
1925
- tooltipBoxElements . forEach ( el => {
1932
+ tooltipBoxElements . forEach ( ( el ) => {
1926
1933
if ( processedElements . has ( el ) ) return ;
1927
1934
processedElements . add ( el ) ;
1928
1935
el . textContent = 'Demo address' ;
1929
1936
el . classList . add ( 'demo-tooltip' ) ;
1930
1937
addDemoClickHandler ( el ) ;
1931
1938
} ) ;
1932
1939
}
1940
+
1941
+ /**
1942
+ * Observes the receive modal and redirects relevant button clicks to the fallback modal
1943
+ */
1944
+ function observeReceiveModal ( processedElements : WeakSet < Element > ) {
1945
+ // Find the receive modal
1946
+ const receiveModal = document . querySelector ( '.receive-modal' ) ;
1947
+ console . log ( { receiveModal} )
1948
+ if ( ! receiveModal ) return ;
1949
+
1950
+ // Look for buttons that should redirect to the fallback modal
1951
+ const buttons = receiveModal . querySelectorAll ( '.nq-button-s, .qr-button' ) ;
1952
+
1953
+ buttons . forEach ( button => {
1954
+ // Skip if we've already processed this button
1955
+ if ( processedElements . has ( button ) ) return ;
1956
+
1957
+ // Mark as processed to avoid adding multiple listeners
1958
+ processedElements . add ( button ) ;
1959
+
1960
+ // Replace the original click handler with our redirect
1961
+ button . addEventListener ( 'click' , ( event ) => {
1962
+ // Prevent the default action and stop propagation
1963
+ event . preventDefault ( ) ;
1964
+ event . stopPropagation ( ) ;
1965
+
1966
+ // Redirect to the fallback modal
1967
+ demoRouter . replace ( {
1968
+ path : `/${ DemoModal . Fallback } ` ,
1969
+ query : { [ DEMO_PARAM ] : '' } ,
1970
+ } ) ;
1971
+
1972
+ console . log ( '[Demo] Redirected receive modal button click to fallback modal' ) ;
1973
+ } , true ) ; // Use capture to intercept the event before other handlers
1974
+ } ) ;
1975
+ }
0 commit comments