-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
170 lines (140 loc) · 3.72 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import Arweave from 'arweave/web';
const arweaveOptions = {
host: 'arweave.net',// Hostname or IP address for a Arweave node
port: 443, // Port, defaults to 1984
protocol: 'https', // Network protocol http or https, defaults to http
timeout: 30000, // Network request timeouts in milliseconds
logging: false, // Enable network request logging
};
const arweave = Arweave.init(arweaveOptions);
export const getEncryptedWallet = async (publicKey) => {
let arweaveTransactions = [];
try {
arweaveTransactions = await arweave.arql({
op: "and",
expr1: {
op: "equals",
expr1: "ar-auth-public-key",
expr2: publicKey
},
expr2: {
op: "equals",
expr1: "app-id",
expr2: "ar-auth"
}
});
}
catch(error) {
console.log("unable to get wallet transactions");
}
return arweaveTransactions;
}
export const getWalletAddress = async (wallet) => {
let arweaveAddress = undefined;
try {
arweaveAddress = await arweave.wallets.jwkToAddress(wallet);
}
catch(error) {
console.log("unable to get wallet address");
}
return arweaveAddress;
}
export const getWalletBalance = async (walletAddress) => {
let arweaveBalance = undefined;
try {
const balance = await arweave.wallets.getBalance(walletAddress);
if (balance) {
arweaveBalance = arweave.ar.winstonToAr(balance);
}
}
catch(error) {
console.log("unable to get wallet balance");
}
return arweaveBalance;
}
export const getWalletTransactions = async (walletAddress) => {
let arweaveTransactions = [];
try {
arweaveTransactions = await arweave.arql({
op: "equals",
expr1: "from",
expr2: walletAddress
});
}
catch(error) {
console.log("unable to get wallet transactions");
}
return arweaveTransactions;
}
export const getTransactionDetails = async (transactionId) => {
let transactionDetails = null;
try {
transactionDetails = await arweave.transactions.get(transactionId);
}
catch(error) {
console.error(error);
console.error("unable to get transaction details");
}
return transactionDetails;
}
export const saveReminder = async(userWallet, data) => {
let reminderSaved = false;
try {
let transaction = await arweave.createTransaction({ data: data.reminder}, userWallet);
transaction.addTag('wevr-reminder-date', data.reminderDate);
transaction.addTag('wevr-reminder-saved', 'yes');
await arweave.transactions.sign(transaction, userWallet);
const response = await arweave.transactions.post(transaction);
reminderSaved = response.status === 200 ? true : false;
}
catch (error) {
console.error(error);
console.error("unable to save reminder");
}
return reminderSaved;
}
export const getUserReminders = async (walletAddress) => {
let userMemos = [];
try {
userMemos = await arweave.arql({
op: "and",
expr1: {
op: "equals",
expr1: "from",
expr2: walletAddress
},
expr2: {
op: "equals",
expr1: "wevr-reminder-saved",
expr2: "yes"
}
});
}
catch(error) {
console.log(error);
console.log("unable to get user reminders");
}
return userMemos;
}
export const getUserDetails = async (walletAddress) => {
let arweaveTransactions = [];
try {
arweaveTransactions = await arweave.arql({
op: 'and',
expr1:{
op: 'equals',
expr1: 'App-Name',
expr2: 'arweave-id'
},
expr2:{
op: 'equals',
expr1: 'from',
expr2: walletAddress,
},
});
}
catch(error) {
console.log("unable to get user details");
}
return arweaveTransactions;
}