get URI parsing into copay core
This commit is contained in:
parent
8acaca75fb
commit
1b780d268b
2 changed files with 24 additions and 18 deletions
|
|
@ -50,4 +50,23 @@ Structure.MAX_NON_HARDENED = MAX_NON_HARDENED;
|
|||
Structure.SHARED_INDEX = SHARED_INDEX;
|
||||
Structure.ID_INDEX = ID_INDEX;
|
||||
|
||||
Structure.parseBitcoinURI = function(uri) {
|
||||
var ret = {};
|
||||
var data = decodeURIComponent(uri);
|
||||
var splitDots = data.split(':');
|
||||
ret.protocol = splitDots[0];
|
||||
data = splitDots[1];
|
||||
var splitQuestion = data.split('?');
|
||||
ret.address = splitQuestion[0];
|
||||
var search = splitQuestion[1];
|
||||
data = JSON.parse('{"' + search.replace(/&/g, '","').replace(/=/g, '":"') + '"}',
|
||||
function(key, value) {
|
||||
return key === "" ? value : decodeURIComponent(value);
|
||||
});
|
||||
ret.amount = parseFloat(data.amount);
|
||||
ret.message = data.message;
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
module.exports = require('soop')(Structure);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue