Skip to content

Commit

Permalink
Improve event handling, better warn on mint delete
Browse files Browse the repository at this point in the history
  • Loading branch information
minibits-cash committed Jan 31, 2024
1 parent 92a2272 commit de3c3ae
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "minibits_wallet",
"version": "0.1.5-beta.28",
"version": "0.1.5-beta.29",
"private": true,
"scripts": {
"android:clean": "cd android && ./gradlew clean",
Expand Down
13 changes: 9 additions & 4 deletions src/models/ContactsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,15 @@ import {
self.publicPubkey = publicPubkey
log.debug('[setPublicPubkey]', publicPubkey)
},
setLastPendingReceivedCheck() {
const ts: number = Math.floor(Date.now() / 1000)
log.trace('[setLastPendingReceivedCheck]', {ts})
self.lastPendingReceivedCheck = ts
setLastPendingReceivedCheck(ts?: number) {
if(ts) {
self.lastPendingReceivedCheck = ts
log.trace('[setLastPendingReceivedCheck]', {ts})
return
}

const ts2: number = Math.floor(Date.now() / 1000)
log.trace('[setLastPendingReceivedCheck]', {ts2})
},
addReceivedEventId(id: string) {
self.receivedEventIds.push(id)
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Contacts/PrivateContacts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ export const PrivateContacts = observer(function (props: {
leftIconInverse={true}
leftIconColor={colors.palette.iconGreen200}
text='Private contacts'
subText={"Add other Minibits users as your private contacts. Every user gets sharable wallet name in an email-like format. You can pay privately to your contacts anytime without cumbersome token copying / pasting."}
subText={"Add other Minibits users as your private contacts. Every user gets sharable @minibits.cash wallet address. You can pay privately to your contacts anytime even if they are offline."}
onPress={gotoNew}
/>
<ListItem
Expand Down
4 changes: 2 additions & 2 deletions src/screens/MintsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ export const MintsScreen: FC<SettingsStackScreenProps<'Mints'>> = observer(funct
let message: string = ''

if (proofsByMint && proofsByMint.length > 0) {
message = 'Your wallet has a positive balance with this mint. If removed, your ecash will be lost. '
message = `Your wallet has ${proofsStore.getMintBalance(selectedMint.mintUrl)?.balance} sats balance with this mint. If removed, your ecash will be lost!\n\n`
}

message += 'Do you really want to remove this mint from the wallet?'
message += `Do you really want to remove ${selectedMint.hostname} - ${selectedMint.shortname} from the wallet?`

Alert.alert(
'Warning',
Expand Down
2 changes: 1 addition & 1 deletion src/screens/PictureScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const PictureScreen: FC<PictureScreenProps> = observer(function PictureSc
</Pressable>
)
})}
{pictures.length === 0 && (
{pictures.length === 0 && !isLoading && (
<Card
ContentComponent={<ListItem
leftIcon='faXmark'
Expand Down
4 changes: 2 additions & 2 deletions src/screens/ProfileScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export const ProfileScreen: FC<ProfileScreenProps> = observer(
<>
<ListItem
text='Create wallet address'
subText='Your wallet address allows you to receive encrypted ecash over Nostr. At the same time it serves as your Lightning address, so that you can receive payments from any Lightning wallet.'
subText='Your wallet address allows you to receive encrypted ecash over Nostr. At the same time it serves as your Lightning address, so that you can receive payments from any Lightning wallet or zaps on Nostr social network.'
/>
<View style={$buttonContainer}>
<Button
Expand All @@ -189,7 +189,7 @@ export const ProfileScreen: FC<ProfileScreenProps> = observer(
<>
<ListItem
text='Your Minibits wallet address'
subText={`Share your wallet address to receive encrypted ecash over Nostr. At the same time it serves as your Lightning address, so that you can receive payments from any Lightning wallet.`}
subText={`Share your wallet address to receive encrypted ecash over Nostr. At the same time it serves as your Lightning address, so that you can receive payments from any Lightning wallet or zaps on Nostr social network.`}
leftIcon='faCircleUser'
bottomSeparator={true}
style={{paddingRight: spacing.small}}
Expand Down
2 changes: 1 addition & 1 deletion src/services/minibitsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '@env'
import { WalletProfile, WalletProfileRecord } from "../models/WalletProfileStore"

// refresh
// refresh // refresh

const getRandomPictures = async function () {
const url = MINIBITS_SERVER_API_HOST + '/profile'
Expand Down
10 changes: 6 additions & 4 deletions src/services/walletService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,23 +199,25 @@ const checkPendingReceived = async function () {
try {
// ignore all kinds of duplicate events
if(events.some(ev => ev.id === event.id)) {
log.error(Err.ALREADY_EXISTS_ERROR, 'Duplicate event received by this subscription, skipping...', event.id)
log.error(Err.ALREADY_EXISTS_ERROR, 'Duplicate event received by this subscription, skipping...', {id: event.id, created_at: event.created_at})
return
}

events.push(event)

if(contactsStore.eventAlreadyReceived(event.id)) {
log.error(Err.ALREADY_EXISTS_ERROR, 'Event has been processed in the past, skipping...', {id: event.id})
log.error(Err.ALREADY_EXISTS_ERROR, 'Event has been processed in the past, skipping...', {id: event.id, created_at: event.created_at})
return
}

contactsStore.addReceivedEventId(event.id)
// move window to receive events to the last event created_at to avoid recive it again
contactsStore.setLastPendingReceivedCheck(event.created_at)

// decrypt message content
const decrypted = await NostrClient.decryptNip04(event.pubkey, event.content)

log.trace('Received event', {decrypted})
log.trace('[checkPendingReceived]', 'Received event', {id: event.id, created_at: event.created_at})

// get sender profile and save it as a contact
const sentFromPubkey = event.pubkey
Expand Down Expand Up @@ -250,7 +252,7 @@ const checkPendingReceived = async function () {
// parse incoming message
const incoming = IncomingParser.findAndExtract(decrypted)

log.trace('Incoming data', {incoming})
log.trace('[checkPendingReceived]', 'Incoming data', {incoming})

if(incoming.type === IncomingDataType.CASHU) {

Expand Down

0 comments on commit de3c3ae

Please sign in to comment.