diff --git a/package.json b/package.json index eb17db5d..d30dc3b5 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/screens/Contacts/PrivateContacts.tsx b/src/screens/Contacts/PrivateContacts.tsx index b84615a5..555aab16 100644 --- a/src/screens/Contacts/PrivateContacts.tsx +++ b/src/screens/Contacts/PrivateContacts.tsx @@ -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 diff --git a/src/screens/Contacts/PublicContacts.tsx b/src/screens/Contacts/PublicContacts.tsx index 19018ac1..e157548e 100644 --- a/src/screens/Contacts/PublicContacts.tsx +++ b/src/screens/Contacts/PublicContacts.tsx @@ -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) diff --git a/src/screens/RelaysScreen.tsx b/src/screens/RelaysScreen.tsx index 9a1ccf6e..206db687 100644 --- a/src/screens/RelaysScreen.tsx +++ b/src/screens/RelaysScreen.tsx @@ -89,7 +89,7 @@ export const RelaysScreen: FC = 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 = observer( } const handleError = function (e: AppError): void { + setIsAddRelayModalVisible(false) setError(e) } diff --git a/src/services/minibitsService.ts b/src/services/minibitsService.ts index fd24f6a3..aa8f830d 100644 --- a/src/services/minibitsService.ts +++ b/src/services/minibitsService.ts @@ -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 } diff --git a/src/services/nostrService.ts b/src/services/nostrService.ts index a0adda0e..7839bd2e 100644 --- a/src/services/nostrService.ts +++ b/src/services/nostrService.ts @@ -382,7 +382,11 @@ const deleteKeyPair = async function (): Promise { 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}`) + } } diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 6593992e..92fe11c8 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -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}, + }) +} + +