Improve validations of new contacts and relays

This commit is contained in:
minibits-cash
2023-11-10 10:58:01 +01:00
parent 88da56e5a4
commit ceaf58660e
7 changed files with 44 additions and 16 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "minibits_wallet",
"version": "0.1.4-beta",
"version": "0.1.4-beta.2",
"private": true,
"scripts": {
"android:clean": "cd android && ./gradlew clean",
+11 -1
View File
@@ -15,7 +15,7 @@ import { Contact, ContactType } from '../../models/Contact'
import { StackNavigationProp } from '@react-navigation/stack'
import { ReceiveOption } from '../ReceiveOptionsScreen'
import { SendOption } from '../SendOptionsScreen'
import { infoMessage } from '../../utils/utils'
import { infoMessage, warningMessage } from '../../utils/utils'
@@ -90,6 +90,9 @@ export const PrivateContacts = observer(function (props: {
if (isExternalDomain) {
// validate and get profile data from nip05 server + relays
const profile = await getNostrProfile(newContactName) as NostrProfile
log.trace('[saveNewContact]', 'Server profile', profile)
const {pubkey, npub, nip05, name, picture} = profile
newContact = {
@@ -105,6 +108,13 @@ export const PrivateContacts = observer(function (props: {
} else {
// do it with single api call for minibts.cash profiles
const profileRecord = await MinibitsClient.getWalletProfileByNip05(newContactName + MINIBITS_NIP05_DOMAIN)
if(!profileRecord) {
warningMessage(`Profile name ${newContactName + MINIBITS_NIP05_DOMAIN} could not be found. Make sure the name is correct.`)
setIsLoading(false)
return
}
const npub = NostrClient.getNpubkey(profileRecord.pubkey)
const {pubkey, nip05, name, avatar: picture} = profileRecord
+2 -3
View File
@@ -252,8 +252,7 @@ export const PublicContacts = observer(function (props: {
const onSavePublicRelay = function () {
try {
if(newPublicRelay.startsWith('wss://')) {
if(newPublicRelay.startsWith('wss://')) {
if(relaysStore.alreadyExists(newPublicRelay)) {
setInfo('Relay already exists.')
return
@@ -274,7 +273,7 @@ export const PublicContacts = observer(function (props: {
setTimeout(() => setShouldReload(true), 1000)
return
} else {
throw new AppError(Err.VALIDATION_ERROR, 'Invalid relay URL')
throw new AppError(Err.VALIDATION_ERROR, 'Invalid relay URL.', newPublicRelay)
}
} catch(e: any) {
handleError(e)
+2 -1
View File
@@ -89,7 +89,7 @@ export const RelaysScreen: FC<SettingsScreenProps> = observer(
toggleAddRelayModal()
onConnect()
} else {
throw new AppError(Err.VALIDATION_ERROR, 'Invalid relay URL.')
throw new AppError(Err.VALIDATION_ERROR, 'Invalid relay URL.', newPublicRelay)
}
} catch(e: any) {
handleError(e)
@@ -97,6 +97,7 @@ export const RelaysScreen: FC<SettingsScreenProps> = observer(
}
const handleError = function (e: AppError): void {
setIsAddRelayModalVisible(false)
setError(e)
}
+9 -9
View File
@@ -1,5 +1,5 @@
import AppError, { Err } from "../utils/AppError"
import { Env, log } from "./logService"
import { log } from "./logService"
import {
MINIBITS_SERVER_API_KEY,
MINIBITS_SERVER_API_HOST,
@@ -19,7 +19,7 @@ const getRandomPictures = async function () {
headers,
})
log.trace(`Got pictures`, MINIBITS_SERVER_API_HOST, 'getRandomPictures')
log.trace('[getRandomPictures]', `Got pictures`)
return avatars
}
@@ -41,7 +41,7 @@ const createWalletProfile = async function (pubkey: string, walletId: string) {
body: JSON.stringify(requestBody)
})
log.info(`Created new profile`, walletProfile.pubkey, 'createWalletProfile')
log.info('[createWalletProfile]', `Created new profile`, walletProfile.pubkey)
return walletProfile
@@ -64,7 +64,7 @@ const updateWalletProfileName = async function (pubkey: string, update: {name: s
body: JSON.stringify(requestBody)
})
log.trace(`Updated wallet profile name`, {name}, 'updateWalletProfileName')
log.trace('[updateWalletProfileName]', `Updated wallet profile name`, {name})
return walletProfile
}
@@ -86,7 +86,7 @@ const updateWalletProfileAvatar = async function (pubkey: string, update: {avata
body: JSON.stringify(requestBody)
})
log.trace(`Updated wallet profile name`, {}, 'updateWalletProfileAvatar')
log.trace('[updateWalletProfileAvatar]', `Updated wallet profile name`, {avatar})
return walletProfile
}
@@ -111,7 +111,7 @@ const updateWalletProfileNip05 = async function (pubkey: string, update: {newPub
body: JSON.stringify(requestBody)
})
log.info(`Updated wallet profile nip05`, walletProfile.nip05, 'updateWalletProfileNip05')
log.info('[updateWalletProfileNip05]', `Updated wallet profile nip05`, walletProfile.nip05)
return walletProfile
}
@@ -127,7 +127,7 @@ const getWalletProfile = async function (pubkey: string) {
headers,
})
log.trace(`Got response`, walletProfile?.pubkey || null, 'getWalletProfile')
log.trace('[getWalletProfile]', `Got response`, walletProfile?.pubkey || null)
return walletProfile
}
@@ -143,7 +143,7 @@ const getWalletProfileByWalletId = async function (walletId: string) {
headers,
})
log.trace(`Got response`, walletProfile?.walletId || null, 'getWalletProfileByWalletId')
log.trace('[getWalletProfileByWalletId]', `Got response`, walletProfile?.walletId || null)
return walletProfile
}
@@ -159,7 +159,7 @@ const getWalletProfileByNip05 = async function (nip05: string) {
headers,
})
log.trace(`Got response`, walletProfile?.walletId || null, 'getWalletProfileByNip05')
log.trace('[getWalletProfileByNip05]', `Got response`, walletProfile?.walletId || null)
return walletProfile
}
+5 -1
View File
@@ -382,7 +382,11 @@ const deleteKeyPair = async function (): Promise<void> {
const getNormalizedRelayUrl = function (url: string): string {
return utils.normalizeURL(url)
try {
return utils.normalizeURL(url)
} catch (e: any) {
throw new AppError(Err.VALIDATION_ERROR, `Invalid relay URL: ${e.message}`)
}
}
+14
View File
@@ -37,3 +37,17 @@ export const infoMessage = function(message: string, description?: string) {
}
export const warningMessage = function(message: string, description?: string) {
const backgroundColor = colors.palette.accent500
return showMessage({
message,
description,
duration: 3000,
backgroundColor,
color: 'white',
style: {minHeight: spacing.screenHeight * 0.15, borderTopLeftRadius: spacing.medium, borderTopRightRadius: spacing.medium},
})
}