Skip to content

Commit

Permalink
update acala.js history api
Browse files Browse the repository at this point in the history
  • Loading branch information
RomeroYang committed Dec 21, 2022
1 parent 7931d83 commit 93ec276
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [0.5.1] - 20221221
- bump polkawallet_sdk v0.5.1.
- cross-chain staking api update.

## [0.4.9] - 20220808
- bump polkawallet_sdk v0.4.9.
- js api update.
Expand Down
2 changes: 1 addition & 1 deletion lib/js_service_acala/dist/main.js

Large diffs are not rendered by default.

40 changes: 23 additions & 17 deletions lib/js_service_acala/src/service/xcm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const chainNodes = {
],
};
const xcm_dest_weight_v2 = "5000000000";
const xcm_dest_weight_unlimited = "Unlimited";

const xcmApi: Record<string, ApiPromise> = {};
// let xcmApi: ApiPromise;
Expand Down Expand Up @@ -132,14 +133,7 @@ async function _getTokenBalance(chain: string, address: string, tokenNameId: str
};
}

async function getTransferTx(
chainFrom: ChainData,
chainTo: ChainData,
tokenName: string,
amount: string,
addressTo: string,
sendFee: any
) {
async function getTransferTx(chainFrom: ChainData, chainTo: ChainData, tokenName: string, amount: string, addressTo: string, sendFee: any) {
if (!wallet) {
wallet = new Wallet((<any>window).api);
await wallet.isReady;
Expand All @@ -149,6 +143,8 @@ async function getTransferTx(

// from acala
if (chainFrom.name === chain_name_acala) {
const useNewDestWeight = (<any>window).api.tx.xTokens.transfer.meta.args[3].type.toString() === "XcmV2WeightLimit";

let dst: any;
if (chainTo.name === chain_name_polkadot) {
// to relay-chain
Expand All @@ -165,12 +161,17 @@ async function getTransferTx(
? {
module: "xTokens",
call: "transfer",
params: [token.toChainData(), amount, { V1: dst }, xcm_dest_weight_v2],
params: [token.toChainData(), amount, { V1: dst }, useNewDestWeight ? xcm_dest_weight_unlimited : xcm_dest_weight_v2],
}
: {
module: "xTokens",
call: "transferMulticurrencies",
params: [[[token.toChainData(), amount], sendFee], 1, { V1: dst }, xcm_dest_weight_v2],
params: [
[[token.toChainData(), amount], sendFee],
1,
{ V1: dst },
useNewDestWeight ? xcm_dest_weight_unlimited : xcm_dest_weight_v2,
],
};
} else {
// to other parachains
Expand All @@ -186,12 +187,17 @@ async function getTransferTx(
? {
module: "xTokens",
call: "transferMulticurrencies",
params: [[[token.toChainData(), amount], sendFee], 1, { V1: dst }, xcm_dest_weight_v2],
params: [
[[token.toChainData(), amount], sendFee],
1,
{ V1: dst },
useNewDestWeight ? xcm_dest_weight_unlimited : xcm_dest_weight_v2,
],
}
: {
module: "xTokens",
call: "transfer",
params: [token.toChainData() as any, amount, { V1: dst }, xcm_dest_weight_v2],
params: [token.toChainData() as any, amount, { V1: dst }, useNewDestWeight ? xcm_dest_weight_unlimited : xcm_dest_weight_v2],
};
}

Expand Down Expand Up @@ -248,7 +254,7 @@ async function getTransferTx(
return {
module: "xTokens",
call: "transfer",
params: [tokenIds[token.name], amount, { V1: dst }, xcm_dest_weight_v2],
params: [tokenIds[token.name], amount, { V1: dst }, xcm_dest_weight_unlimited],
};
}

Expand All @@ -266,13 +272,13 @@ async function getTransferParams(
const res = await getTransferTx(chainFrom, chainTo, tokenName, amount, addressTo, sendFee);
if (!res) return null;

const {module, call, params} = res;
const tx = (chainFrom.name === 'acala' ? (<any>window).api : getApi(chainFrom.name)).tx[module][call](...params);
const { module, call, params } = res;
const tx = (chainFrom.name === "acala" ? (<any>window).api : getApi(chainFrom.name)).tx[module][call](...params);
return {
module,
call,
params: tx.args.map(e => e.toHuman()),
txHex: tx.toHex()
params: tx.args.map((e) => e.toHuman()),
txHex: tx.toHex(),
};
}

Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: polkawallet_plugin_acala
description: Acala network plugin for Polkawallet.
version: 0.4.9
version: 0.5.1
homepage:

environment:
Expand All @@ -20,8 +20,8 @@ dependencies:
get_storage: ^2.0.2
device_info: ^2.0.1
graphql_flutter: ^5.0.0-nullsafety.5
polkawallet_sdk: ^0.4.9
polkawallet_ui: ^0.4.9
polkawallet_sdk: ^0.5.1
polkawallet_ui: ^0.5.1
flutter_screenutil: ^5.0.0+2
skeleton_loader: ^2.0.0+4
rive: ^0.9.0
Expand Down

0 comments on commit 93ec276

Please sign in to comment.