Skip to content

Commit 572df1f

Browse files
committed
chore(demo): handle receive modal
1 parent 08b9740 commit 572df1f

File tree

1 file changed

+52
-9
lines changed

1 file changed

+52
-9
lines changed

src/lib/Demo.ts

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ const demoPolygonAddress = '0xabc123DemoPolygonAddress';
5656
const buyFromAddress = 'NQ04 JG63 HYXL H3QF PPNA 7ED7 426M 3FQE FHE5';
5757

5858
// 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)
6363

6464
// Swaps
6565
const onGoingSwaps = new Map<string, SetupSwapArgs>();
@@ -126,6 +126,12 @@ function insertCustomDemoStyles() {
126126
*/
127127
function rewriteDemoRoutes() {
128128
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+
}
129135
// Redirect certain known paths to the Buy demo modal
130136
if (to.path === '/buy') {
131137
return next({
@@ -154,6 +160,7 @@ function setupSingleMutationObserver() {
154160
disableSwapTriggers(processedElements);
155161
enableSellAndSwapModals(processedElements);
156162
obfuscateAddresses(processedElements);
163+
observeReceiveModal(processedElements);
157164
};
158165

159166
// Create one mutation observer for all DOM modifications
@@ -1897,7 +1904,7 @@ function obfuscateAddresses(processedElements: WeakSet<HTMLElement>) {
18971904

18981905
// Process NIM address displays: obfuscate address chunks beyond the first three.
18991906
const nimAddressElements = document.querySelectorAll('.copyable.address-display') as NodeListOf<HTMLElement>;
1900-
nimAddressElements.forEach(el =>
1907+
nimAddressElements.forEach((el) =>
19011908
processElement(el, (element) => {
19021909
const chunks = element.querySelectorAll('.chunk');
19031910
for (let i = 3; i < chunks.length; i++) {
@@ -1906,27 +1913,63 @@ function obfuscateAddresses(processedElements: WeakSet<HTMLElement>) {
19061913
chunk.textContent = 'XXXX';
19071914
if (space) chunk.appendChild(space);
19081915
}
1909-
})
1916+
}),
19101917
);
19111918

19121919
// Process short address displays: change the last chunk of the short address.
19131920
const shortAddressElements = document.querySelectorAll('.tooltip.interactive-short-address.is-copyable') as NodeListOf<HTMLElement>;
1914-
shortAddressElements.forEach(el =>
1921+
shortAddressElements.forEach((el) =>
19151922
processElement(el, (element) => {
19161923
const lastChunk = element.querySelector('.short-address .address:last-child');
19171924
if (lastChunk) {
19181925
lastChunk.textContent = 'xxxx';
19191926
}
1920-
})
1927+
}),
19211928
);
19221929

19231930
// Process tooltip boxes inside short address displays.
19241931
const tooltipBoxElements = document.querySelectorAll('.tooltip.interactive-short-address.is-copyable .tooltip-box') as NodeListOf<HTMLElement>;
1925-
tooltipBoxElements.forEach(el => {
1932+
tooltipBoxElements.forEach((el) => {
19261933
if (processedElements.has(el)) return;
19271934
processedElements.add(el);
19281935
el.textContent = 'Demo address';
19291936
el.classList.add('demo-tooltip');
19301937
addDemoClickHandler(el);
19311938
});
19321939
}
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

Comments
 (0)