Skip to content

Commit

Permalink
Added notifications for tips and payments
Browse files Browse the repository at this point in the history
  • Loading branch information
f-r00t committed Aug 31, 2022
1 parent 3e68a90 commit 8734d8f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 36 deletions.
65 changes: 30 additions & 35 deletions src/MainScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { Styles } from './Styles';
import { handleURI, toastPopUp } from './Utilities';
import { getBestCache, cacheSync, getKeyPair, getMessage, getExtra, optimizeMessages, intToRGB, hashCode, get_avatar } from './HuginUtilities';
import { ProgressBar } from './ProgressBar';
import { savePreferencesToDatabase, saveToDatabase, loadPayeeDataFromDatabase } from './Database';
import { boardsMessageExists, getBoardsMessage, savePreferencesToDatabase, saveToDatabase, loadPayeeDataFromDatabase } from './Database';
import { Globals, initGlobals } from './Globals';
import { reportCaughtException } from './Sentry';
import { processBlockOutputs, makePostRequest } from './NativeCode';
Expand Down Expand Up @@ -92,7 +92,7 @@ async function init(navigation) {
optimizeMessages(10);

}

});

Globals.wallet.on('deadnode', () => {
Expand Down Expand Up @@ -189,7 +189,7 @@ function handleNotification(notification) {

payee = new URLSearchParams(payee).toString();

let url = 'xkr://' + payee;
let url = 'xkr://'.replace('address=', '') + payee;

Linking.openURL(url);

Expand All @@ -208,6 +208,8 @@ function handleNotification(notification) {
export async function sendNotification(transaction) {
// /* Don't show notifications if disabled */

console.log('WTFWTFWTF');

let this_addr = await Address.fromAddress(Globals.wallet.getPrimaryAddress());

let my_public_key = this_addr.spend.publicKey;
Expand All @@ -216,40 +218,33 @@ export async function sendNotification(transaction) {

let payments = [];

let nbrOfTxs = amount_received / 10000;

//optimizeMessages(nbrOfTxs);

// for (transfer in transaction.transfers)

let extra = await getExtra(transaction.hash);



let message = await getMessage(extra);

// let messages = await getMessages();
// Globals.logger.addLogMessage('MessagesDB: ' + JSON.stringify(messages));
Globals.logger.addLogMessage('Received message: ' + JSON.stringify(message));
let nbrOfTxs = amount_received / 100000;

let from = message.from;
console.log('Receieved ', nbrOfTxs);

let payees = await loadPayeeDataFromDatabase();
for (payee in payees) {

if (payees[payee].address == from) {
from = payees[payee].nickname;
}

}

// PushNotification.localNotification({
// title: from,//'Incoming transaction received!',
// //message: `You were sent ${prettyPrintAmount(transaction.totalAmount(), Config)}`,
// message: message.msg,
// data: JSON.stringify(transaction.hash),
// largeIconUrl: get_avatar(message.from, 64),
// });
if (nbrOfTxs < 1) {
return;
}
console.log(transaction);
console.log(transaction.paymentID);
let isTip = await boardsMessageExists(transaction.paymentID);
console.log('isTip', isTip);
let tippedMsg;
isTip = (isTip && transaction.paymentID != '');
console.log('isTip2', isTip);
if (isTip) {
tippedMsg = await getBoardsMessage(transaction.paymentID);
}
console.log(tippedMsg);
const title = (isTip ? 'Tip received' : 'Payment received');
const message = (isTip ? `You just received a tip for your post "${tippedMsg[0].message}" in ${tippedMsg[0].board} worth ${nbrOfTxs} XKR` : `You just received ${nbrOfTxs} XKR`);

PushNotification.localNotification({
title: title,//'Incoming transaction received!',
//message: `You were sent ${prettyPrintAmount(transaction.totalAmount(), Config)}`,
message: message,
data: JSON.stringify(transaction.hash)
});
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/TransactionsScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export class TransactionDetailsScreenNoTranslation extends React.Component {
{...this.props}
/>}

{tipTo &&
{tipTo && this.state.transaction.paymentID !== '' &&
<>
<View style={{width: '90%', margin: 10}}>
<Text style={{
Expand Down

0 comments on commit 8734d8f

Please sign in to comment.