From e0d4ecf6ae02e1661dafa932825b77d1c348f7a2 Mon Sep 17 00:00:00 2001 From: woudini Date: Wed, 2 Aug 2017 13:48:09 -0400 Subject: [PATCH] feat(Contacts): expose uuid function for iOS to override --- src/contact.js | 4 +--- src/contacts.js | 12 ++++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/contact.js b/src/contact.js index b112e8f0d..e819286c2 100644 --- a/src/contact.js +++ b/src/contact.js @@ -6,7 +6,6 @@ const Metadata = require('./metadata'); const assoc = require('ramda/src/assoc'); const prop = require('ramda/src/prop'); const map = require('ramda/src/map'); -const uuid = require('uuid'); const FacilitatedTx = require('./facilitatedTx'); class Contact { @@ -29,8 +28,7 @@ Contact.factory = function (o) { return new Contact(o); }; -Contact.new = function (o) { - const id = uuid(); +Contact.new = function (o, id) { const namedContact = assoc('id', id, o); return new Contact(namedContact); }; diff --git a/src/contacts.js b/src/contacts.js index 36f32fefa..d71d2b6b8 100644 --- a/src/contacts.js +++ b/src/contacts.js @@ -50,11 +50,15 @@ Contacts.prototype.wipe = function () { }; Contacts.prototype.new = function (object) { - const c = Contact.new(object); + const c = Contact.new(object, this.uuid()); this.list = R.assoc(c.id, c, this.list); return c; }; +Contacts.prototype.uuid = function() { + return uuid(); +} + const fromNull = (str) => str || ''; const isContact = (uniqueId) => R.where({id: R.equals(uniqueId)}); const contains = R.curry((substr, key) => R.where(R.objOf(key, R.compose(R.contains(substr), fromNull)))); @@ -217,7 +221,7 @@ const cancelResponse = function (id) { // I want you to pay me Contacts.prototype.sendPR = function (userId, intendedAmount, id, note, initiatorSource) { // we should reserve the address (check buy-sell) - should probable be an argument - id = id ? id : uuid() + id = id ? id : this.uuid() const contact = this.get(userId); const account = initiatorSource != null ? MyWallet.wallet.hdwallet.accounts[initiatorSource] : MyWallet.wallet.hdwallet.defaultAccount; const address = account.receiveAddress; @@ -235,7 +239,7 @@ Contacts.prototype.sendPR = function (userId, intendedAmount, id, note, initiato // request payment request (step-1) Contacts.prototype.sendRPR = function (userId, intendedAmount, id, note) { - id = id ? id : uuid() + id = id ? id : this.uuid() const message = requestPaymentRequest(intendedAmount, id, note); const contact = this.get(userId); return this.sendMessage(userId, REQUEST_PAYMENT_REQUEST_TYPE, message) @@ -245,7 +249,7 @@ Contacts.prototype.sendRPR = function (userId, intendedAmount, id, note) { // payment request response Contacts.prototype.sendPRR = function (userId, txHash, id) { - id = id ? id : uuid() + id = id ? id : this.uuid() const message = paymentRequestResponse(id, txHash); const contact = this.get(userId); return this.sendMessage(userId, PAYMENT_REQUEST_RESPONSE_TYPE, message)