Skip to content

Commit

Permalink
Send notification on completed topup
Browse files Browse the repository at this point in the history
  • Loading branch information
minibits-cash committed Sep 20, 2023
1 parent c753c76 commit 5169d52
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/models/Invoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const InvoiceModel = types
const decoded = decodeInvoice(self.encodedInvoice)
const {expiry, timestamp} = getInvoiceData(decoded)

const expiresAt = addSeconds(new Date(timestamp * 1000), expiry as number)
const expiresAt = addSeconds(new Date(timestamp as number * 1000), expiry as number)

log.trace(
`Invoice expiry is ${expiry}, setting expiresAt to ${expiresAt}`,
Expand Down
12 changes: 6 additions & 6 deletions src/screens/TopupScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export const TopupScreen: FC<WalletStackScreenProps<'Topup'>> = observer(

setResultModalInfo({
status: TransactionStatus.COMPLETED,
message: `Payment received! Your wallet has been credited with ${invoice.amount} sats.`,
message: `Your invoice has been paid and your wallet balance credited with ${invoice.amount} sats.`,
})

setTransactionStatus(TransactionStatus.COMPLETED)
Expand Down Expand Up @@ -725,7 +725,7 @@ export const TopupScreen: FC<WalletStackScreenProps<'Topup'>> = observer(
) : (
<SendAsNostrDMBlock
toggleNostrDMModal={toggleNostrDMModal}
encodedTokenToSend={invoiceToPay as string}
encodedInvoiceToSend={invoiceToPay as string}
contactToSendFrom={contactToSendFrom as Contact}
contactToSendTo={contactToSendTo as Contact}
relaysToShareTo={relaysToShareTo}
Expand Down Expand Up @@ -917,7 +917,7 @@ const ShareAsQRCodeBlock = observer(function (props: {

const SendAsNostrDMBlock = observer(function (props: {
toggleNostrDMModal: any
encodedTokenToSend: string
encodedInvoiceToSend: string
contactToSendFrom: Contact
contactToSendTo: Contact
relaysToShareTo: string[]
Expand All @@ -942,7 +942,7 @@ const SendAsNostrDMBlock = observer(function (props: {
]}>
<Text
selectable
text={props.encodedTokenToSend}
text={props.encodedInvoiceToSend}
style={{color: tokenTextColor, paddingBottom: spacing.medium}}
size="xxs"
/>
Expand All @@ -954,7 +954,7 @@ const SendAsNostrDMBlock = observer(function (props: {
) : (
<View style={$buttonContainer}>
<Button
text="Send"
text="Send request"
onPress={props.sendAsNostrDM}
style={{marginRight: spacing.medium}}
LeftAccessory={() => (
Expand Down Expand Up @@ -997,7 +997,7 @@ const SendAsNostrDMBlock = observer(function (props: {
icon="faCheckCircle"
iconColor={colors.palette.success200}
title="Success!"
message="Coins have been succesfully sent."
message="Payment reuest has been succesfully sent."
/>
<View style={$buttonContainer}>
<Button
Expand Down
12 changes: 12 additions & 0 deletions src/screens/WalletScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import { NotificationService } from '../services/notificationService'
import PagerView, { PagerViewOnPageScrollEventData } from 'react-native-pager-view'
import { ExpandingDot, ScalingDot, SlidingBorder, SlidingDot } from 'react-native-animated-pagination-dots'
import { PaymentRequest, PaymentRequestStatus } from '../models/PaymentRequest'
import { Invoice } from '../models/Invoice'

const AnimatedPagerView = Animated.createAnimatedComponent(PagerView)
const deploymentKey = APP_ENV === Env.PROD ? CODEPUSH_PRODUCTION_DEPLOYMENT_KEY : CODEPUSH_STAGING_DEPLOYMENT_KEY
Expand Down Expand Up @@ -122,6 +123,7 @@ export const WalletScreen: FC<WalletScreenProps> = observer(

EventEmitter.on('receiveTokenCompleted', onReceiveTokenCompleted)
EventEmitter.on('receivePaymentRequest', onReceivePaymentRequest)
EventEmitter.on('topupCompleted', onTopupCompleted)

return () => {
EventEmitter.off('receiveTokenCompleted', onReceiveTokenCompleted)
Expand Down Expand Up @@ -197,6 +199,16 @@ export const WalletScreen: FC<WalletScreenProps> = observer(
result.picture,
)
}


const onReceiveTopupCompleted = async (invoice: Invoice) => { // TODO make it ReceivedEventResult
log.trace('onReceiveTopupCompleted event handler trigerred', invoice)

await NotificationService.createLocalNotification(
`⚡ ${invoice.amount} sats received!`,
`Your invoice has been paid and your wallet balance credited with ${invoice.amount} sats.`,
)
}


const onReceivePaymentRequest = async (result: ReceivedEventResult) => {
Expand Down

0 comments on commit 5169d52

Please sign in to comment.