mirror of
https://github.com/minibits-cash/minibits_wallet.git
synced 2026-10-06 03:38:24 +00:00
Fixes to recovery
This commit is contained in:
Vendored
+1
-1
@@ -1 +1 @@
|
||||
019a2ff9-adc8-7f97-92c1-ec6d92db39a3
|
||||
019a3577-44d5-7927-8015-e5a30263640e
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "minibits_wallet",
|
||||
"version": "0.3.2-beta.4",
|
||||
"version": "0.3.2-beta.5",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"android:clean": "cd android && ./gradlew clean",
|
||||
|
||||
@@ -43,7 +43,6 @@ export const ImportBackupScreen = observer(function ImportBackupScreen({ route }
|
||||
const {
|
||||
mintsStore,
|
||||
proofsStore,
|
||||
userSettingsStore,
|
||||
contactsStore,
|
||||
walletProfileStore,
|
||||
walletStore,
|
||||
@@ -65,7 +64,6 @@ export const ImportBackupScreen = observer(function ImportBackupScreen({ route }
|
||||
mintsStore: MintsStoreSnapshot,
|
||||
contactsStore: ContactsStoreSnapshot,
|
||||
} | undefined>(undefined) // type tbd
|
||||
const [profileToRecover, setProfileToRecover] = useState<WalletProfileRecord | undefined>(undefined)
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const [error, setError] = useState<AppError | undefined>()
|
||||
const [statusMessage, setStatusMessage] = useState<string>()
|
||||
@@ -155,8 +153,8 @@ export const ImportBackupScreen = observer(function ImportBackupScreen({ route }
|
||||
|
||||
const onConfirmBackup = async function () {
|
||||
try {
|
||||
if(!backup) {
|
||||
throw new AppError(Err.VALIDATION_ERROR, 'Missing backup.')
|
||||
if(!backup || !seedHashRef.current) {
|
||||
throw new AppError(Err.VALIDATION_ERROR, 'Missing backup or seed.')
|
||||
}
|
||||
|
||||
LayoutAnimation.easeInEaseOut()
|
||||
@@ -244,18 +242,18 @@ export const ImportBackupScreen = observer(function ImportBackupScreen({ route }
|
||||
mnemonic
|
||||
}
|
||||
|
||||
// update seed to the provided one
|
||||
keys.SEED = seed
|
||||
|
||||
// In case there is a profile linked to provided seedHash,
|
||||
// it's address is recovered to the current profile.
|
||||
// As we regenerate ecash from provided seed, it is linked to current profile as well.
|
||||
// it's address, avatar and seed is recovered to the current profile.
|
||||
await walletProfileStore.recover(
|
||||
keys.walletId,
|
||||
seedHashRef.current,
|
||||
)
|
||||
|
||||
await KeyChain.saveWalletKeys(keys)
|
||||
// update seed to the provided one
|
||||
const keysCopy = { ...keys }
|
||||
keysCopy.SEED = seed
|
||||
|
||||
await KeyChain.saveWalletKeys(keysCopy)
|
||||
walletStore.cleanCachedWalletKeys()
|
||||
|
||||
if(!mintsStore.mintExists(MINIBITS_MINT_URL)) {
|
||||
@@ -369,26 +367,13 @@ export const ImportBackupScreen = observer(function ImportBackupScreen({ route }
|
||||
}
|
||||
/>
|
||||
)}
|
||||
{isValidMnemonic && isValidBackup && profileToRecover && (
|
||||
<Card
|
||||
style={$card}
|
||||
ContentComponent={
|
||||
<ListItem
|
||||
text={profileToRecover.nip05}
|
||||
subTx="profileToRecoverDesc"
|
||||
LeftComponent={<View style={[$numIcon, {backgroundColor: numIconColor}]}><Text text={'3'}/></View>}
|
||||
style={$item}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
{isValidMnemonic && isValidBackup && (
|
||||
<Card
|
||||
style={$card}
|
||||
ContentComponent={
|
||||
<ListItem
|
||||
text={'Wallet address not found'}
|
||||
subText="Wallet profile linked to the provided seed not found, new one will be created for you."
|
||||
text={'Wallet profile recovery'}
|
||||
subText="While importing the wallet we'll try to recover wallet address and avatar linked to the provided seed."
|
||||
LeftComponent={<View style={[$numIcon, {backgroundColor: numIconColor}]}><Text text={'3'}/></View>}
|
||||
style={$item}
|
||||
/>
|
||||
|
||||
@@ -29,7 +29,7 @@ export const RecoverWalletAddressScreen = observer(function RecoverWalletAddress
|
||||
},
|
||||
})
|
||||
|
||||
const { walletProfileStore, userSettingsStore, walletStore, authStore } = useStores()
|
||||
const { walletProfileStore, walletStore } = useStores()
|
||||
|
||||
const mnemonicInputRef = useRef<TextInput>(null)
|
||||
const seedRef = useRef<Uint8Array | null>(null)
|
||||
@@ -119,16 +119,13 @@ export const RecoverWalletAddressScreen = observer(function RecoverWalletAddress
|
||||
seedHashRef.current
|
||||
)
|
||||
|
||||
userSettingsStore.setIsOnboarded(true)
|
||||
|
||||
setStatusMessage(translate('recovery_completed'))
|
||||
await delay(1000)
|
||||
setStatusMessage('')
|
||||
setIsLoading(false)
|
||||
|
||||
navigation.dispatch(
|
||||
StackActions.popToTop()
|
||||
)
|
||||
//@ts-ignore
|
||||
navigation.navigate('Tabs')
|
||||
} catch (e: any) {
|
||||
handleError(e)
|
||||
}
|
||||
|
||||
@@ -454,18 +454,18 @@ export const SeedRecoveryScreen = observer(function SeedRecoveryScreen({ route }
|
||||
mnemonic
|
||||
}
|
||||
|
||||
// update seed to the provided one
|
||||
keys.SEED = seed
|
||||
|
||||
// In case there is a profile linked to provided seedHash,
|
||||
// it's address is recovered to the current profile.
|
||||
// As we regenerate ecash from provided seed, it is linked to current profile as well.
|
||||
// it's address, avatar and seed is recovered to the current profile.
|
||||
await walletProfileStore.recover(
|
||||
keys.walletId,
|
||||
seedHashRef.current,
|
||||
)
|
||||
|
||||
await KeyChain.saveWalletKeys(keys)
|
||||
// update seed to the provided one
|
||||
const keysCopy = { ...keys }
|
||||
keysCopy.SEED = seed
|
||||
|
||||
await KeyChain.saveWalletKeys(keysCopy)
|
||||
walletStore.cleanCachedWalletKeys()
|
||||
|
||||
if(!mintsStore.mintExists(MINIBITS_MINT_URL)) {
|
||||
@@ -578,7 +578,7 @@ return (
|
||||
<Button
|
||||
onPress={startRecovery}
|
||||
tx={startIndex === 0 ? 'startRecovery' : 'nextInterval'}
|
||||
preset={(startIndex === 0 || totalRecoveredAmount > 0) ? 'default' : 'secondary'}
|
||||
preset={(startIndex === 0 || totalRecoveredAmount == 0) ? 'default' : 'secondary'}
|
||||
style={{marginRight: spacing.small}}
|
||||
disabled={selectedMintUrl ? false : true}
|
||||
/>
|
||||
|
||||
@@ -198,7 +198,7 @@ const updateDeviceToken = async function (deviceToken: string) {
|
||||
return walletProfile
|
||||
}
|
||||
|
||||
// TODO remove pubkey from params
|
||||
// recover profile address, avatar and seed from former profile (if exists, otherwise only seed is linked) to the current one.
|
||||
const recoverProfile = async function (walletId: string, seedHash: string) {
|
||||
const url = MINIBITS_SERVER_API_HOST + '/profile'
|
||||
const method = 'PUT'
|
||||
@@ -214,12 +214,12 @@ const recoverProfile = async function (walletId: string, seedHash: string) {
|
||||
jwtAuthRequired: true
|
||||
}) as WalletProfileRecord
|
||||
|
||||
log.info('[recoverProfile]', `Recovered wallet address`, {walletAddress: walletProfile.nip05})
|
||||
log.info('[recoverProfile]', `Recovered wallet profile `, {walletAddress: walletProfile.nip05})
|
||||
|
||||
return walletProfile
|
||||
}
|
||||
|
||||
|
||||
// recover address only to the current profile, keep current avatar and seed
|
||||
const recoverAddress = async function (walletId: string, seedHash: string) {
|
||||
const url = MINIBITS_SERVER_API_HOST + '/profile'
|
||||
const method = 'PUT'
|
||||
@@ -229,13 +229,13 @@ const recoverAddress = async function (walletId: string, seedHash: string) {
|
||||
seedHash
|
||||
}
|
||||
|
||||
const walletProfile = await fetchApi(url + `/recover`, {
|
||||
const walletProfile = await fetchApi(url + `/recoverAddress`, {
|
||||
method,
|
||||
body,
|
||||
jwtAuthRequired: true
|
||||
}) as WalletProfileRecord
|
||||
|
||||
log.info('[recoverProfile]', `Recovered wallet address`, {seedHash, walletId})
|
||||
log.info('[recoverAddress]', `Recovered wallet address`, {seedHash, walletId})
|
||||
|
||||
return walletProfile
|
||||
}
|
||||
|
||||
@@ -1902,6 +1902,7 @@ const recoverMeltQuoteChange = async function (params: {mintUrl: string, meltQuo
|
||||
// check is quote has been paid
|
||||
const meltQuoteResponse: MeltQuoteResponse = await walletStore.checkLightningMeltQuote(mintUrl, meltQuote)
|
||||
const {quote, state} = meltQuoteResponse
|
||||
|
||||
const amountToRecover = meltQuoteResponse.change ? sumBlindSignatures(meltQuoteResponse.change) : 0
|
||||
|
||||
if (quote !== meltQuote) {
|
||||
@@ -2041,6 +2042,8 @@ const recoverMeltQuoteChange = async function (params: {mintUrl: string, meltQuo
|
||||
status: TransactionStatus.ERROR,
|
||||
data: JSON.stringify(transactionData)
|
||||
})
|
||||
|
||||
return { recoveredAmount: 0 }
|
||||
}
|
||||
/*
|
||||
* UNKNOWN
|
||||
|
||||
Reference in New Issue
Block a user