2020-03-04 23:11:15 +01:00
|
|
|
|
var LOCALE = 'en'
|
|
|
|
|
|
2020-04-01 22:18:46 +02:00
|
|
|
|
var EventHub = new Vue();
|
|
|
|
|
|
2020-03-04 23:11:15 +01:00
|
|
|
|
var LNbits = {
|
|
|
|
|
api: {
|
|
|
|
|
request: function (method, url, macaroon, data) {
|
|
|
|
|
return axios({
|
|
|
|
|
method: method,
|
|
|
|
|
url: url,
|
|
|
|
|
headers: {
|
2020-04-16 13:02:20 +02:00
|
|
|
|
'api_key': macaroon
|
2020-03-04 23:11:15 +01:00
|
|
|
|
},
|
|
|
|
|
data: data
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
createInvoice: function (wallet, amount, memo) {
|
2020-03-07 22:27:00 +01:00
|
|
|
|
return this.request('post', '/api/v1/payments', wallet.inkey, {
|
|
|
|
|
out: false,
|
2020-03-04 23:11:15 +01:00
|
|
|
|
amount: amount,
|
|
|
|
|
memo: memo
|
|
|
|
|
});
|
|
|
|
|
},
|
2020-03-07 22:27:00 +01:00
|
|
|
|
payInvoice: function (wallet, bolt11) {
|
2020-04-01 22:18:46 +02:00
|
|
|
|
return this.request('post', '/api/v1/payments', wallet.adminkey, {
|
2020-03-07 22:27:00 +01:00
|
|
|
|
out: true,
|
|
|
|
|
bolt11: bolt11
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
getPayments: function (wallet, checkPending) {
|
|
|
|
|
var query_param = (checkPending) ? '?check_pending' : '';
|
|
|
|
|
return this.request('get', ['/api/v1/payments', query_param].join(''), wallet.inkey);
|
2020-03-04 23:11:15 +01:00
|
|
|
|
},
|
2020-03-07 22:27:00 +01:00
|
|
|
|
getPayment: function (wallet, payhash) {
|
|
|
|
|
return this.request('get', '/api/v1/payments/' + payhash, wallet.inkey);
|
2020-03-04 23:11:15 +01:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
href: {
|
|
|
|
|
createWallet: function (walletName, userId) {
|
|
|
|
|
window.location.href = '/wallet?' + (userId ? 'usr=' + userId + '&' : '') + 'nme=' + walletName;
|
|
|
|
|
},
|
|
|
|
|
deleteWallet: function (walletId, userId) {
|
|
|
|
|
window.location.href = '/deletewallet?usr=' + userId + '&wal=' + walletId;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
map: {
|
|
|
|
|
extension: function (data) {
|
|
|
|
|
var obj = _.object(['code', 'isValid', 'name', 'shortDescription', 'icon'], data);
|
|
|
|
|
obj.url = ['/', obj.code, '/'].join('');
|
|
|
|
|
return obj;
|
|
|
|
|
},
|
|
|
|
|
user: function (data) {
|
|
|
|
|
var obj = _.object(['id', 'email', 'extensions', 'wallets'], data);
|
|
|
|
|
var mapWallet = this.wallet;
|
|
|
|
|
obj.wallets = obj.wallets.map(function (obj) {
|
|
|
|
|
return mapWallet(obj);
|
|
|
|
|
}).sort(function (a, b) {
|
2020-04-01 22:18:46 +02:00
|
|
|
|
return a.name.localeCompare(b.name);
|
2020-03-04 23:11:15 +01:00
|
|
|
|
});
|
2020-04-05 12:19:25 +02:00
|
|
|
|
obj.walletOptions = obj.wallets.map(function (obj) {
|
|
|
|
|
return {
|
|
|
|
|
label: [obj.name, ' (', obj.id , ')'].join(''),
|
|
|
|
|
value: obj.id
|
|
|
|
|
};
|
|
|
|
|
});
|
2020-03-04 23:11:15 +01:00
|
|
|
|
return obj;
|
|
|
|
|
},
|
|
|
|
|
wallet: function (data) {
|
|
|
|
|
var obj = _.object(['id', 'name', 'user', 'adminkey', 'inkey', 'balance'], data);
|
2020-03-07 22:27:00 +01:00
|
|
|
|
obj.msat = obj.balance;
|
|
|
|
|
obj.sat = Math.round(obj.balance / 1000);
|
2020-03-04 23:11:15 +01:00
|
|
|
|
obj.fsat = new Intl.NumberFormat(LOCALE).format(obj.sat);
|
|
|
|
|
obj.url = ['/wallet?usr=', obj.user, '&wal=', obj.id].join('');
|
|
|
|
|
return obj;
|
2020-03-07 22:27:00 +01:00
|
|
|
|
},
|
|
|
|
|
payment: function (data) {
|
|
|
|
|
var obj = _.object(['payhash', 'pending', 'amount', 'fee', 'memo', 'time'], data);
|
2020-03-31 19:05:25 +02:00
|
|
|
|
obj.date = Quasar.utils.date.formatDate(new Date(obj.time * 1000), 'YYYY-MM-DD HH:mm');
|
2020-03-07 22:27:00 +01:00
|
|
|
|
obj.msat = obj.amount;
|
|
|
|
|
obj.sat = obj.msat / 1000;
|
|
|
|
|
obj.fsat = new Intl.NumberFormat(LOCALE).format(obj.sat);
|
|
|
|
|
obj.isIn = obj.amount > 0;
|
|
|
|
|
obj.isOut = obj.amount < 0;
|
|
|
|
|
obj.isPaid = obj.pending == 0;
|
|
|
|
|
return obj;
|
2020-03-04 23:11:15 +01:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
utils: {
|
|
|
|
|
formatSat: function (value) {
|
|
|
|
|
return new Intl.NumberFormat(LOCALE).format(value);
|
|
|
|
|
},
|
|
|
|
|
notifyApiError: function (error) {
|
|
|
|
|
var types = {
|
|
|
|
|
400: 'warning',
|
|
|
|
|
401: 'warning',
|
|
|
|
|
500: 'negative'
|
2020-03-31 19:05:25 +02:00
|
|
|
|
};
|
2020-03-04 23:11:15 +01:00
|
|
|
|
Quasar.plugins.Notify.create({
|
2020-03-31 19:05:25 +02:00
|
|
|
|
timeout: 5000,
|
2020-03-04 23:11:15 +01:00
|
|
|
|
type: types[error.response.status] || 'warning',
|
|
|
|
|
message: error.response.data.message ||Â null,
|
2020-03-07 22:27:00 +01:00
|
|
|
|
caption: [error.response.status, ' ', error.response.statusText].join('').toUpperCase() ||Â null,
|
2020-03-04 23:11:15 +01:00
|
|
|
|
icon: null
|
|
|
|
|
});
|
2020-04-01 22:18:46 +02:00
|
|
|
|
},
|
|
|
|
|
exportCSV: function (columns, data) {
|
|
|
|
|
var wrapCsvValue = function(val, formatFn) {
|
|
|
|
|
var formatted = formatFn !== void 0
|
|
|
|
|
? formatFn(val)
|
|
|
|
|
: val;
|
|
|
|
|
|
|
|
|
|
formatted = (formatted === void 0 || formatted === null)
|
|
|
|
|
? ''
|
|
|
|
|
: String(formatted);
|
|
|
|
|
|
|
|
|
|
formatted = formatted.split('"').join('""');
|
|
|
|
|
|
|
|
|
|
return `"${formatted}"`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var content = [columns.map(function (col) {
|
|
|
|
|
return wrapCsvValue(col.label);
|
|
|
|
|
})].concat(data.map(function (row) {
|
|
|
|
|
return columns.map(function (col) {
|
|
|
|
|
return wrapCsvValue(
|
|
|
|
|
(typeof col.field === 'function')
|
|
|
|
|
? col.field(row)
|
|
|
|
|
: row[(col.field === void 0) ? col.name : col.field],
|
|
|
|
|
col.format
|
|
|
|
|
);
|
|
|
|
|
}).join(',');
|
|
|
|
|
})).join('\r\n');
|
|
|
|
|
|
|
|
|
|
var status = Quasar.utils.exportFile('table-export.csv', content, 'text/csv');
|
|
|
|
|
|
|
|
|
|
if (status !== true) {
|
|
|
|
|
Quasar.plugins.Notify.create({
|
|
|
|
|
message: 'Browser denied file download...',
|
|
|
|
|
color: 'negative',
|
|
|
|
|
icon: null
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-03-04 23:11:15 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var windowMixin = {
|
|
|
|
|
data: function () {
|
|
|
|
|
return {
|
2020-04-03 22:37:34 +02:00
|
|
|
|
g: {
|
2020-03-04 23:11:15 +01:00
|
|
|
|
visibleDrawer: false,
|
|
|
|
|
extensions: [],
|
|
|
|
|
user: null,
|
|
|
|
|
wallet: null,
|
2020-03-07 22:27:00 +01:00
|
|
|
|
payments: [],
|
2020-03-04 23:11:15 +01:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
toggleDarkMode: function () {
|
|
|
|
|
this.$q.dark.toggle();
|
|
|
|
|
this.$q.localStorage.set('lnbits.darkMode', this.$q.dark.isActive);
|
|
|
|
|
},
|
|
|
|
|
copyText: function (text, message) {
|
|
|
|
|
var notify = this.$q.notify;
|
|
|
|
|
Quasar.utils.copyToClipboard(text).then(function () {
|
2020-04-05 12:19:25 +02:00
|
|
|
|
notify({message: message || 'Copied to clipboard!'});
|
2020-03-04 23:11:15 +01:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
created: function () {
|
|
|
|
|
this.$q.dark.set(this.$q.localStorage.getItem('lnbits.darkMode'));
|
|
|
|
|
if (window.user) {
|
2020-04-03 22:37:34 +02:00
|
|
|
|
this.g.user = Object.freeze(LNbits.map.user(window.user));
|
2020-03-04 23:11:15 +01:00
|
|
|
|
}
|
|
|
|
|
if (window.wallet) {
|
2020-04-03 22:37:34 +02:00
|
|
|
|
this.g.wallet = Object.freeze(LNbits.map.wallet(window.wallet));
|
2020-03-04 23:11:15 +01:00
|
|
|
|
}
|
|
|
|
|
if (window.extensions) {
|
2020-04-03 22:37:34 +02:00
|
|
|
|
var user = this.g.user;
|
|
|
|
|
this.g.extensions = Object.freeze(window.extensions.map(function (data) {
|
2020-03-04 23:11:15 +01:00
|
|
|
|
return LNbits.map.extension(data);
|
|
|
|
|
}).map(function (obj) {
|
|
|
|
|
if (user) {
|
|
|
|
|
obj.isEnabled = user.extensions.indexOf(obj.code) != -1;
|
|
|
|
|
} else {
|
|
|
|
|
obj.isEnabled = false;
|
|
|
|
|
}
|
|
|
|
|
return obj;
|
|
|
|
|
}).sort(function (a, b) {
|
|
|
|
|
return a.name > b.name;
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|