1- /* eslint-disable max-len */
1+ /* eslint-disable max-len, consistent-return, no-console, no-async-promise-executor */
22import { createStore } from 'pinia' ;
33import VueRouter from 'vue-router' ;
44import { TransactionState as ElectrumTransactionState } from '@nimiq/electrum-client' ;
55import { CryptoCurrency , Utf8Tools } from '@nimiq/utils' ;
6- import { Address , KeyPair , PlainTransactionDetails , PlainTransactionRecipientData , PrivateKey , TransactionFormat } from '@nimiq/core' ;
6+ import { KeyPair , PlainTransactionDetails , PrivateKey } from '@nimiq/core' ;
77import { AccountType , useAccountStore } from '@/stores/Account' ;
88import { AddressType , useAddressStore } from '@/stores/Address' ;
99import { toSecs , type Transaction as NimTransaction , useTransactionsStore } from '@/stores/Transactions' ;
@@ -14,17 +14,16 @@ import { useStakingStore } from '@/stores/Staking';
1414import { useAccountSettingsStore } from '@/stores/AccountSettings' ;
1515import { usePolygonAddressStore } from '@/stores/PolygonAddress' ;
1616import Config from 'config' ;
17- import { AssetList , FastspotAsset , FastspotEstimate , FastspotFee , FastspotLimits , FastspotUserLimits , ReferenceAsset , SwapAsset , SwapStatus } from '@nimiq/fastspot-api' ;
17+ import { FastspotAsset , FastspotLimits , FastspotUserLimits , ReferenceAsset , SwapAsset , SwapStatus } from '@nimiq/fastspot-api' ;
1818import HubApi , { SetupSwapResult } from '@nimiq/hub-api' ;
19+ import { useConfig } from '@/composables/useConfig' ;
1920import { useBtcAddressStore } from './BtcAddress' ;
2021import { useContactsStore } from './Contacts' ;
2122import { useBtcLabelsStore } from './BtcLabels' ;
2223import { useUsdcContactsStore } from './UsdcContacts' ;
2324import { useUsdtContactsStore } from './UsdtContacts' ;
2425import { useFiatStore } from './Fiat' ;
2526import { SwapState , useSwapsStore } from './Swaps' ;
26- import { getUsdcHtlcContract } from '@/ethers' ;
27- import { useConfig } from '@/composables/useConfig' ;
2827
2928export type DemoState = {
3029 active : boolean ,
@@ -87,7 +86,6 @@ export const useDemoStore = createStore({
8786 * Initializes the demo environment and sets up various routes, data, and watchers.
8887 */
8988 async initialize ( router : VueRouter ) {
90- // eslint-disable-next-line no-console
9189 console . warn ( '[Demo] Initializing demo environment...' ) ;
9290
9391 demoRouter = router ;
@@ -454,7 +452,7 @@ function transformNimTransaction(txs: Partial<NimTransaction>[]): NimTransaction
454452 proof : { raw : '' , type : 'raw' } ,
455453 data : tx . data || { type : 'raw' , raw : '' } ,
456454 ...tx ,
457- }
455+ } ;
458456 } ) ;
459457}
460458
@@ -474,7 +472,7 @@ interface BtcTransactionDefinition {
474472 description : string ;
475473 recipientLabel ?: string ;
476474 incoming : boolean ;
477- address : string
475+ address : string ;
478476}
479477
480478/**
@@ -489,52 +487,52 @@ function defineBtcFakeTransactions(): BtcTransaction[] {
489487 description : 'Initial BTC purchase from exchange' ,
490488 incoming : true ,
491489 address : '1Kj4SNWFCxqvtP8nkJxeBwkXxgY9LW9rGg' ,
492- recipientLabel : 'Satoshi Exchange'
490+ recipientLabel : 'Satoshi Exchange' ,
493491 } ,
494492 {
495493 fraction : 0.15 ,
496494 daysAgo : 1600 ,
497495 description : 'Mining pool payout' ,
498496 incoming : true ,
499497 address : '1Hz7vQrRjnu3z9k7gxDYhKjEmABqChDvJr' ,
500- recipientLabel : 'Genesis Mining Pool'
498+ recipientLabel : 'Genesis Mining Pool' ,
501499 } ,
502500 {
503501 fraction : - 0.19 ,
504502 daysAgo : 1200 ,
505503 description : 'Purchase from online marketplace' ,
506504 incoming : false ,
507505 address : '1LxKe5kKdgGVwXukEgqFxh6DrCXF2Pturc' ,
508- recipientLabel : 'Digital Bazaar Shop'
506+ recipientLabel : 'Digital Bazaar Shop' ,
509507 } ,
510508 {
511509 fraction : 0.3 ,
512510 daysAgo : 800 ,
513511 description : 'Company payment for consulting' ,
514512 incoming : true ,
515513 address : '1N7aecJuKGDXzYK8CgpnNRYxdhZvXPxp3B' ,
516- recipientLabel : 'Corporate Treasury'
514+ recipientLabel : 'Corporate Treasury' ,
517515 } ,
518516 {
519517 fraction : - 0.15 ,
520518 daysAgo : 365 ,
521519 description : 'Auto-DCA investment program' ,
522520 incoming : false ,
523- address : '12vxjmKJkfL9s5JwqUzEVVJGvKYJgALbsz'
521+ address : '12vxjmKJkfL9s5JwqUzEVVJGvKYJgALbsz' ,
524522 } ,
525523 {
526524 fraction : 0.075 ,
527525 daysAgo : 180 ,
528526 description : 'P2P sale of digital goods' ,
529527 incoming : true ,
530- address : '1MZYS9nvVmFvSK7em5zzAsnvRq82RUcypS'
528+ address : '1MZYS9nvVmFvSK7em5zzAsnvRq82RUcypS' ,
531529 } ,
532530 {
533531 fraction : 0.05 ,
534532 daysAgo : 60 ,
535533 description : 'Recent purchase from exchange' ,
536534 incoming : true ,
537- address : '1Kj4SNWFCxqvtP8nkJxeBwkXxgY9LW9rGg'
535+ address : '1Kj4SNWFCxqvtP8nkJxeBwkXxgY9LW9rGg' ,
538536 } ,
539537 ] . sort ( ( a , b ) => b . daysAgo - a . daysAgo ) ;
540538
@@ -689,7 +687,6 @@ function insertFakeBtcTransactions(txs = defineBtcFakeTransactions()) {
689687 addTransactions ( txs ) ;
690688}
691689
692-
693690// #endregion
694691
695692// #region Polygon txs
@@ -1075,7 +1072,6 @@ function interceptFetchRequest() {
10751072 const url = new URL ( args [ 0 ] as string ) ;
10761073 const isFastspotRequest = url . host === ( new URL ( Config . fastspot . apiEndpoint ) . host ) ;
10771074 const isLimitsRequest = url . pathname . includes ( '/limits' ) ;
1078- const isEstimateRequest = url . pathname . includes ( '/estimate' ) ;
10791075 const isAssetsRequest = url . pathname . includes ( '/assets' ) ;
10801076 const isSwapRequest = url . pathname . includes ( '/swaps' ) ;
10811077
@@ -1106,6 +1102,7 @@ function interceptFetchRequest() {
11061102 return new Response ( JSON . stringify ( limits ) ) ;
11071103 }
11081104
1105+ // eslint-disable-next-line no-promise-executor-return
11091106 const sleep = ( ms : number ) => new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
11101107 await sleep ( 1000 + Math . random ( ) * 500 ) ;
11111108
@@ -1376,8 +1373,8 @@ function completeSwap(activeSwap: any) {
13761373 const toAsset = activeSwap . to . asset ;
13771374 const fromAmount = activeSwap . from . amount ;
13781375 const toAmount = activeSwap . to . amount ;
1379- const fromFee = activeSwap . from . fee || 0 ;
1380- const toFee = activeSwap . to . fee || 0 ;
1376+ // const fromFee = activeSwap.from.fee || 0;
1377+ // const toFee = activeSwap.to.fee || 0;
13811378
13821379 // Create outgoing transaction (from asset)
13831380 switch ( fromAsset ) {
@@ -1397,7 +1394,7 @@ function completeSwap(activeSwap: any) {
13971394 sender : demoNimAddress ,
13981395 timeout : 0 ,
13991396 } ,
1400- }
1397+ } ;
14011398 insertFakeNimTransactions ( transformNimTransaction ( [ tx ] ) ) ;
14021399 break ;
14031400 }
@@ -1409,7 +1406,7 @@ function completeSwap(activeSwap: any) {
14091406 fraction : - fromAmount / btcInitialBalance ,
14101407 incoming : false ,
14111408 recipientLabel : 'HTLC-ADDRESS' ,
1412- }
1409+ } ;
14131410 insertFakeBtcTransactions ( transformBtcTransaction ( [ tx ] ) ) ;
14141411 break ;
14151412 }
@@ -1437,6 +1434,9 @@ function completeSwap(activeSwap: any) {
14371434 insertFakeUsdtTransactions ( transformUsdtTransaction ( [ tx ] ) ) ;
14381435 break ;
14391436 }
1437+ default : {
1438+ console . warn ( `Unsupported asset type: ${ fromAsset } ` ) ;
1439+ }
14401440 }
14411441
14421442 // Create incoming transaction (to asset)
@@ -1457,7 +1457,7 @@ function completeSwap(activeSwap: any) {
14571457 sender : 'HTLC-ADDRESS' ,
14581458 timeout : 0 ,
14591459 } ,
1460- }
1460+ } ;
14611461 insertFakeNimTransactions ( transformNimTransaction ( [ tx ] ) ) ;
14621462 break ;
14631463 }
@@ -1469,7 +1469,7 @@ function completeSwap(activeSwap: any) {
14691469 fraction : toAmount / btcInitialBalance ,
14701470 incoming : true ,
14711471 recipientLabel : demoBtcAddress ,
1472- }
1472+ } ;
14731473 insertFakeBtcTransactions ( transformBtcTransaction ( [ tx ] ) ) ;
14741474 break ;
14751475 }
@@ -1496,8 +1496,10 @@ function completeSwap(activeSwap: any) {
14961496 insertFakeUsdtTransactions ( transformUsdtTransaction ( [ tx ] ) ) ;
14971497 break ;
14981498 }
1499+ default : {
1500+ console . warn ( `Unsupported asset type: ${ toAsset } ` ) ;
1501+ }
14991502 }
1500- // eslint-disable-next-line no-console
15011503 console . log ( 'Demo swap completed:' , { fromAsset, toAsset, fromAmount, toAmount } ) ;
15021504 } , 3000 ) ; // Simulate a delay for the swap to complete
15031505}
@@ -1565,67 +1567,65 @@ export class DemoHubApi extends HubApi {
15651567 const instance = new DemoHubApi ( ) ;
15661568 return new Proxy ( instance , {
15671569 get ( target , prop : keyof HubApi ) {
1568- if ( typeof target [ prop ] === 'function' ) {
1569- return async ( ...args : Parameters < HubApi [ typeof prop ] > ) => new Promise ( async ( resolve , reject ) => {
1570- const requestName = String ( prop ) ;
1571- const [ firstArg ] = args ;
1572- // eslint-disable-next-line no-console
1573- console . warn ( `[Demo] Mocking Hub call: ${ requestName } ("${ firstArg } ")` ) ;
1574-
1575- if ( ignoreHubRequests . includes ( requestName ) ) {
1576- return ;
1577- }
1578-
1579- if ( requestName === 'setupSwap' ) {
1580- const swap = await firstArg as SetupSwapArgs ;
1581- const signerTransaction : SetupSwapResult = {
1582- nim : {
1583- transaction : new Uint8Array ( ) ,
1584- serializedTx : '0172720036a3b2ca9e0de8b369e6381753ebef945a020091fa7bbddf959616767c50c50962c9e056ade9c400000000000000989680000000000000000000c3e23d0500a60100010366687aadf862bd776c8fc18b8e9f8e20089714856ee233b3902a591d0d5f292520000000000000000000000000000000000000000000000000000000000000000000200demoSerializedTx' ,
1585- hash : '6c58b337a907fe000demoTxHash8a1f4ab4fdc0f69b1e582f' ,
1586- raw : {
1587- signerPublicKey : new Uint8Array ( ) ,
1588- signature : new Uint8Array ( ) ,
1589- sender : 'NQ86 D3M0 SW4P NB59 U3F8 NDLX CE0P AFMX Y52S' ,
1590- senderType : 2 ,
1591- recipient : swap . redeem . recipient ,
1592- recipientType : 0 ,
1593- value : swap . redeem . value ,
1594- fee : 0 ,
1595- validityStartHeight : swap . redeem . validityStartHeight ,
1596- extraData : new Uint8Array ( ) ,
1597- flags : 0 ,
1598- networkId : 5 ,
1599- proof : new Uint8Array ( ) ,
1600- } ,
1601- } ,
1602- btc : {
1603- serializedTx : '0200000000010168c8952af998f2c68412a848a72d1f9b0b7ff27417df1cb85514c97474b51ba40000000000ffffffff026515000000000000220020bf0ffdd2ffb9a579973455cfe9b56515538b79361d5ae8a4d255dea2519ef77864c501000000000016001428257447efe2d254ce850ea2760274d233d86e5c024730440220792fa932d9d0591e3c5eb03f47d05912a1e21f3e76d169e383af66e47896ac8c02205947df5523490e4138f2da0fc5c9da3039750fe43bd217b68d26730fdcae7fbe012102ef8d4b51d1a075e67d62baa78991d5fc36a658fec28d8b978826058168ed2a1a00000000' ,
1604- hash : '3090808993a796c26a614f5a4a36a48e0b4af6cd3e28e39f3f006e9a447da2b3' ,
1605- } ,
1606- refundTx : '02000000000101b3a27d449a6e003f9fe3283ecdf64a0b8ea4364a5a4f616ac296a793898090300000000000feffffff011e020000000000001600146d2146bb49f6d1de6b4f14e0a8074c79b887cef50447304402202a7dce2e39cf86ee1d7c1e9cc55f1e0fb26932fd22e5437e5e5804a9e5d220b1022031aa177ea085c10c4d54b2f5aa528aac0013b67f9ee674070aa2fb51894de80e0121025b4d40682bbcb5456a9d658971b725666a3cccaa2fb45d269d2f1486bf85b3c000636382012088a820be8719b9427f1551c4234f8b02d8f8aa055ae282b2e9eef6c155326ae951061f8876a914e546b01d8c9d9bf35f9f115132ce8eab7191a68d88ac67046716ca67b17576a9146d2146bb49f6d1de6b4f14e0a8074c79b887cef588ac686816ca67' ,
1607- } ;
1570+ if ( typeof target [ prop ] !== 'function' ) {
1571+ return target [ prop ] ;
1572+ }
16081573
1609- // Add to onGoingSwaps map
1610- onGoingSwaps . set ( swap . swapId , swap ) ;
1574+ return async ( ...args : Parameters < HubApi [ typeof prop ] > ) => new Promise ( async ( resolveInterceptedAction ) => {
1575+ const requestName = String ( prop ) ;
1576+ const [ firstArg ] = args ;
1577+ console . warn ( `[Demo] Mocking Hub call: ${ requestName } ("${ firstArg } ")` ) ;
1578+
1579+ if ( ignoreHubRequests . includes ( requestName ) ) {
1580+ return ;
1581+ }
1582+
1583+ if ( requestName === 'setupSwap' ) {
1584+ const swap = await firstArg as SetupSwapArgs ;
1585+ const signerTransaction : SetupSwapResult = {
1586+ nim : {
1587+ transaction : new Uint8Array ( ) ,
1588+ serializedTx : '0172720036a3b2ca9e0de8b369e6381753ebef945a020091fa7bbddf959616767c50c50962c9e056ade9c400000000000000989680000000000000000000c3e23d0500a60100010366687aadf862bd776c8fc18b8e9f8e20089714856ee233b3902a591d0d5f292520000000000000000000000000000000000000000000000000000000000000000000200demoSerializedTx' ,
1589+ hash : '6c58b337a907fe000demoTxHash8a1f4ab4fdc0f69b1e582f' ,
1590+ raw : {
1591+ signerPublicKey : new Uint8Array ( ) ,
1592+ signature : new Uint8Array ( ) ,
1593+ sender : 'NQ86 D3M0 SW4P NB59 U3F8 NDLX CE0P AFMX Y52S' ,
1594+ senderType : 2 ,
1595+ recipient : swap . redeem . recipient ,
1596+ recipientType : 0 ,
1597+ value : swap . redeem . value ,
1598+ fee : 0 ,
1599+ validityStartHeight : swap . redeem . validityStartHeight ,
1600+ extraData : new Uint8Array ( ) ,
1601+ flags : 0 ,
1602+ networkId : 5 ,
1603+ proof : new Uint8Array ( ) ,
1604+ } ,
1605+ } ,
1606+ btc : {
1607+ serializedTx : '0200000000010168c8952af998f2c68412a848a72d1f9b0b7ff27417df1cb85514c97474b51ba40000000000ffffffff026515000000000000220020bf0ffdd2ffb9a579973455cfe9b56515538b79361d5ae8a4d255dea2519ef77864c501000000000016001428257447efe2d254ce850ea2760274d233d86e5c024730440220792fa932d9d0591e3c5eb03f47d05912a1e21f3e76d169e383af66e47896ac8c02205947df5523490e4138f2da0fc5c9da3039750fe43bd217b68d26730fdcae7fbe012102ef8d4b51d1a075e67d62baa78991d5fc36a658fec28d8b978826058168ed2a1a00000000' ,
1608+ hash : '3090808993a796c26a614f5a4a36a48e0b4af6cd3e28e39f3f006e9a447da2b3' ,
1609+ } ,
1610+ refundTx : '02000000000101b3a27d449a6e003f9fe3283ecdf64a0b8ea4364a5a4f616ac296a793898090300000000000feffffff011e020000000000001600146d2146bb49f6d1de6b4f14e0a8074c79b887cef50447304402202a7dce2e39cf86ee1d7c1e9cc55f1e0fb26932fd22e5437e5e5804a9e5d220b1022031aa177ea085c10c4d54b2f5aa528aac0013b67f9ee674070aa2fb51894de80e0121025b4d40682bbcb5456a9d658971b725666a3cccaa2fb45d269d2f1486bf85b3c000636382012088a820be8719b9427f1551c4234f8b02d8f8aa055ae282b2e9eef6c155326ae951061f8876a914e546b01d8c9d9bf35f9f115132ce8eab7191a68d88ac67046716ca67b17576a9146d2146bb49f6d1de6b4f14e0a8074c79b887cef588ac686816ca67' ,
1611+ } ;
16111612
1612- resolve ( signerTransaction ) ;
1613- return
1614- }
1613+ // Add to onGoingSwaps map
1614+ onGoingSwaps . set ( swap . swapId , swap ) ;
16151615
1616- // Wait for router readiness
1617- await new Promise < void > ( ( resolve ) => {
1618- demoRouter . onReady ( resolve ) ;
1619- } ) ;
1616+ resolveInterceptedAction ( signerTransaction ) ;
1617+ return ;
1618+ }
16201619
1621- // eslint-disable-next-line no-console
1622- console . log ( '[Demo] Redirecting to fallback modal' ) ;
1623- demoRouter . push ( `/ ${ DemoModal . Fallback } ` ) ;
1620+ // Wait for router readiness
1621+ await new Promise < void > ( ( resolve ) => {
1622+ demoRouter . onReady ( resolve ) ;
16241623 } ) ;
1625- }
1626- return target [ prop ] ;
1624+
1625+ console . log ( '[Demo] Redirecting to fallback modal' ) ;
1626+ demoRouter . push ( `/${ DemoModal . Fallback } ` ) ;
1627+ } ) ;
16271628 } ,
16281629 } ) ;
16291630 }
16301631}
1631-
0 commit comments