Skip to content

Commit

Permalink
Merge pull request #17 from AcalaNetwork/develop
Browse files Browse the repository at this point in the history
release 0.4.7
  • Loading branch information
RomeroYang authored Jun 6, 2022
2 parents 812d08e + 9108e3c commit 06994d6
Show file tree
Hide file tree
Showing 22 changed files with 624 additions and 351 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [0.4.7] - 20220606
- bump polkawallet_sdk v0.4.7.
- xcm transfer est. fee fix.
- ui update.
- moonbeam/parallel xcm transfer support.

## [0.4.6] - 20220526
- bump polkawallet_sdk v0.4.6.
- new module browser.
Expand Down
2 changes: 1 addition & 1 deletion lib/api/loan/acalaApiLoan.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AcalaApiLoan {
return res;
}

Future<List<LoanType>> queryLoanTypes() async {
Future<List<LoanType>?> queryLoanTypes() async {
final res = await service.queryLoanTypes();
return res
.map((e) =>
Expand Down
2 changes: 1 addition & 1 deletion lib/js_service_acala/dist/main.js

Large diffs are not rendered by default.

36 changes: 22 additions & 14 deletions lib/js_service_acala/src/service/keyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,29 +177,18 @@ function _extractEvents(api: ApiPromise, result: SubmittableResult) {
}

let success = false;
let error: DispatchError["type"] = "";
let error: string;
result.events
.filter((event) => !!event.event)
.map(({ event: { data, method, section } }) => {
if (section === "system" && method === "ExtrinsicFailed") {
const [dispatchError] = (data as unknown) as ITuple<[DispatchError]>;
let message = dispatchError.type;
error = _getDispatchError(dispatchError);

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

message = `${err.section}.${err.name}`;
} catch (error) {
// swallow error
}
}
(<any>window).send("txUpdateEvent", {
title: `${section}.${method}`,
message,
message: error,
});
error = message;
} else {
(<any>window).send("txUpdateEvent", {
title: `${section}.${method}`,
Expand All @@ -213,6 +202,25 @@ function _extractEvents(api: ApiPromise, result: SubmittableResult) {
return { success, error };
}

export function _getDispatchError(dispatchError: DispatchError): string {
let message: string = dispatchError.type;

if (dispatchError.isModule) {
try {
const mod = dispatchError.asModule;
const error = dispatchError.registry.findMetaError(mod);

message = `${error.section}.${error.name}`;
} catch (error) {
// swallow
}
} else if (dispatchError.isToken) {
message = `${dispatchError.type}.${dispatchError.asToken.type}`;
}

return message;
}

/**
* sign and send extrinsic to network and wait for result.
*/
Expand Down
30 changes: 28 additions & 2 deletions lib/js_service_acala/src/service/xcm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const chain_name_acala = "acala";
const chain_name_polkadot = "polkadot";
const chain_name_statemint = "statemint";
const chain_name_parallel = "parallel";
const chain_name_moon = "moonbeam";

const relay_chain_token = "DOT";

Expand All @@ -23,6 +24,12 @@ const chainNodes = {
"wss://statemint-rpc.dwellir.com",
],
[chain_name_parallel]: ["wss://parallel.api.onfinality.io/public-ws", "wss://rpc.parallel.fi", "wss://parallel-rpc.dwellir.com"],
[chain_name_moon]: [
"wss://wss.api.moonbeam.network",
"wss://moonbeam.public.blastapi.io",
"wss://moonbeam-rpc.dwellir.com",
"wss://moonbeam.api.onfinality.io/public-ws",
],
};
const xcm_dest_weight_v2 = "5000000000";

Expand Down Expand Up @@ -146,6 +153,25 @@ async function getTransferParams(
if (chainTo.name === chain_name_polkadot) {
// to relay-chain
dst = { parents: 1, interior: { X1: { AccountId32: { id: u8aToHex(decodeAddress(addressTo)), network: "Any" } } } };
} else if (chainTo.name === chain_name_moon) {
// to moon beam
dst = {
parents: 1,
interior: {
X2: [{ Parachain: chainTo.paraChainId }, { AccountKey20: { key: addressTo, network: "Any" } }],
},
};
return token.name === "ACA" || token.name === "AUSD" || token.name === "fa://0"
? {
module: "xTokens",
call: "transfer",
params: [token.toChainData(), amount, { V1: dst }, xcm_dest_weight_v2],
}
: {
module: "xTokens",
call: "transferMulticurrencies",
params: [[[token.toChainData(), amount], sendFee], 1, { V1: dst }, xcm_dest_weight_v2],
};
} else {
// to other parachains
dst = {
Expand Down Expand Up @@ -212,7 +238,7 @@ async function getTransferParams(
LDOT: 110,
};

if (typeof tokenIds[token.symbol] === "undefined") return;
if (typeof tokenIds[token.name] === "undefined") return;

const dst = {
parents: 1,
Expand All @@ -222,7 +248,7 @@ async function getTransferParams(
return {
module: "xTokens",
call: "transfer",
params: [tokenIds[token.symbol], amount, { V1: dst }, xcm_dest_weight_v2],
params: [tokenIds[token.name], amount, { V1: dst }, xcm_dest_weight_v2],
};
}

Expand Down
20 changes: 8 additions & 12 deletions lib/pages/assets/transferFormXCM.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,6 @@ class _TransferFormXCMState extends State<TransferFormXCM> {
return null;
}

Future<void> _validateAccountTo(KeyPairData acc, int chainToSS58) async {
final error = await _checkAccountTo(acc, chainToSS58);
setState(() {
_accountToError = error;
});
}

Future<void> _getAccountSysInfo() async {
final info = await widget.plugin.sdk.webView?.evalJavascript(
'api.query.system.account("${widget.keyring.current.address}")');
Expand Down Expand Up @@ -348,7 +341,7 @@ class _TransferFormXCMState extends State<TransferFormXCM> {
}

Future<XcmTxConfirmParams?> _getTxParams(
Widget? chainFromIcon, String feeToken) async {
Widget? chainFromIcon, TokenBalanceData feeToken) async {
if (_accountToError == null &&
_formKey.currentState!.validate() &&
!_submitting &&
Expand Down Expand Up @@ -520,8 +513,6 @@ class _TransferFormXCMState extends State<TransferFormXCM> {
final available = Fmt.balanceInt(balanceData?.amount) -
Fmt.balanceInt(balanceData?.locked);
final nativeToken = widget.plugin.networkState.tokenSymbol![0];
final nativeTokenDecimals = widget.plugin.networkState.tokenDecimals![
widget.plugin.networkState.tokenSymbol!.indexOf(nativeToken)];
final existDeposit = token.tokenNameId == nativeToken
? Fmt.balanceInt(widget
.plugin.networkConst['balances']['existentialDeposit']
Expand Down Expand Up @@ -581,8 +572,13 @@ class _TransferFormXCMState extends State<TransferFormXCM> {
final chainToSS58 = isFromKar
? ((tokensConfig['xcmChains'] ?? {})[chainTo] ?? {})['ss58']
: widget.plugin.basic.ss58;
final feeToken = ((tokensConfig['xcmChains'] ?? {})[_chainFrom] ??
final feeTokenSymbol = ((tokensConfig['xcmChains'] ?? {})[_chainFrom] ??
{})['nativeToken'];
final feeToken = isFromKar
? AssetsUtils.getBalanceFromTokenNameId(widget.plugin, nativeToken)
: widget.plugin.store!.assets.allTokens.firstWhere((e) =>
e.symbol!.toUpperCase() ==
feeTokenSymbol.toString().toUpperCase());

final labelStyle = Theme.of(context).textTheme.headline4;
final subTitleStyle = TextStyle(fontSize: 12, height: 1);
Expand Down Expand Up @@ -877,7 +873,7 @@ class _TransferFormXCMState extends State<TransferFormXCM> {
),
),
Text(
'${Fmt.priceCeilBigInt(fee, isFromKar ? nativeTokenDecimals : token.decimals!, lengthMax: 6)} $feeToken',
'${Fmt.priceCeilBigInt(fee, feeToken.decimals!, lengthMax: 6)} $feeTokenSymbol',
style: infoValueStyle),
],
),
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/earnNew/earnDetailPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ class _UserCard extends StatelessWidget {
if (amount < 0) {
amount = 0;
}
if (amount > 0.001) {
if (amount > 0.0001) {
canClaim = true;
}
final rewardToken =
Expand Down
Loading

0 comments on commit 06994d6

Please sign in to comment.