-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
111 lines (96 loc) · 3.11 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
let axios = require('axios') //JS LIBRARY FOR REST API FUNCTIONS
async function getCollection(user,offset) { //GET A USERS OBJKT COLLECTION IN SETS OF TEN
try {
const res = await axios.get('https://api.better-call.dev/v1/account/mainnet/' + user + '/token_balances?size=10&offset=' + offset)
return res.data
} catch (error) {
return null
}
}
async function getUserInfo(user) {
try {
const res = await axios.get('https://api.better-call.dev/v1/account/mainnet/' + user + '/token_balances')
return res.data.total
} catch (error) {
return null
}
}
async function getCreations(id,offset){
try {
const res = await axios.get('https://api.better-call.dev/v1/tokens/mainnet/metadata?creator=' + id + '&size=10&offset='+offset)
return res.data
} catch (error) {
return null
}
}
async function getTokenInfo(id){
try {
const res = await axios.get('https://api.better-call.dev/v1/tokens/mainnet/metadata?token_id=' + id.toString())
return res.data[0]
} catch (error) {
return null
}
}
//Tezos Address
async function getProfile(user){
//Get Collection
getUserInfo(user).then((response) => {
let collection = new Array()
for (let index = 0; index < response / 10; index++) {
collection.push(getCollection(user,index*10))
}
Promise.all(collection).then((values) => {
let balances = new Array()
values.flat().forEach(element => {
balances = balances.concat(element.balances)
});
console.log("collection"+balances)
//DO SOMETHING WITH THE USER COLLECTION HERE
});
});
//Get Creations
getCreations(user,0).then((data) => {
console.log("creations" + data)
//DO SOMETHING WITH THE FIRST 10 USER CREATIONS HERE
})
}
//Get Single HeN Object
async function getObjkts(id){
let queue = new Array()
//Multiple Objects
if(typeof id == 'object'){
id.forEach(element => {
queue.push(getTokenInfo(element))
});
Promise.all(queue).then((values) => {
console.log(values)
//DO SOMETHING WITH THE OBJKTS META DATA HERE
});
}else{
queue.push(getTokenInfo(id))
Promise.all(queue).then((values) => {
console.log(values)
//DO SOMETHING WITH THE OBJKT META DATA HERE
});
}
}
// Get all GLTF Models in a Users Collection
// let user = 'tz1dy6DgvAjeBZpfRE3NoL84BRm4tupyKfFf'
// getUserInfo(user).then((response) => {
// let collection = new Array()
// for (let index = 0; index < response / 10; index++) {
// collection.push(getCollection(user,index*10))
// }
// Promise.all(collection).then((values) => {
// let balances = new Array()
// values.flat().forEach(element => {
// balances = balances.concat(element.balances)
// });
// let models = balances.filter(item => item.formats)
// models = models.filter(item => item.formats[0].mimeType.includes('gltf'))
// });
// });
//Fetch Objkt Info in an inputted Array
// getObjkts([36899])
//Get all collections and the last ten creations from a Users Tezos Address
getProfile('tz1dy6DgvAjeBZpfRE3NoL84BRm4tupyKfFf')