@@ -30,17 +30,16 @@ import {
30
30
} from '@/wallets/client/fragments'
31
31
import { gql , useApolloClient , useMutation , useQuery } from '@apollo/client'
32
32
import { useDecryption , useEncryption , useSetKey , useWalletLoggerFactory , useWalletsUpdatedAt , WalletStatus } from '@/wallets/client/hooks'
33
- import { useCallback , useEffect , useMemo , useRef , useState } from 'react'
33
+ import { useCallback , useEffect , useMemo , useState } from 'react'
34
34
import {
35
- isEncryptedField , isTemplate , isWallet , protocolAvailable , protocolClientSchema , protocolLogName , reverseProtocolRelationName ,
36
- walletLud16Domain
35
+ isEncryptedField , isTemplate , isWallet , protocolAvailable , protocolLogName , reverseProtocolRelationName , walletLud16Domain
37
36
} from '@/wallets/lib/util'
38
37
import { protocolTestSendPayment } from '@/wallets/client/protocols'
39
38
import { timeoutSignal } from '@/lib/time'
40
39
import { FAST_POLL_INTERVAL_MS , WALLET_SEND_PAYMENT_TIMEOUT_MS } from '@/lib/constants'
41
40
import { useToast } from '@/components/toast'
42
41
import { useMe } from '@/components/me'
43
- import { useTemplates , useWallets , useWalletsLoading } from '@/wallets/client/context'
42
+ import { useTemplates , useWallets } from '@/wallets/client/context'
44
43
import { requestPersistentStorage } from '@/components/use-indexeddb'
45
44
46
45
export function useWalletsQuery ( ) {
@@ -446,127 +445,10 @@ function useEncryptConfig (defaultProtocol, options = {}) {
446
445
return useMemo ( ( ) => ( { encryptConfig, ready } ) , [ encryptConfig , ready ] )
447
446
}
448
447
449
- // TODO(wallet-v2): remove migration code
450
- // =============================================================
451
- // ****** Below is the migration code for WALLET v1 -> v2 ******
452
- // remove when we can assume migration is complete (if ever)
453
- // =============================================================
454
-
455
- export function useWalletMigrationMutation ( ) {
456
- const wallets = useWallets ( )
457
- const loading = useWalletsLoading ( )
458
- const client = useApolloClient ( )
459
- const { encryptConfig, ready } = useEncryptConfig ( )
460
-
461
- // XXX We use a ref for the wallets to avoid duplicate wallets
462
- // Without a ref, the migrate callback would depend on the wallets and thus update every time the migration creates a wallet.
463
- // This update would then cause the useEffect in wallets/client/context/hooks that triggers the migration to run again before the first migration is complete.
464
- const walletsRef = useRef ( wallets )
465
- useEffect ( ( ) => {
466
- if ( ! loading ) walletsRef . current = wallets
467
- } , [ loading ] )
468
-
469
- const migrate = useCallback ( async ( { name, enabled, ...configV1 } ) => {
470
- const protocol = { name, send : true }
471
-
472
- const configV2 = migrateConfig ( protocol , configV1 )
473
-
474
- const isSameProtocol = ( p ) => {
475
- const sameName = p . name === protocol . name
476
- const sameSend = p . send === protocol . send
477
- const sameConfig = Object . keys ( p . config )
478
- . filter ( k => ! [ '__typename' , 'id' ] . includes ( k ) )
479
- . every ( k => p . config [ k ] === configV2 [ k ] )
480
- return sameName && sameSend && sameConfig
481
- }
482
-
483
- const exists = walletsRef . current . some ( w => w . name === name && w . protocols . some ( isSameProtocol ) )
484
- if ( exists ) return
485
-
486
- const schema = protocolClientSchema ( protocol )
487
- await schema . validate ( configV2 )
488
-
489
- const encrypted = await encryptConfig ( configV2 , { protocol } )
490
-
491
- // decide if we create a new wallet (templateName) or use an existing one (walletId)
492
- const templateName = getWalletTemplateName ( protocol )
493
- let walletId
494
- const wallet = walletsRef . current . find ( w =>
495
- w . name === name && ! w . protocols . some ( p => p . name === protocol . name && p . send )
496
- )
497
- if ( wallet ) {
498
- walletId = Number ( wallet . id )
499
- }
500
-
501
- await client . mutate ( {
502
- mutation : protocolUpsertMutation ( protocol ) ,
503
- variables : {
504
- ...( walletId ? { walletId } : { templateName } ) ,
505
- enabled,
506
- ...encrypted
507
- }
508
- } )
509
- } , [ client , encryptConfig ] )
510
-
511
- return useMemo ( ( ) => ( { migrate, ready : ready && ! loading } ) , [ migrate , ready , loading ] )
512
- }
513
-
514
448
export function useUpdateKeyHash ( ) {
515
449
const [ mutate ] = useMutation ( UPDATE_KEY_HASH )
516
450
517
451
return useCallback ( async ( keyHash ) => {
518
452
await mutate ( { variables : { keyHash } } )
519
453
} , [ mutate ] )
520
454
}
521
-
522
- function migrateConfig ( protocol , config ) {
523
- switch ( protocol . name ) {
524
- case 'LNBITS' :
525
- return {
526
- url : config . url ,
527
- apiKey : config . adminKey
528
- }
529
- case 'PHOENIXD' :
530
- return {
531
- url : config . url ,
532
- apiKey : config . primaryPassword
533
- }
534
- case 'BLINK' :
535
- return {
536
- url : config . url ,
537
- apiKey : config . apiKey ,
538
- currency : config . currency
539
- }
540
- case 'LNC' :
541
- return {
542
- pairingPhrase : config . pairingPhrase ,
543
- localKey : config . localKey ,
544
- remoteKey : config . remoteKey ,
545
- serverHost : config . serverHost
546
- }
547
- case 'WEBLN' :
548
- return { }
549
- case 'NWC' :
550
- return {
551
- url : config . nwcUrl
552
- }
553
- default :
554
- return config
555
- }
556
- }
557
-
558
- function getWalletTemplateName ( protocol ) {
559
- switch ( protocol . name ) {
560
- case 'LNBITS' :
561
- case 'PHOENIXD' :
562
- case 'BLINK' :
563
- case 'NWC' :
564
- return protocol . name
565
- case 'LNC' :
566
- return 'LND'
567
- case 'WEBLN' :
568
- return 'ALBY'
569
- default :
570
- return null
571
- }
572
- }
0 commit comments