Skip to content

Commit

Permalink
Merge pull request #21 from BlakeKaufman/10-add-notifications-to-cont…
Browse files Browse the repository at this point in the history
…act-payments

10 add notifications to contact payments
  • Loading branch information
BlakeKaufman authored Oct 5, 2024
2 parents e6a384f + 1f616ed commit 745c0ff
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ export default function ContactsTransactionItem(props) {

if (txData.uuid === txID) {
console.log('TRUE');
console.log(txData);
// console.log(txData);
return {
...tx,
data: txDataType ? txData : {...txData, isRedeemed: true},
Expand Down Expand Up @@ -602,7 +602,7 @@ function ConfirmedOrSentTransaction({
const {nodeInformation, masterInfoObject} = useGlobalContextProvider();
const {textColor} = GetThemeColors();

console.log(props.transaction, 'TES');
// console.log(props.transaction, 'TES');
return (
<View style={[styles.transactionContainer, {alignItems: 'center'}]}>
{txParsed.isDeclined ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import GetThemeColors from '../../../../hooks/themeColors';
import ThemeImage from '../../../../functions/CustomElements/themeImage';
import {assetIDS} from '../../../../functions/liquidWallet/assetIDS';
import useDebounce from '../../../../hooks/useDebounce';
import {getSignleContact} from '../../../../../db';

export default function SendAndRequestPage(props) {
const navigate = useNavigation();
Expand Down Expand Up @@ -415,6 +416,12 @@ export default function SendAndRequestPage(props) {
);

async function handleSubmit() {
// sendPushNotification({
// selectedContactUsername: selectedContact.uniqueName,
// myProfile: globalContactsInformation.myProfile,
// sendingAmountSat: 5000,
// });
// return;
if (!nodeInformation.didConnectToNode) {
navigate.navigate('ErrorScreen', {
errorMessage: 'Please reconnect to the internet to use this feature',
Expand Down Expand Up @@ -486,6 +493,7 @@ export default function SendAndRequestPage(props) {
paymentType,
decodedAddedContacts,
publicKey,
selectedContact,
),
});
// setIsPerformingSwap(true);
Expand Down Expand Up @@ -607,6 +615,7 @@ export default function SendAndRequestPage(props) {
paymentType,
decodedAddedContacts,
publicKey,
selectedContact,
);
navigate.goBack();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,15 +261,7 @@ export default function SendPaymentScreen({
navigate,
setHasError,
});
}, [
nodeInformation,
btcAdress,
goBackFunction,
liquidNodeInformation,
masterInfoObject,
setWebViewArgs,
webViewRef,
]);
}, []);

return (
<GlobalThemeView>
Expand Down
4 changes: 2 additions & 2 deletions app/functions/liquidWallet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ async function getLiquidTxFee({amountSat, address}) {
: process.env.BLITZ_LIQUID_TESTNET_ADDRESS;
console.log(amountSat, address, '!');

const fee_rate = 100; // this is the sat/vB * 100 fee rate. Example 280 would equal a fee rate of .28 sat/vB. 100 would equal .1 sat/vB
const fee_rate = process.env.BOLTZ_ENVIRONMENT === 'testnet' ? 20 : 100; // this is the sat/vB * 100 fee rate. Example 280 would equal a fee rate of .28 sat/vB. 100 would equal .1 sat/vB

const builder = await new TxBuilder().create(network);

Expand Down Expand Up @@ -234,7 +234,7 @@ async function sendLiquidTransaction(amountSat, address, doesNeedToWait) {
const update = await client.fullScan(wollet);
await wollet.applyUpdate(update);

const fee_rate = 100; // this is the sat/vB * 100 fee rate. Example 280 would equal a fee rate of .28 sat/vB. 100 would equal .1 sat/vB
const fee_rate = process.env.BOLTZ_ENVIRONMENT === 'testnet' ? 20 : 100; // this is the sat/vB * 100 fee rate. Example 280 would equal a fee rate of .28 sat/vB. 100 would equal .1 sat/vB
const builder = await new TxBuilder().create(network);
await builder.addLbtcRecipient(address, amountSat);
await builder.feeRate(fee_rate);
Expand Down
54 changes: 54 additions & 0 deletions app/functions/messaging/publishMessage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {AblyRealtime} from './getToken';
import {encriptMessage} from './encodingAndDecodingMessages';
import formatBalanceAmount from '../formatNumber';
import {getSignleContact} from '../../../db';

export async function pubishMessageToAbly(
fromPrivKey,
Expand All @@ -11,6 +13,7 @@ export async function pubishMessageToAbly(
paymentType,
decodedContacts,
sendingPublicKey,
selectedContact,
) {
try {
const channel = AblyRealtime.channels.get('blitzWalletPayments');
Expand Down Expand Up @@ -59,6 +62,11 @@ export async function pubishMessageToAbly(
// return contact;
// } else return contact;
// });
sendPushNotification({
selectedContactUsername: selectedContact.uniqueName,
myProfile: globalContactsInformation.myProfile,
data: data,
});

toggleGlobalContactsInformation(
{
Expand All @@ -79,3 +87,49 @@ export async function pubishMessageToAbly(
console.log(err);
}
}

async function sendPushNotification({
selectedContactUsername,
myProfile,
data,
}) {
console.log(selectedContactUsername);
const retrivedContact = await getSignleContact(
selectedContactUsername.toLowerCase(),
);

if (retrivedContact.length === 0) return;
const [selectedContact] = retrivedContact;

const devicePushKey = selectedContact?.pushNotifications?.key?.encriptedText;
const deviceType = selectedContact?.pushNotifications?.platform;

console.log(devicePushKey, deviceType);

if (!devicePushKey || !deviceType) return;
let message;
if (JSON.parse(data).isRequest) {
message = `${myProfile.uniqueName} requested you ${formatBalanceAmount(
JSON.parse(data).amountMsat / 1000,
)} sats`;
} else {
message = `${myProfile.uniqueName} paid you ${formatBalanceAmount(
JSON.parse(data).amountMsat / 1000,
)} sats`;
}

await fetch(
'http://localhost:8888/.netlify/functions/contactsPushNotification',
{
method: 'POST', // Specify the HTTP method
headers: {
'Content-Type': 'application/json', // Set the content type to JSON
},
body: JSON.stringify({
devicePushKey: devicePushKey,
deviceType: deviceType,
message: message,
}),
},
);
}
4 changes: 3 additions & 1 deletion db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,9 @@ export async function getSignleContact(wantedName) {
where('contacts.myProfile.uniqueNameLower', '==', wantedName.toLowerCase()),
);
const querySnapshot = await getDocs(q);
return new Promise(resolve => resolve(querySnapshot.docs));
// Map through querySnapshot and return the data from each document
const contactData = querySnapshot.docs.map(doc => doc.data());
return new Promise(resolve => resolve(contactData));
}
export async function canUsePOSName(
collectionName = 'blitzWalletUsers',
Expand Down

0 comments on commit 745c0ff

Please sign in to comment.