Skip to content
Commits on Source (2)
<?php
/**
* BTC Wallet Controller
*
* @version 1
* @author Mark Harding
*/
namespace Minds\Controllers\api\v2\wallet;
use Minds\Core;
use Minds\Core\Entities\Actions;
use Minds\Helpers;
use Minds\Interfaces;
use Minds\Api\Factory;
use Minds\Core\Payments;
use Minds\Entities;
class btc implements Interfaces\Api
{
/**
* Returns merchant information
* @param array $pages
*
* API:: /v1/merchant/:slug
*/
public function get($pages)
{
Factory::isLoggedIn();
$response = [];
switch ($pages[0]) {
case "address":
$response['address'] = Core\Session::getLoggedInUser()->getBtcAddress();
break;
}
return Factory::response($response);
}
public function post($pages)
{
Factory::isLoggedIn();
$response = [];
$user = Core\Session::getLoggedInUser();
$save = new Actions\Save();
switch ($pages[0]) {
case "address":
$user->setBtcAddress($_POST['address']);
$save->setEntity($user)
->save();
break;
}
return Factory::response($response);
}
public function put($pages)
{
return Factory::response(array());
}
public function delete($pages)
{
return Factory::response(array());
}
}
<?php
$wireUrl = "{$vars['site_url']}wallet/tokens/transactions/{$vars['contract']}?{$vars['tracking']}";
$avatarUrl = "{$vars['sender']->getIconUrl()}";
$wireDate = date('M d, Y', ($vars['timestamp']));
$wireDate = date('M d, Y', ($vars['timestamp']));
$amount = number_format($vars['amount'], 2);
?>
<table cellspacing="8" cellpadding="8" border="0" width="600" align="center">
......@@ -19,7 +19,7 @@
<h4 <?php echo $emailStyles->getStyles('m-clear', 'm-fonts', 'm-header'); ?>>@<?php echo $vars['sender']->get('name'); ?> wired you</h4>
<p <?php echo $emailStyles->getStyles('m-fonts', 'm-subtitle', 'm-clear'); ?>>Transfer Date and Amount:</p>
<p <?php echo $emailStyles->getStyles('m-fonts', 'm-subtitle', 'm-clear'); ?>>
<?php echo $wireDate; ?>; +<?php echo $amount ?> tokens
<?php echo $wireDate; ?>; +<?php echo $amount ?>
</p>
</td>
</tr>
......@@ -36,7 +36,7 @@
<tr>
<td>
<p <?php echo $emailStyles->getStyles('m-clear', 'm-fonts'); ?>>
For any issues, including the recipient not receiving tokens, please contact us at <a href="mailto:info@minds.com">info@minds.com</a>.
For any issues, including the recipient not receiving their wire, please contact us at <a href="mailto:info@minds.com">info@minds.com</a>.
</p>
</td>
</tr>
......
<?php
$wireUrl = "{$vars['site_url']}wallet/tokens/transactions/{$vars['contract']}?{$vars['tracking']}";
$avatarUrl = "{$vars['receiver']->getIconUrl()}";
$wireDate = date('M d, Y', ($vars['timestamp']));
$wireDate = date('M d, Y', ($vars['timestamp']));
$amount = number_format($vars['amount'], 2);
?>
<table cellspacing="8" cellpadding="8" border="0" width="600" align="center">
......@@ -19,7 +19,7 @@
<h4 <?php echo $emailStyles->getStyles('m-clear', 'm-fonts', 'm-header'); ?>>You wired @<?php echo $vars['receiver']->get('name'); ?></h4>
<p <?php echo $emailStyles->getStyles('m-fonts', 'm-subtitle', 'm-clear'); ?>>Transfer Date and Amount:</p>
<p <?php echo $emailStyles->getStyles('m-fonts', 'm-subtitle', 'm-clear'); ?>>
<?php echo $wireDate; ?>; +<?php echo $amount ?> tokens
<?php echo $wireDate; ?>; +<?php echo $amount ?>
</p>
</td>
</tr>
......@@ -36,7 +36,7 @@
<tr>
<td>
<p <?php echo $emailStyles->getStyles('m-clear', 'm-fonts'); ?>>
For any issues, including the recipient not receiving tokens, please contact us at <a href="mailto:info@minds.com">info@minds.com</a>.
For any issues, including the recipient not receiving their wire, please contact us at <a href="mailto:info@minds.com">info@minds.com</a>.
</p>
</td>
</tr>
......
......@@ -40,7 +40,6 @@ class WireReceived extends EmailCampaign
];
$timestamp = gettype($this->wire->getTimestamp()) === 'object' ? $this->wire->getTimestamp()->time() : $this->wire->getTimestamp();
$amount = $this->wire->getMethod() === 'tokens' ? BigNumber::fromPlain($this->wire->getAmount(), 18)->toDouble() : $this->wire->getAmount();
$contract = $this->wire->getMethod() === 'onchain' ? 'wire' : 'offchain:wire';
$this->template->setTemplate('default.tpl');
......@@ -50,7 +49,7 @@ class WireReceived extends EmailCampaign
$this->template->set('email', $this->user->getEmail());
$this->template->set('guid', $this->user->getGUID());
$this->template->set('timestamp', $timestamp);
$this->template->set('amount', $amount);
$this->template->set('amount', $this->getAmountString($this->wire));
$this->template->set('sender', $this->wire->getSender());
$this->template->set('contract', $contract);
$this->template->set('campaign', $this->campaign);
......@@ -73,4 +72,21 @@ class WireReceived extends EmailCampaign
$this->mailer->queue($this->build());
}
}
private function getAmountString($wire)
{
$amount = $wire->getAmount();
if ($wire->getMethod() === 'tokens') {
$amount = BigNumber::fromPlain($wire->getAmount(), 18)->toDouble();
$currency = $amount === 1 ? 'token' : 'tokens';
} else {
$currency = strtoupper($wire->getMethod());
}
if ($wire->getMethod() === 'usd') {
$amount = $amount / 100;
}
return "$amount $currency";
}
}
......@@ -41,6 +41,7 @@ class WireSent extends EmailCampaign
$timestamp = gettype($this->wire->getTimestamp()) === 'object' ? $this->wire->getTimestamp()->time() : $this->wire->getTimestamp();
$amount = $this->wire->getMethod() === 'tokens' ? BigNumber::fromPlain($this->wire->getAmount(), 18)->toDouble() : $this->wire->getAmount();
$contract = $this->wire->getMethod() === 'onchain' ? 'wire' : 'offchain:wire';
$this->template->setTemplate('default.tpl');
......@@ -50,7 +51,7 @@ class WireSent extends EmailCampaign
$this->template->set('email', $this->user->getEmail());
$this->template->set('guid', $this->user->getGUID());
$this->template->set('timestamp', $timestamp);
$this->template->set('amount', $amount);
$this->template->set('amount', $this->getAmountString($this->wire));
$this->template->set('receiver', $this->wire->getReceiver());
$this->template->set('sender', $this->wire->getSender());
$this->template->set('contract', $contract);
......@@ -74,4 +75,24 @@ class WireSent extends EmailCampaign
$this->mailer->queue($this->build());
}
}
<<<<<<< HEAD
=======
private function getAmountString($wire)
{
$amount = $wire->getAmount();
if ($wire->getMethod() === 'tokens') {
$amount = BigNumber::fromPlain($wire->getAmount(), 18)->toDouble();
$currency = $amount === 1 ? 'token' : 'tokens';
} else {
$currency = strtoupper($wire->getMethod());
}
if ($wire->getMethod() === 'usd') {
$amount = $amount / 100;
}
return "$amount $currency";
}
>>>>>>> d85a52e... (feat): wire emails support multiple currencies
}
......@@ -101,7 +101,7 @@ class WireNotification implements Interfaces\QueueRunner
$amount = $wire->getAmount();
if ($wire->getMethod() === 'tokens') {
$amount = BigNumber::fromPlain($wire->getAmount(), 18)->toDouble();
$currency = $amount > 1 ? 'tokens' : 'token';
$currency = $amount === 1 ? 'token' : 'tokens';
} else {
$currency = strtoupper($wire->getMethod());
}
......
......@@ -37,6 +37,7 @@ class User extends \ElggUser
$this->attributes['pinned_posts'] = [];
$this->attributes['eth_wallet'] = '';
$this->attributes['eth_incentive'] = '';
$this->attributes['btc_address'] = '';
$this->attributes['phone_number'] = null;
$this->attributes['phone_number_hash'] = null;
$this->attributes['icontime'] = time();
......@@ -990,7 +991,8 @@ class User extends \ElggUser
'canary',
'theme',
'onchain_booster',
'toaster_notifications'
'toaster_notifications',
'btc_address',
));
}
......@@ -1095,4 +1097,24 @@ class User extends \ElggUser
{
$this->toaster_notifications = $enabled ? 1 : 0;
}
/**
* Returns btc_address
* @return string
*/
public function getBtcAddress()
{
return (string) $this->btc_address;
}
/**
* Set btc_address
* @param string $btc_address
*/
public function setBtcAddress($btc_address)
{
$this->btc_address = (string) $btc_address;
return $this;
}
}
......@@ -67,6 +67,8 @@ class WireReceivedSpec extends ObjectBehavior
public function it_should_send_a_wire_received_email_tokens()
{
$this->wire->setMethod('tokens');
$this->wire->setAmount(2000000000000000);
$this->getCampaign()->shouldEqual('when');
$this->getTopic()->shouldEqual('wire_received');
$this->setUser($this->receiver);
......@@ -79,7 +81,39 @@ class WireReceivedSpec extends ObjectBehavior
$data['guid']->shouldEqual($this->receiverGUID);
$data['email']->shouldEqual($this->receiverEmail);
$data['username']->shouldEqual($this->receiverUsername);
$data['amount']->shouldEqual(BigNumber::fromPlain(10, 18)->toDouble());
$data['amount']->shouldEqual('0.002 tokens');
$this->mailer->queue(Argument::any())->shouldBeCalled();
$testEmailSubscription = (new EmailSubscription())
->setUserGuid($this->receiverGUID)
->setCampaign('when')
->setTopic('wire_received')
->setValue(true);
$this->manager->isSubscribed($testEmailSubscription)->shouldBeCalled()->willReturn(true);
$this->send();
}
public function it_should_send_a_wire_received_email_eth()
{
$this->wire->setMethod('eth');
$this->wire->setAmount(7);
$this->getCampaign()->shouldEqual('when');
$this->getTopic()->shouldEqual('wire_received');
$this->setUser($this->receiver);
$this->setWire($this->wire);
$this->setSuggestions($this->mockSuggestions());
$message = $this->build();
$message->getSubject()->shouldEqual('You received a wire');
$to = $message->getTo()[0]['name']->shouldEqual($this->receiverName);
$to = $message->getTo()[0]['email']->shouldEqual($this->receiverEmail);
$data = $this->getTemplate()->getData();
$data['guid']->shouldEqual($this->receiverGUID);
$data['email']->shouldEqual($this->receiverEmail);
$data['username']->shouldEqual($this->receiverUsername);
$data['amount']->shouldEqual('7 ETH');
$this->mailer->queue(Argument::any())->shouldBeCalled();
$testEmailSubscription = (new EmailSubscription())
......@@ -92,9 +126,10 @@ class WireReceivedSpec extends ObjectBehavior
$this->send();
}
public function it_should_send_a_wire_received_email_onchain()
public function it_should_send_a_wire_received_email_usd()
{
$this->wire->setMethod('onchain');
$this->wire->setMethod('usd');
$this->wire->setAmount(500);
$this->getCampaign()->shouldEqual('when');
$this->getTopic()->shouldEqual('wire_received');
$this->setUser($this->receiver);
......@@ -108,8 +143,8 @@ class WireReceivedSpec extends ObjectBehavior
$data['guid']->shouldEqual($this->receiverGUID);
$data['email']->shouldEqual($this->receiverEmail);
$data['username']->shouldEqual($this->receiverUsername);
$data['contract']->shouldEqual('wire');
$data['amount']->shouldEqual(10);
$data['amount']->shouldEqual('5 USD');
$this->mailer->queue(Argument::any())->shouldBeCalled();
$testEmailSubscription = (new EmailSubscription())
......@@ -122,6 +157,36 @@ class WireReceivedSpec extends ObjectBehavior
$this->send();
}
// public function it_should_send_a_wire_received_email_onchain()
// {
// $this->wire->setMethod('onchain');
// $this->getCampaign()->shouldEqual('when');
// $this->getTopic()->shouldEqual('wire_received');
// $this->setUser($this->receiver);
// $this->setWire($this->wire);
// $this->setSuggestions($this->mockSuggestions());
// $message = $this->build();
// $message->getSubject()->shouldEqual('You received a wire');
// $to = $message->getTo()[0]['name']->shouldEqual($this->receiverName);
// $to = $message->getTo()[0]['email']->shouldEqual($this->receiverEmail);
// $data = $this->getTemplate()->getData();
// $data['guid']->shouldEqual($this->receiverGUID);
// $data['email']->shouldEqual($this->receiverEmail);
// $data['username']->shouldEqual($this->receiverUsername);
// $data['contract']->shouldEqual('wire');
// $data['amount']->shouldEqual('2000000000000000 ONCHAIN');
// $this->mailer->queue(Argument::any())->shouldBeCalled();
// $testEmailSubscription = (new EmailSubscription())
// ->setUserGuid($this->receiverGUID)
// ->setCampaign('when')
// ->setTopic('wire_received')
// ->setValue(true);
// $this->manager->isSubscribed($testEmailSubscription)->shouldBeCalled()->willReturn(true);
// $this->send();
// }
public function it_should_not_send_unsubscribed()
{
$this->getCampaign()->shouldEqual('when');
......