Skip to content

Commit 51ea99e

Browse files
committed
fix: demo mode improvements and router fixes
1 parent 96437e5 commit 51ea99e

File tree

9 files changed

+67
-124
lines changed

9 files changed

+67
-124
lines changed

src/components/layouts/AccountOverview.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<div class="mobile-menu-bar flex-row">
3232
<button
3333
class="reset menu-button"
34-
@click="$router.replace({ name: RouteName.Root, query: { sidebar: 'true' } })"
34+
@click="$router.push({ name: RouteName.Root, query: { sidebar: 'true' } })"
3535
>
3636
<MenuIcon/>
3737
<AttentionDot v-if="updateAvailable"/>

src/composables/useActiveMobileColumn.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@ export enum ColumnType {
1313
let activeMobileColumn: Ref<ColumnType> | null = null;
1414

1515
// Adding this code at the end of the call stack so router is not undefined
16-
setTimeout(() => {
16+
const initializeRouterGuard = () => {
17+
// Check if router and beforeResolve method exist (needed for demo mode initialization)
18+
if (!router || typeof router.beforeResolve !== 'function') {
19+
// Retry after a longer delay if router is not ready (happens in demo mode)
20+
setTimeout(initializeRouterGuard, 100);
21+
return;
22+
}
23+
1724
router.beforeResolve((to, from, next) => {
1825
if (!activeMobileColumn) {
1926
activeMobileColumn = ref(ColumnType.ACCOUNT);
@@ -43,7 +50,8 @@ setTimeout(() => {
4350

4451
next();
4552
});
46-
}, 0);
53+
};
54+
setTimeout(initializeRouterGuard, 0);
4755

4856
export function useActiveMobileColumn() {
4957
if (!activeMobileColumn) {

src/global.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Build-time constants defined by webpack DefinePlugin
3+
* These values are replaced at build time and should not be accessed via process.env
4+
*/
5+
6+
/** Whether this is a demo build */
7+
declare const IS_DEMO_BUILD: boolean;

src/i18n/en.po

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ msgstr ""
2020
msgid "{amount} fee"
2121
msgstr ""
2222

23-
#: src/components/layouts/Network.vue:30
24-
#: src/components/layouts/Network.vue:50
25-
#: src/components/layouts/Network.vue:65
23+
#: src/components/layouts/Network.vue:35
24+
#: src/components/layouts/Network.vue:55
25+
#: src/components/layouts/Network.vue:70
2626
msgid "{amount}/tx"
2727
msgstr ""
2828

@@ -38,7 +38,7 @@ msgstr ""
3838
msgid "{count} Confirmation | {count} Confirmations"
3939
msgstr ""
4040

41-
#: src/components/layouts/Network.vue:28
41+
#: src/components/layouts/Network.vue:33
4242
msgid "{count} Peer | {count} Peers"
4343
msgstr ""
4444

@@ -127,11 +127,11 @@ msgstr ""
127127
msgid "1"
128128
msgstr ""
129129

130-
#: src/components/layouts/Network.vue:36
130+
#: src/components/layouts/Network.vue:41
131131
msgid "1-2 sec"
132132
msgstr ""
133133

134-
#: src/components/layouts/Network.vue:57
134+
#: src/components/layouts/Network.vue:62
135135
msgid "10 min"
136136
msgstr ""
137137

@@ -152,7 +152,7 @@ msgstr ""
152152
msgid "2-4h"
153153
msgstr ""
154154

155-
#: src/components/layouts/Network.vue:72
155+
#: src/components/layouts/Network.vue:77
156156
msgid "20 sec"
157157
msgstr ""
158158

@@ -217,8 +217,8 @@ msgstr ""
217217
msgid "Accounts"
218218
msgstr ""
219219

220-
#: src/components/layouts/AccountOverview.vue:159
221-
#: src/components/layouts/AccountOverview.vue:273
220+
#: src/components/layouts/AccountOverview.vue:162
221+
#: src/components/layouts/AccountOverview.vue:276
222222
msgid "Activate"
223223
msgstr ""
224224

@@ -307,7 +307,7 @@ msgstr ""
307307
msgid "All countries"
308308
msgstr ""
309309

310-
#: src/components/layouts/AccountOverview.vue:281
310+
#: src/components/layouts/AccountOverview.vue:284
311311
#: src/components/LegacyAccountNotice.vue:37
312312
msgid "All new features are exclusive to new accounts. Upgrade now, it only takes seconds."
313313
msgstr ""
@@ -405,7 +405,7 @@ msgstr ""
405405
msgid "Awaiting swap secret"
406406
msgstr ""
407407

408-
#: src/components/layouts/Network.vue:14
408+
#: src/components/layouts/Network.vue:19
409409
msgid "Back to addresses"
410410
msgstr ""
411411

@@ -434,8 +434,8 @@ msgstr ""
434434
msgid "BIC works, too."
435435
msgstr ""
436436

437-
#: src/components/AddressList.vue:191
438-
#: src/components/layouts/AccountOverview.vue:140
437+
#: src/components/AddressList.vue:196
438+
#: src/components/layouts/AccountOverview.vue:143
439439
#: src/components/layouts/AddressOverview.vue:125
440440
#: src/components/layouts/Settings.vue:119
441441
#: src/components/LegacyAccountNotice.vue:21
@@ -663,7 +663,7 @@ msgstr ""
663663
msgid "Choose an Address"
664664
msgstr ""
665665

666-
#: src/components/layouts/AccountOverview.vue:229
666+
#: src/components/layouts/AccountOverview.vue:232
667667
msgid "Choose Stablecoin"
668668
msgstr ""
669669

@@ -739,7 +739,7 @@ msgstr ""
739739
msgid "Connected to"
740740
msgstr ""
741741

742-
#: src/components/layouts/Network.vue:120
742+
#: src/components/layouts/Network.vue:125
743743
msgid "connecting"
744744
msgstr ""
745745

@@ -1068,7 +1068,7 @@ msgstr ""
10681068
msgid "Error:"
10691069
msgstr ""
10701070

1071-
#: src/components/layouts/Network.vue:121
1071+
#: src/components/layouts/Network.vue:126
10721072
msgid "established"
10731073
msgstr ""
10741074

@@ -1823,7 +1823,7 @@ msgstr ""
18231823
msgid "Partially reverted"
18241824
msgstr ""
18251825

1826-
#: src/components/layouts/Network.vue:118
1826+
#: src/components/layouts/Network.vue:123
18271827
msgid "paused"
18281828
msgstr ""
18291829

@@ -2555,7 +2555,7 @@ msgstr ""
25552555
msgid "Swap"
25562556
msgstr ""
25572557

2558-
#: src/components/layouts/AccountOverview.vue:194
2558+
#: src/components/layouts/AccountOverview.vue:197
25592559
msgid "Swap BTC {arrowIcon} {ticker}"
25602560
msgstr ""
25612561

@@ -2588,11 +2588,11 @@ msgstr ""
25882588
msgid "Swap more per 30 days."
25892589
msgstr ""
25902590

2591-
#: src/components/layouts/AccountOverview.vue:123
2591+
#: src/components/layouts/AccountOverview.vue:126
25922592
msgid "Swap NIM {arrowIcon} {ticker}"
25932593
msgstr ""
25942594

2595-
#: src/components/layouts/AccountOverview.vue:87
2595+
#: src/components/layouts/AccountOverview.vue:90
25962596
msgid "Swap NIM {arrowIcon} BTC"
25972597
msgstr ""
25982598

@@ -2637,7 +2637,7 @@ msgstr ""
26372637
msgid "Switch validator"
26382638
msgstr ""
26392639

2640-
#: src/components/layouts/Network.vue:119
2640+
#: src/components/layouts/Network.vue:124
26412641
msgid "syncing"
26422642
msgstr ""
26432643

@@ -2662,8 +2662,8 @@ msgstr ""
26622662
msgid "TEN31 Verification"
26632663
msgstr ""
26642664

2665-
#: src/components/AddressList.vue:210
2666-
#: src/components/layouts/AccountOverview.vue:221
2665+
#: src/components/AddressList.vue:215
2666+
#: src/components/layouts/AccountOverview.vue:224
26672667
#: src/components/layouts/AddressOverview.vue:131
26682668
#: src/components/swap/SwapBalanceBar.vue:29
26692669
#: src/components/swap/SwapBalanceBar.vue:55
@@ -2922,8 +2922,8 @@ msgstr ""
29222922
msgid "To change your validator, un-stake all NIM and restart the process. Click here to {unstakeLink}."
29232923
msgstr ""
29242924

2925-
#: src/components/layouts/AccountOverview.vue:128
2926-
#: src/components/layouts/AccountOverview.vue:199
2925+
#: src/components/layouts/AccountOverview.vue:131
2926+
#: src/components/layouts/AccountOverview.vue:202
29272927
#: src/components/swap/SwapModal.vue:37
29282928
msgid "To swap with USDC/USDT, choose a stablecoin."
29292929
msgstr ""
@@ -3048,8 +3048,8 @@ msgstr ""
30483048
msgid "Update validator"
30493049
msgstr ""
30503050

3051-
#: src/components/AddressList.vue:200
3052-
#: src/components/layouts/AccountOverview.vue:218
3051+
#: src/components/AddressList.vue:205
3052+
#: src/components/layouts/AccountOverview.vue:221
30533053
#: src/components/layouts/AddressOverview.vue:128
30543054
#: src/components/swap/SwapBalanceBar.vue:24
30553055
#: src/components/swap/SwapBalanceBar.vue:50

src/lib/Constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export { CryptoCurrency } from '@nimiq/utils';
66
export const CASHLINK_ADDRESS = 'cashlink';
77
export const BANK_ADDRESS = 'bank';
88

9-
export const ENV_MAIN = 'MainAlbatross';
9+
export const ENV_MAIN = 'main';
1010
export const ENV_TEST = 'test';
1111
export const ENV_DEV = 'dev';
1212

src/lib/demo/DemoConstants.ts

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,48 @@
11
/* eslint-disable max-len */
22

3-
// Demo state type
43
export type DemoState = {
54
active: boolean,
65
};
76

8-
// Demo modal types
97
export const DemoModal = {
108
Fallback: 'demo-fallback',
119
Buy: 'demo-buy',
1210
} as const;
13-
14-
// Demo addresses
1511
export const demoNimAddress = 'NQ57 2814 7L5B NBBD 0EU7 EL71 HXP8 M7H8 MHKD';
1612
export const demoBtcAddress = '1XYZDemoAddress';
1713
export const demoPolygonAddress = '0xabc123DemoPolygonAddress';
1814
export const buyFromAddress = 'NQ04 JG63 HYXL H3QF PPNA 7ED7 426M 3FQE FHE5';
1915

20-
// Initial balances
21-
export const nimInitialBalance = 140_418 * 1e5; // 14,041,800,000 - 14 april, 2018. 5 decimals.
22-
export const btcInitialBalance = 0.00025 * 1e8; // 0.00025 BTC (8 decimals)
23-
export const usdtInitialBalance = 514.83 * 1e6; // 5000 USDT (6 decimals)
24-
export const usdcInitialBalance = 357.38 * 1e6; // 3000 USDC (6 decimals)
16+
// Initial balance represents 14 april, 2018 (birth of Nimiq)
17+
export const nimInitialBalance = 140_418 * 1e5;
18+
export const btcInitialBalance = 0.00025 * 1e8;
19+
export const usdtInitialBalance = 514.83 * 1e6;
20+
export const usdcInitialBalance = 357.38 * 1e6;
2521

26-
// Flow types - supporting wallet playground actions
2722
export type DemoFlowType = 'buy' | 'swap' | 'stake' | 'idle';
2823

29-
// Iframe communication message types
3024
export type WalletPlaygroundMessage = {
3125
type: 'demo:ready' | 'action:open-buy-modal' | 'action:open-staking-modal' | 'action:open-swap-modal' | 'action:close-modal',
3226
data?: any,
3327
};
3428

35-
// Demo routes mapping - including idle state
3629
export const demoRoutes: Record<DemoFlowType, string> = {
37-
buy: '/demo-buy', // Use demo buy route to show custom modal
30+
buy: '/demo-buy',
3831
swap: '/swap/NIM-BTC',
3932
stake: '/staking',
40-
idle: '/', // Default route for idle state
33+
idle: '/',
4134
};
4235

43-
// Hub API requests to ignore
36+
// Ignored to prevent unnecessary Hub initialization
4437
export const ignoreHubRequests = [
4538
'addBtcAddresses',
4639
'on',
4740
];
48-
49-
// Demo CSS styles
5041
export const demoCSS = `
5142
.transaction-list .month-label > :where(.fetching, .failed-to-fetch) {
5243
display: none;
5344
}
5445
55-
/* Hide address */
5646
.active-address .meta .copyable {
5747
display: none !important;
5848
}
@@ -73,15 +63,14 @@ export const demoCSS = `
7363
display: none;
7464
}
7565
76-
/* Demo address tooltip styling */
7766
.tooltip.demo-tooltip {
7867
width: max-content;
7968
background: var(--nimiq-orange-bg);
8069
margin-left: -7rem;
8170
}
8271
8372
.tooltip.demo-tooltip::after {
84-
background: #fc750c; /* Match the red theme for the demo warning */
73+
background: #fc750c;
8574
}
8675
8776
.demo-highlight-badge {
@@ -136,13 +125,10 @@ export const demoCSS = `
136125
background: #dedee2 !important;
137126
}
138127
139-
/* Hide links and addresses to block explorer in the swap animation */
140128
.swap-animation :where(.short-address, .blue-link.nq-link) {
141129
display: none !important;
142130
}
143131
`;
144-
145-
// Bank SVG icon
146132
export const bankSvg = `<svg class="bank-icon" width="48" height="48" viewBox="0 0 66 66"
147133
fill="none" xmlns="http://www.w3.org/2000/svg">
148134
<path d="M65.012 40.982c-4.408 17.682-22.315 28.438-39.999 24.03C7.339 60.605-3.422 42.698.989
@@ -158,13 +144,9 @@ export const bankSvg = `<svg class="bank-icon" width="48" height="48" viewBox="0
158144
</svg>`;
159145

160146
/**
161-
* Checks if the demo mode should be active.
162-
* Demo mode is only activated through build commands:
163-
* - yarn serve:demo
164-
* - yarn build:demo
165-
* - yarn build:demo-production
147+
* Demo mode is only activated through build commands (yarn serve:demo, yarn build:demo).
166148
* This ensures demo builds are separate deployments with no runtime activation.
167149
*/
168150
export function checkIfDemoIsActive(): boolean {
169-
return !!(process.env as any).IS_DEMO_BUILD;
151+
return IS_DEMO_BUILD; // Replaced at build time by webpack DefinePlugin
170152
}

src/lib/demo/DemoHubApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ interface SetupSwapArgs {
5454
}
5555

5656
/**
57-
* Replacement of the Hub API class to capture and redirect calls to our demo modals instead.
57+
* Mock Hub API that redirects calls to demo modals instead of real Hub.
5858
*/
5959
export class DemoHubApi extends HubApi {
6060
static create(): DemoHubApi {

0 commit comments

Comments
 (0)