Skip to content

Commit

Permalink
improve unwrap dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
hmisty committed Jan 9, 2024
1 parent 6447b86 commit 388db7a
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 26 deletions.
44 changes: 40 additions & 4 deletions scripts/controllers/addressInfoController.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,27 @@ angular.module('ethExplorer')
$('#dialog-unwrap-wjoule').modal('show');
}

$scope.wjUnwrapToConfirm = function () {
const amt = $('#wj-unwrap-amount')[0].value;
const to = $('#wj-unwrap-to')[0].value;
const save_info = $('#wj-unwrap-save-info')[0].checked;
console.log('wjUnwrapTo', amt, to, save_info);

$('#confirm-unwrap-wj-from').text($scope.addressId);
$('#confirm-unwrap-wj-amount').text(amt ? amt : '0');
$('#confirm-unwrap-wj-amount2').text(amt ? amt : '0');
$('#confirm-unwrap-wj-to').text(to ? to : $scope.addressId);

$('#dialog-unwrap-wjoule-confirm').modal({keyboard:false, backdrop:'static'});
$('#dialog-unwrap-wjoule-confirm').modal('show');
}

$scope.wjUnwrapTo = function () {
const DIALOG_TITLE = 'Unwrap wJ';
const amt = $('#wj-unwrap-amount')[0].value;
const to = $('#wj-unwrap-to')[0].value;
console.log('wjUnwrapTo', amt, to);
const save_info = $('#wj-unwrap-save-info')[0].checked;
console.log('wjUnwrapTo', amt, to, save_info);

if (amt && !isNaN(amt)) { // isNaN works, nice.
if (!(amt > 0)) {
Expand All @@ -148,6 +164,11 @@ angular.module('ethExplorer')
wj_contract.methods.withdraw(e)
.send({from: connectedAccount}, handlerShowTx(DIALOG_TITLE))
.then(handlerShowRct(DIALOG_TITLE));

if (!save_info) {
$('#wj-unwrap-amount')[0].value = '';
$('#wj-unwrap-to')[0].value = '';
}
} else {
dialogShowTxt(DIALOG_TITLE, '错误:无法评估gas:' + err.message); //展示合约逻辑报错
}
Expand All @@ -158,6 +179,11 @@ angular.module('ethExplorer')
wj_contract.methods.withdrawTo(to, e)
.send({from: connectedAccount}, handlerShowTx(DIALOG_TITLE))
.then(handlerShowRct(DIALOG_TITLE));

if (!save_info) {
$('#wj-unwrap-amount')[0].value = '';
$('#wj-unwrap-to')[0].value = '';
}
} else {
dialogShowTxt(DIALOG_TITLE, '错误:无法评估gas:' + err.message); //展示合约逻辑报错
}
Expand Down Expand Up @@ -234,9 +260,11 @@ angular.module('ethExplorer')
console.log('loading golden_idx.json ...');
});

getJNSDAOV();
getAllJNS();
getAllJNSVote();
// JNS -> JNSDAOV, JNSVote, etc.
getAllJNS().then(() => {
getJNSDAOV();
getAllJNSVote();
});
}

function getAddressInfos(){
Expand Down Expand Up @@ -512,6 +540,8 @@ angular.module('ethExplorer')
}

function getAllJNS() {
var deferred = $q.defer();

$scope.allJNS = [];
var addr = $scope.addressId;
var contract = new web3.eth.Contract(jns_ABI, jns_contract_address);
Expand Down Expand Up @@ -542,6 +572,9 @@ angular.module('ethExplorer')
}
});
}

if (balance > 0)
deferred.resolve();
}
});

Expand All @@ -553,6 +586,9 @@ angular.module('ethExplorer')
console.log('[addressInfo] chainId: ', $scope.chainId, 'account: ', $scope.account, 'jnsContractOwner: ', $scope.jnsContractOwner);
$scope.$apply();
});


return deferred.promise;
}

function getAllJNSVote() {
Expand Down
80 changes: 58 additions & 22 deletions views/addressInfo.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ <h1>
<tbody>
<tr>
<td><b>能量余额:</b></td>
<td>{{balanceInEther || "计算中..."}} J (焦耳),即 {{balance || "计算中..."}} e (能量单位)</td>
<td>{{balanceInEther || "-"}} J (焦耳),即 {{balance || "-"}} e (能量单位)</td>
</tr>
<tr>
<td><b>数字资产:</b></td>
<td></td>
</tr>
<tr>
<td>Wrapped Joule</td>
<td>{{wjBalanceInJoule || "计算中..."}} wJ
<td>{{wjBalanceInJoule || "-"}} wJ
<span ng-style="{ 'display': chainId == '0xe52' && account.toLowerCase() == addressId.toLowerCase() ? 'inline-block' : 'none' }">
<span ng-style="{ 'display': wjBalance > 0 ? 'inline-block':'none'}">
<button ng-click="wjUnwrapDialog()"><font style="color:#0023ed">unwrap</font></button>
Expand All @@ -49,26 +49,23 @@ <h1>
<tr>
<td><b>藏品和徽章:</b></td>
<td>
JTI: {{countJTI || "统计中..."}}
JTI: {{countJTI || "-"}}
<span ng-style="{ 'display': chainId == '0xe52' && account.toLowerCase() == jtiContractOwner.toLowerCase() ? 'inline-block' : 'none' }">
<button ng-click="star()">⭐️</button>
</span>
,
FlyingJ: {{countFlyingJ || "统计中..."}}
,
CryptoJunks: {{countCryptoJunks || "统计中..."}}
,
JNSDAO V: {{countJNSDAOV || "统计中..."}}
<span ng-style="{ 'display': chainId == '0xe52' && account.toLowerCase() == addressId.toLowerCase() ? 'inline-block' : 'none' }">
<button ng-click="register()"><font style="color:#c647ba">npub</font></button>
</span>
,
JNS: {{countJNS || "统计中..."}}
<span ng-style="{ 'display': countFlyingJ > 0 ? 'inline-block' : 'none' }">, FlyingJ: {{countFlyingJ}}</span>
<span ng-style="{ 'display': countCryptoJunks > 0 ? 'inline-block' : 'none' }">, CryptoJunks: {{countCryptoJunks}}</span>
<span ng-style="{ 'display': countJNS > 0 ? 'inline-block' : 'none' }">, JNS: {{countJNS}}</span>
<!--span ng-style="{ 'display': chainId == '0xe52' && account == jnsContractOwner ? 'inline-block' : 'none' }">
<button ng-click="mint()">🔨</button>
</span-->
,
JNSVote POAP: {{countJNSVote || "统计中..."}}
<span ng-style="{ 'display': countJNSVote > 0 ? 'inline-block' : 'none' }">, JNSVote POAP: {{countJNSVote}}</span>
<span ng-style="{ 'display': countJNSDAOV > 0 ? 'inline-block' : 'none' }">
, JNSDAO V: {{countJNSDAOV || "统计中..."}}
<span ng-style="{ 'display': chainId == '0xe52' && account.toLowerCase() == addressId.toLowerCase() ? 'inline-block' : 'none' }">
<button ng-click="register()"><font style="color:#c647ba">npub</font></button>
</span>
</span>
</td>
</tr>
<tr data-ng-repeat="i5 in allJNSDAOV">
Expand Down Expand Up @@ -134,20 +131,59 @@ <h4 class="modal-title"><span id="">Unwrap wJ</span></h4>
</div></center>
<div class="modal-body">
<code>
<span style="word-break:break-all;" id="">
<p>拆开wJ (wrapped Joule),释放其中的能量到某一地址。需输入:</p>
<p>1. 要拆开的wJ数量:<input type="text" id="wj-unwrap-amount"></input> wJ</p>
<p>2. 接收能量的链地址(留空则默认为当前地址):<input type="text" id="wj-unwrap-to"></input></p>
</span>
<div style="word-break:break-all;" id="">
<div>
<div>释放wJ (wrapped Joule)中的能量(1 wJ = 1 J)到某一地址作为gas使用。</div>
<div>需输入:</div>
<div>1. 要释放的Joule量:<input type="text" id="wj-unwrap-amount"></input> J</div>
</div>
<div style="margin-top:5px;">
<div>2. 接收能量的链地址(留空则默认为当前地址):</div>
<div><input style="width:100%" type="text" id="wj-unwrap-to"></input></div>
</div>
<div style="float:right;margin-top:10px;">
<input type="checkbox" checked id="wj-unwrap-save-info"><font color="black">点击确定后不清空输入框</font></input>
</div>
</div>
</code>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal" ng-click="wjUnwrapTo()">确定</button>
<button type="button" class="btn btn-primary" data-dismiss="modal" ng-click="wjUnwrapToConfirm()">确定</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
</div>
</div>
</div>
</div>
<!-- end of dialog for input to unwrap wJoule -->

<!-- dialog for double checking & confirming to unwrap wJoule -->
<div id="dialog-unwrap-wjoule-confirm" class="modal fade" role="dialog">
<div class="modal-dialog">

<!-- Modal content-->
<div class="modal-content">
<center><div class="modal-header">
<h4 class="modal-title"><span id="">Unwrap wJ, 再次确认</span></h4>
</div></center>
<div class="modal-body">
<code>
<div style="word-break:break-all;" id="">
将从地址:<span id="confirm-unwrap-wj-from"></span>
减少:<span id="confirm-unwrap-wj-amount"></span> wJ
并将其中的能量:<span id="confirm-unwrap-wj-amount2"></span> J
释放到地址:<span id="confirm-unwrap-wj-to"></span>
作为gas使用。
</div>
<div style="float:right;">确认吗?</div>
</code>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal" ng-click="wjUnwrapTo()">确定</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
</div>
</div>
</div>
</div>
<!-- end of dialog for double checking & confirming to unwrap wJoule -->

</div>

0 comments on commit 388db7a

Please sign in to comment.