Skip to content

Commit

Permalink
Update demo page.
Browse files Browse the repository at this point in the history
  • Loading branch information
cssmagic committed Jul 1, 2018
1 parent 439f526 commit 591d2d7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 44 deletions.
66 changes: 33 additions & 33 deletions demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,16 @@ const ERROR_CONTRACT_CONFIG = `Error: Syntax error in your input!
* 不需要严格遵守 JSON 规范`

//////////////////// core ////////////////////
$('#core--call').on('click', function () {
// check env
if (
!Nasa.ua.isMobileDevice() &&
!(Nasa.ua.isDesktopChrome() && Nasa.ua.isWalletExtensionInstalled())
) {
alert('抱歉,暂不支持您当前的浏览器环境!')
return
} else if (Nasa.ua.isWeChat()) {
alert('抱歉,微信浏览器不支持唤起手机钱包 App。\n\n请点右上角菜单,再选择 “在浏览器打开”。')
return
}

$('#core--query').on('click', function () {
const $this = $(this)
const contract = $this.siblings('input[name="contract"]').val().trim()
const fn = $this.siblings('input[name="fn"]').val().trim()
const inputArgs = $this.siblings('input[name="args"]').val().trim()
const $extra = $this.siblings('.extra')
const $inputPayId = $extra.find('input[name="payId"]')

const text = $this.text()
const DISABLED = 'disabled'
const restoreBtn = () => {$this.text(text).removeAttr(DISABLED)}
$this.text('Calling contract...')
$this.text('Querying contract...')
.attr(DISABLED, DISABLED)

// form args
Expand All @@ -51,36 +37,42 @@ $('#core--call').on('click', function () {
}
}

Nasa.call(contract, fn, args)
.then((payId) => {
Nasa.query(contract, fn, args)
.then((data) => {
restoreBtn()
$inputPayId.val(payId)
setTimeout(() => {
$extra.show()
}, 5000)
alert(JSON.stringify(data, null, 4))
})
.catch((e) => {
restoreBtn()
let msg = e.message
if (msg === Nasa.error.TX_REJECTED_BY_USER) {
msg = '您已取消交易!'
}
alert(msg)
alert(e.message)
})
})


$('#core--call').on('click', function () {
// check env
if (
!Nasa.ua.isMobileDevice() &&
!(Nasa.ua.isDesktopChrome() && Nasa.ua.isWalletExtensionInstalled())
) {
alert('抱歉,暂不支持您当前的浏览器环境!')
return
} else if (Nasa.ua.isWeChat()) {
alert('抱歉,微信浏览器不支持唤起手机钱包 App。\n\n请点右上角菜单,再选择 “在浏览器打开”。')
return
}

$('#core--query').on('click', function () {
const $this = $(this)
const contract = $this.siblings('input[name="contract"]').val().trim()
const fn = $this.siblings('input[name="fn"]').val().trim()
const inputArgs = $this.siblings('input[name="args"]').val().trim()
const $extra = $this.siblings('.extra')
const $inputPayId = $extra.find('input[name="payId"]')

const text = $this.text()
const DISABLED = 'disabled'
const restoreBtn = () => {$this.text(text).removeAttr(DISABLED)}
$this.text('Querying contract...')
$this.text('Calling contract...')
.attr(DISABLED, DISABLED)

// form args
Expand All @@ -96,17 +88,25 @@ $('#core--query').on('click', function () {
}
}

Nasa.query(contract, fn, args)
.then((data) => {
Nasa.call(contract, fn, args)
.then((payId) => {
restoreBtn()
alert(JSON.stringify(data, null, 4))
$inputPayId.val(payId)
setTimeout(() => {
$extra.show()
}, 5000)
})
.catch((e) => {
restoreBtn()
alert(e.message)
let msg = e.message
if (msg === Nasa.error.TX_REJECTED_BY_USER) {
msg = '您已取消交易!'
}
alert(msg)
})
})


$('#core--checkTx').on('click', function () {
const $this = $(this)
const $input = $this.siblings('input[type="text"]')
Expand Down
22 changes: 11 additions & 11 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ <h2>Core API</h2>
<h3><code>Nasa.query()</code></h3>
<div class="api-descr">
<div class="text">
<p>此方法用于向合约查询数据</p>
<p>用于向合约查询数据</p>
<blockquote>
<p>以下预设参数指向某个主网合约提供的接口,你可以随意修改并尝试。</p>
<p>以下预设参数指向 “超级词典” 合约提供的接口,你可以随意修改并尝试。</p>
</blockquote>
</div>
<input type="text" name="contract" placeholder="input your contract addr..." value="n1pbCznWEq8xwyVnJQLUTeHU9XxSoUNHWEt">
Expand All @@ -47,14 +47,14 @@ <h3><code>Nasa.query()</code></h3>
<h3><code>Nasa.call()</code></h3>
<div class="api-descr">
<div class="text">
<p>此方法用于向合约写入数据</p>
<p>用于向合约写入数据</p>
<blockquote>
<p>此方法的演示需要在以下环境运行:</p>
<ul>
<li>桌面版 Chrome 浏览器,并安装 <a href="https://github.com/nebulasio/WebExtensionWallet" target="_blank">星云钱包扩展</a></li>
<li>手机浏览器(iOS Safari 或 Android Chrome),并安装 <a href="https://nano.nebulas.io/" target="_blank">星云手机钱包 App</a></li>
</ul>
<p>以下预设参数指向某个主网合约提供的接口,你可以随意修改并尝试。</p>
<p>以下预设参数指向 “超级词典” 合约提供的接口,你可以随意修改并尝试。</p>
</blockquote>
</div>
<input type="text" name="contract" placeholder="input your contract addr..." value="n1pbCznWEq8xwyVnJQLUTeHU9XxSoUNHWEt">
Expand All @@ -70,7 +70,7 @@ <h3><code>Nasa.call()</code></h3>
<h3><code>Nasa.checkTx()</code></h3>
<div class="api-descr">
<div class="text">
<p>此方法用于查询交易结果</p>
<p>用于查询交易结果</p>
<blockquote>
<p>以下预设参数是一个已经完成的主网交易流水号,你可以随意修改并尝试。</p>
</blockquote>
Expand All @@ -87,7 +87,7 @@ <h2>Contract</h2>
<h3><code>Nasa.contract.set()</code></h3>
<div class="api-descr">
<div class="text">
<p>此方法用于指定你需要的合约地址</p>
<p>用于指定你需要的合约地址</p>
</div>
<textarea placeholder="input contract addr in specific format...">
{
Expand All @@ -113,7 +113,7 @@ <h3><code>Nasa.contract.set()</code></h3>
<h3><code>Nasa.contract.get()</code></h3>
<div class="api-descr">
<div class="text">
<p>此方法用于获取你事先指定的合约地址</p>
<p>用于获取你事先指定的合约地址</p>
</div>
<input type="text" placeholder="input a contract name..." value="default">
<button class="cm-btn" id="contract--get">Get</button>
Expand All @@ -127,7 +127,7 @@ <h2>Env</h2>
<h3><code>Nasa.env.set()</code></h3>
<div class="api-descr">
<div class="text">
<p>此方法用于指定当前环境</p>
<p>用于指定当前环境</p>
</div>
<select name="env">
<option value="">Select & set as current...</option>
Expand All @@ -140,7 +140,7 @@ <h3><code>Nasa.env.set()</code></h3>
<h3><code>Nasa.env.get()</code></h3>
<div class="api-descr">
<div class="text">
<p>此方法用于获取当前环境</p>
<p>用于获取当前环境</p>
</div>
<button class="cm-btn" id="env--get">Get</button>
</div>
Expand All @@ -153,7 +153,7 @@ <h2>User</h2>
<h3><code>Nasa.user.getAddr()</code></h3>
<div class="api-descr">
<div class="text">
<p>此方法用于获取当前用户的钱包地址</p>
<p>用于获取当前用户的钱包地址</p>
</div>
<button class="cm-btn" id="user--getAddr">Get</button>
</div>
Expand All @@ -166,7 +166,7 @@ <h2>UA</h2>
<h3><code>Nasa.ua.isSupported()</code></h3>
<div class="api-descr">
<div class="text">
<p>此方法用于判断当前浏览器是否支持 Nasa.js 所用到的某些特性。</p>
<p>用于判断当前浏览器是否支持 Nasa.js 所用到的某些特性。</p>
</div>
<button class="cm-btn" id="ua--isSupported">Test</button>
</div>
Expand Down

0 comments on commit 591d2d7

Please sign in to comment.