tronair-gui
Version:
Web application/GUI for performing airdrops on the TRON blockchain
277 lines (229 loc) • 7.9 kB
JavaScript
import DataSheetBase from './DataSheetBase.js';
export default class DataSheet_acc_tokens extends DataSheetBase {
constructor(id, updateCb) {
super(id, updateCb);
this.requestedKeyPath = ""; // this value can be specified in the React Studio data sheet UI
}
makeDefaultItems() {
// eslint-disable-next-line no-unused-vars
let key = 1;
// eslint-disable-next-line no-unused-vars
let item;
// The contents of this data sheet will be loaded by plugin 'Generic JSON'.
item = {};
this.items.push(item);
item['balance'] = "1000000";
item['name'] = "_";
item.key = key++;
// item = {};
// this.items.push(item);
// item['balance'] = "14070695";
// item['owner_address'] = "TAm6Bbxw6F5RiZmKdEaqxFctiq2Cku8S5w";
// item['name'] = "1001429";
// item.key = key++;
// item = {};
// this.items.push(item);
// item['balance'] = "124825305";
// item['owner_address'] = "TDGy2M9qWBepSHDEutWWxWd1JZfmAed3BP";
// item['name'] = "1000322";
// item.key = key++;
// item = {};
// this.items.push(item);
// item['balance'] = "1256256";
// item['owner_address'] = "TLFraeBr1qpHzMuv45knHoTiHr2UFty3A5";
// item['name'] = "1000430";
// item.key = key++;
// item = {};
// this.items.push(item);
// item['balance'] = "10816289";
// item['owner_address'] = "TRxAWB5Jo919U3rVWBkm8uMViViWRrUst2";
// item['name'] = "1001344";
// item.key = key++;
// item = {};
// this.items.push(item);
// item['balance'] = "4819928";
// item['owner_address'] = "TLrMgZkrp7RcqpSocmrEoouLu57crESnFQ";
// item['name'] = "1001451";
// item.key = key++;
// item = {};
// this.items.push(item);
// item['balance'] = "2164240";
// item['owner_address'] = "TYGe1UnXwMpxa5xhX5BPf6moSvwnbhAPu1";
// item['name'] = "1001628";
// item.key = key++;
// item = {};
// this.items.push(item);
// item['balance'] = "1196258";
// item['owner_address'] = "TQw7CVALENBqCP3uZuo1KxiTnvCqGnoeod";
// item['name'] = "1000416";
// item.key = key++;
// item = {};
// this.items.push(item);
// item['balance'] = "814901";
// item['owner_address'] = "TLJhxKVcPed2wuW2XMYAFNqa9iW6toDDGZ";
// item['name'] = "1001655";
// item.key = key++;
// item = {};
// this.items.push(item);
// item['balance'] = "120";
// item['owner_address'] = "TWDUanVdxEShjpbiX57ExztMCDy8vCFcHh";
// item['name'] = "1001132";
// item.key = key++;
// item = {};
// this.items.push(item);
// item['balance'] = "70734766";
// item['owner_address'] = "TGQwBNht8h3zev4gBtDMoQjWE2WJm1Zr9B";
// item['name'] = "1000532";
// item.key = key++;
// item = {};
// this.items.push(item);
// item['balance'] = "999995";
// item['owner_address'] = "TETfrKQpteFMfwY5vLNdSJeDMJZJDgNnBo";
// item['name'] = "1000645";
// item.key = key++;
// item = {};
// this.items.push(item);
// item['balance'] = "11000";
// item['owner_address'] = "TN8p9sUqKgdnvWqbE4dCq6bTV6GhkpZhXP";
// item['name'] = "1000526";
// item.key = key++;
// item = {};
// this.items.push(item);
// item['balance'] = "14716852800";
// item['owner_address'] = "TP6PtaBSMM6sfWtWWD9k77YHWGmh7K3Lae";
// item['name'] = "1002072";
// item.key = key++;
// item = {};
// this.items.push(item);
// item['balance'] = "44400";
// item['owner_address'] = "TWqKTJ5JhyD7rsbbWzEvS5ZZD9Q5QPPvSH";
// item['name'] = "1000562";
// item.key = key++;
// item = {};
// this.items.push(item);
// item['balance'] = "18614478700";
// item['owner_address'] = "TF5Bn4cJCT6GVeUgyCN4rBhDg42KBrpAjg";
// item['name'] = "1002000";
// item.key = key++;
// item = {};
// this.items.push(item);
// item['balance'] = "135000";
// item['owner_address'] = "TUsTUrKVE1QL5ZNM4rCZ7Ld9G3vGxtbHCK";
// item['name'] = "1000080";
// item.key = key++;
// item = {};
// this.items.push(item);
// item['balance'] = "39";
// item['owner_address'] = "TKR5bPJX8VMHBER3ikUWGghFnHxiC6kEPA";
// item['name'] = "1000748";
// item.key = key++;
// item = {};
// this.items.push(item);
// item['balance'] = "50000000";
// item['owner_address'] = "TYWmiPERm9kWUcnduqaE5jxT7eeZxfn5SQ";
// item['name'] = "1002099";
// item.key = key++;
// item = {};
// this.items.push(item);
// item['balance'] = "1";
// item['owner_address'] = "TV4dQ6hMLQ821Rxi7T46Cwsdp2NsrkFBqM";
// item['name'] = "1002145";
// item.key = key++;
}
urlFromOptions(options) {
const baseUrl = "https://apilist.tronscan.org";
// let baseUrl = options.url || 'https://apilist.tronscan.org';
let path = options.servicePath || '';
if (path.length > 0 && path.substr(0, 1) !== '/' && baseUrl.substr(baseUrl.length - 1, 1) !== '/')
path = '/'+path;
let query = options.query || '';
if (query.length > 0) {
const dataSlots = options.dataSlots || {};
query = "?" + this.expandSlotTemplateString(query, dataSlots);
}
return baseUrl + path + query;
}
// this function's implementation is provided by React Studio.
_fetchComplete = (err, options) => {
if (err) {
console.log('** Web service write failed: ', err, options);
} else {
if (this.updateCb) this.updateCb(this);
}
}
addItem(item, options) {
super.addItem(item, options);
const url = this.urlFromOptions(options);
let headers = {};
headers['Content-Type'] = 'application/json';
const fetchOpts = {
method: 'POST',
headers: headers,
body: JSON.stringify(item),
};
fetch(url, fetchOpts)
.then((response) => {
if (response.status >= 400) {
console.log("** Error sending %s to %s, response: ", fetchOpts.method, url, response);
throw new Error("Server error: "+response.status);
}
return response.json();
})
.then((json) => {
this._fetchComplete(null, options);
})
.catch((exc) => {
this._fetchComplete(exc, options);
});
}
removeItem(item, options) {
super.removeItem(item, options);
const url = this.urlFromOptions(options);
let headers = {};
headers['Content-Type'] = 'application/json';
const fetchOpts = {
method: 'DELETE',
headers: headers,
body: JSON.stringify(item),
};
fetch(url, fetchOpts)
.then((response) => {
if (response.status >= 400) {
console.log("** Error sending %s to %s, response: ", fetchOpts.method, url, response);
throw new Error("Server error: "+response.status);
}
return response.json();
})
.then((json) => {
this._fetchComplete(null, options);
})
.catch((exc) => {
this._fetchComplete(exc, options);
});
}
replaceItemByRowIndex(idx, item, options) {
super.replaceItemByRowIndex(idx, item, options);
const url = this.urlFromOptions(options);
let headers = {};
headers['Content-Type'] = 'application/json';
const fetchOpts = {
method: 'PUT',
headers: headers,
body: JSON.stringify(item),
};
fetch(url, fetchOpts)
.then((response) => {
if (response.status >= 400) {
console.log("** Error sending %s to %s, response: ", fetchOpts.method, url, response);
throw new Error("Server error: "+response.status);
}
return response.json();
})
.then((json) => {
this._fetchComplete(null, options);
})
.catch((exc) => {
this._fetchComplete(exc, options);
});
}
}