Skip to content

Commit

Permalink
add laminar margin pages WIP & fix issue #68 #70
Browse files Browse the repository at this point in the history
  • Loading branch information
RomeroYang committed Jul 28, 2020
1 parent 8c79fa1 commit 397e858
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 177 deletions.
38 changes: 38 additions & 0 deletions lib/js_service_laminar/src/service/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,43 @@ async function txFeeEstimate(txInfo, paramList) {
return dispatchInfo;
}

function _extractEvents(api, result) {
if (!result || !result.events) {
return;
}

result.events
.filter((event) => !!event.event)
.map(({ event: { data, method, section } }) => {
if (section === "system" && method === "ExtrinsicFailed") {
const [dispatchError] = data;
let message = dispatchError.type;

if (dispatchError.isModule) {
try {
const mod = dispatchError.asModule;
const error = api.registry.findMetaError(
new Uint8Array([mod.index.toNumber(), mod.error.toNumber()])
);

message = `${error.section}.${error.name}`;
} catch (error) {
// swallow error
}
}
window.send("txUpdateEvent", {
title: `${section}.${method}`,
message,
});
} else {
window.send("txUpdateEvent", {
title: `${section}.${method}`,
message: "ok",
});
}
});
}

function sendTx(txInfo, paramList) {
return new Promise((resolve) => {
const keyPair = keyring.getPair(hexToU8a(txInfo.pubKey));
Expand All @@ -246,6 +283,7 @@ function sendTx(txInfo, paramList) {
const tx = api.tx[txInfo.module][txInfo.call](...paramList);
const onStatusChange = (result) => {
if (result.status.isInBlock || result.status.isFinalized) {
_extractEvents(api, result);
// resolve({ hash: result.status.asInBlock.toHex() });
resolve({
hash: tx.hash.hash.toHuman(),
Expand Down
14 changes: 14 additions & 0 deletions lib/js_service_laminar/src/service/laminar.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,23 @@ async function subscribeSyntheticPools() {
return {};
}

const msgChannelMarginPools = "LaminarMarginPools";
async function subscribeMarginPools() {
laminarApi.margin.allPoolIds().subscribe((ids) => {
ids.forEach((id) => {
laminarApi.margin.poolInfo(id).subscribe((res) => {
// res.options.forEach((e) => (e.poolId = res.poolId));
send(msgChannelMarginPools, res);
});
});
});
return {};
}

export default {
subscribeMessage,
getTokens,
subscribePrices,
subscribeSyntheticPools,
subscribeMarginPools,
};
2 changes: 1 addition & 1 deletion lib/page-acala/homa/redeemPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class _HomaRedeemPageState extends State<HomaRedeemPage> {
era = pool.freeList[_eraSelected].era;
}
var args = {
"title": I18n.of(context).acala['homa.mint'],
"title": I18n.of(context).acala['homa.redeem'],
"txInfo": {
"module": 'homa',
"call": 'redeem',
Expand Down
80 changes: 30 additions & 50 deletions lib/page-acala/loan/loanCard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,60 +32,40 @@ class LoanCard extends StatelessWidget {
padding: EdgeInsets.fromLTRB(16, 24, 16, 16),
child: Column(
children: <Widget>[
Stack(
alignment: AlignmentDirectional.topEnd,
Column(
children: <Widget>[
Column(
children: <Widget>[
Text(dic['loan.borrowed'] + ' aUSD'),
Padding(
padding: EdgeInsets.only(top: 8, bottom: 0),
child: Text(
Fmt.priceCeilBigInt(loan.debits,
decimals: acala_token_decimals),
style: TextStyle(
fontSize: 36,
color: Theme.of(context).primaryColor,
),
),
),
Padding(
padding: EdgeInsets.only(bottom: 16),
child: Text(
'${I18n.of(context).assets['balance']}: $balance',
style: TextStyle(fontSize: 14),
),
),
Row(
children: <Widget>[
InfoItem(
crossAxisAlignment: CrossAxisAlignment.center,
title: dic['collateral.interest'],
content: Fmt.ratio(dailyInterest, needSymbol: false),
),
InfoItem(
crossAxisAlignment: CrossAxisAlignment.center,
title: dic['collateral.ratio.year'],
content: ratio,
)
],
Text(dic['loan.borrowed'] + ' aUSD'),
Padding(
padding: EdgeInsets.only(top: 8, bottom: 0),
child: Text(
Fmt.priceCeilBigInt(loan.debits,
decimals: acala_token_decimals),
style: TextStyle(
fontSize: 36,
color: Theme.of(context).primaryColor,
),
],
),
),
GestureDetector(
child: Container(
child: Column(
children: <Widget>[
Icon(Icons.history, color: primaryColor),
Text(
dic['loan.txs'],
style: TextStyle(color: primaryColor, fontSize: 14),
)
],
),
Padding(
padding: EdgeInsets.only(bottom: 16),
child: Text(
'${I18n.of(context).assets['balance']}: $balance',
style: TextStyle(fontSize: 14),
),
onTap: () => Navigator.of(context)
.pushNamed(LoanHistoryPage.route, arguments: loan.type),
),
Row(
children: <Widget>[
InfoItem(
crossAxisAlignment: CrossAxisAlignment.center,
title: dic['collateral.interest'],
content: Fmt.ratio(dailyInterest, needSymbol: false),
),
InfoItem(
crossAxisAlignment: CrossAxisAlignment.center,
title: dic['collateral.ratio.year'],
content: ratio,
)
],
),
],
),
Expand Down
Loading

0 comments on commit 397e858

Please sign in to comment.