commit
8afabfc7e8
3 changed files with 55 additions and 12 deletions
|
@ -191,9 +191,14 @@ class LBRY_Admin
|
||||||
$new_channel = $_POST['new_channel'];
|
$new_channel = $_POST['new_channel'];
|
||||||
$bid_amount = $_POST['bid_amount'];
|
$bid_amount = $_POST['bid_amount'];
|
||||||
|
|
||||||
// TODO: Wrap in a try catch
|
// Try to add the new channel
|
||||||
LBRY()->daemon->channel_new($new_channel, $bid_amount);
|
try {
|
||||||
LBRY()->notice->set_notice('success', 'Successfully added a new channel!', true);
|
$result = LBRY()->daemon->channel_new($new_channel, $bid_amount);
|
||||||
|
// Tell the user it takes some time to go through
|
||||||
|
LBRY()->notice->set_notice('success', 'Successfully added a new channel! Please wait a few minutes for the bid to process.', true);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
LBRY()->notice->set_notice('error', $e->getMessage(), false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_safe_redirect($redirect_url);
|
wp_safe_redirect($redirect_url);
|
||||||
|
|
|
@ -24,7 +24,7 @@ class LBRY_Daemon
|
||||||
public function wallet_unused_address()
|
public function wallet_unused_address()
|
||||||
{
|
{
|
||||||
$result = $this->request('wallet_unused_address');
|
$result = $this->request('wallet_unused_address');
|
||||||
return json_decode($result)->result;
|
return $result->result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,17 +36,17 @@ class LBRY_Daemon
|
||||||
public function wallet_balance()
|
public function wallet_balance()
|
||||||
{
|
{
|
||||||
$result = $this->request('wallet_balance');
|
$result = $this->request('wallet_balance');
|
||||||
return json_decode($result)->result;
|
return $result->result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* https://lbryio.github.io/lbry/#channel_list
|
* https://lbryio.github.io/lbry/#channel_list
|
||||||
* @return array claim dictionary
|
* @return array claim dictionary or null if empty
|
||||||
*/
|
*/
|
||||||
public function channel_list()
|
public function channel_list()
|
||||||
{
|
{
|
||||||
$result = $this->request('channel_list');
|
$result = $this->request('channel_list')->result;
|
||||||
return null;
|
return empty($result) ? null : $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,7 +55,29 @@ class LBRY_Daemon
|
||||||
*/
|
*/
|
||||||
public function channel_new($channel_name, $bid_amount)
|
public function channel_new($channel_name, $bid_amount)
|
||||||
{
|
{
|
||||||
return null;
|
// TODO: Sanitize channel name and bid
|
||||||
|
|
||||||
|
// Make sure no @ sign, as we will add that
|
||||||
|
if (strpos($channel_name, '@')) {
|
||||||
|
throw new \Exception('Illegal character "@" in channel name', 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// No white space allowed
|
||||||
|
if (strpos($channel_name, ' ')) {
|
||||||
|
throw new \Exception("No spaces allowed in channel name", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$channel_name = '@' . $channel_name;
|
||||||
|
|
||||||
|
$result = $this->request(
|
||||||
|
'channel_new',
|
||||||
|
array(
|
||||||
|
'channel_name' => $channel_name,
|
||||||
|
'amount' => floatval($bid_amount)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->check_for_errors($result);
|
||||||
|
return $result->result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -86,7 +108,18 @@ class LBRY_Daemon
|
||||||
|
|
||||||
$result = curl_exec($ch);
|
$result = curl_exec($ch);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
return $result;
|
return json_decode($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks for erros in decoded daemon response and throws an exception if it finds one
|
||||||
|
* @param $response
|
||||||
|
*/
|
||||||
|
private function check_for_errors($response)
|
||||||
|
{
|
||||||
|
if (property_exists($response, 'error')) {
|
||||||
|
throw new \Exception($response->error->message, $response->error->code);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -20,7 +20,11 @@ $channel_list = $LBRY->daemon->channel_list();
|
||||||
|
|
||||||
<h2>Your Publishable Channels</h2>
|
<h2>Your Publishable Channels</h2>
|
||||||
<?php if ($channel_list): ?>
|
<?php if ($channel_list): ?>
|
||||||
|
<ul class="lbry-channel-list">
|
||||||
|
<?php foreach ($channel_list as $channel): ?>
|
||||||
|
<li><?= $channel->name ?></li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<p>Looks like you haven't added any channels yet, feel free to do so below:</p>
|
<p>Looks like you haven't added any channels yet, feel free to do so below:</p>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
@ -34,7 +38,8 @@ $channel_list = $LBRY->daemon->channel_list();
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">New Channel Name</th>
|
<th scope="row">New Channel Name</th>
|
||||||
<td>
|
<td>
|
||||||
<input type="text" name="new_channel" value="" placeholder="Your New Channel" required>
|
<span>@</span>
|
||||||
|
<input type="text" name="new_channel" value="" placeholder="your-new-channel" required>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
Loading…
Reference in a new issue