-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.ts
42 lines (40 loc) · 1018 Bytes
/
lib.ts
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
import Arweave from 'arweave';
import { Tag, Set } from '../types/types';
const arweave = Arweave.init({
host: 'arweave.net',
port: 443,
protocol: 'https'
});
export async function loadSet(tx_id : string) {
console.log("Loading set");
let set = {
title: '',
cards: [],
}
if (tx_id == '') return set;
// Get cards
await arweave.api.get(tx_id).then(results => {
if (results.data === "Request type not found.") return set;
set.cards = results.data;
}).catch(() => {
console.log("Could not load set");
return set;
});
// Get title
const tags_query = `{
transactions(
first: 1
ids: ["${tx_id}"]
) {
edges { node { tags { name value } } }
}
}`
await arweave.api.post('/graphql', {query: tags_query}).then((results) => {
const tags = results.data.data.transactions.edges[0].node.tags;
set.title = tags.find((tag : Tag) => tag.name == 'Title').value;
}).catch((err) => {
console.log(err);
return set;
})
return set;
}