@subwallet/extension-base 1.3.37-0 → 1.3.38-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/background/KoniTypes.d.ts +2 -0
- package/cjs/core/logic-validation/request.js +49 -12
- package/cjs/koni/background/handlers/State.js +4 -8
- package/cjs/koni/background/handlers/Tabs.js +38 -5
- package/cjs/packageInfo.js +1 -1
- package/cjs/page/cardano/cips/cip30.js +21 -1
- package/cjs/page/cardano/index.js +5 -5
- package/cjs/services/request-service/handler/CardanoRequestHandler.js +4 -3
- package/cjs/services/request-service/helper/index.js +19 -17
- package/cjs/services/swap-service/handler/base-handler.js +4 -2
- package/cjs/services/swap-service/handler/uniswap-handler.js +122 -57
- package/cjs/services/swap-service/index.js +1 -1
- package/core/logic-validation/request.d.ts +1 -0
- package/core/logic-validation/request.js +50 -14
- package/koni/background/handlers/State.js +5 -9
- package/koni/background/handlers/Tabs.d.ts +1 -0
- package/koni/background/handlers/Tabs.js +38 -5
- package/package.json +8 -8
- package/packageInfo.js +1 -1
- package/page/cardano/cips/cip30.d.ts +31 -17
- package/page/cardano/cips/cip30.js +17 -1
- package/page/cardano/index.d.ts +20 -4
- package/page/cardano/index.js +5 -5
- package/services/request-service/handler/CardanoRequestHandler.js +4 -3
- package/services/request-service/helper/index.js +19 -17
- package/services/swap-service/handler/base-handler.js +4 -2
- package/services/swap-service/handler/uniswap-handler.d.ts +1 -1
- package/services/swap-service/handler/uniswap-handler.js +99 -34
- package/services/swap-service/index.js +1 -1
- package/types/service-base.d.ts +1 -0
|
@@ -900,6 +900,7 @@ export interface TonSignatureRequest extends TonSignRequest {
|
|
|
900
900
|
export interface CardanoSignatureRequest extends CardanoSignRequest {
|
|
901
901
|
id: string;
|
|
902
902
|
errors?: ErrorValidation[];
|
|
903
|
+
currentAddress: string;
|
|
903
904
|
payload: unknown;
|
|
904
905
|
}
|
|
905
906
|
export interface EvmSendTransactionRequest extends TransactionConfig, EvmSignRequest {
|
|
@@ -1841,6 +1842,7 @@ export interface KoniRequestSignatures {
|
|
|
1841
1842
|
'cardano(account.get.address)': [null, string[]];
|
|
1842
1843
|
'cardano(account.get.balance)': [null, Cbor];
|
|
1843
1844
|
'cardano(account.get.change.address)': [null, string];
|
|
1845
|
+
'cardano(account.get.reward.address)': [null, string[]];
|
|
1844
1846
|
'cardano(account.get.utxos)': [RequestCardanoGetUtxos, Cbor[] | null];
|
|
1845
1847
|
'cardano(account.get.collateral)': [RequestCardanoGetCollateral, Cbor[] | null];
|
|
1846
1848
|
'cardano(network.get.current)': [null, number];
|
|
@@ -11,6 +11,7 @@ exports.joiValidate = void 0;
|
|
|
11
11
|
exports.validateSignMessageData = validateSignMessageData;
|
|
12
12
|
exports.validateTypedSignMessageDataV1 = validateTypedSignMessageDataV1;
|
|
13
13
|
exports.validateTypedSignMessageDataV3V4 = validateTypedSignMessageDataV3V4;
|
|
14
|
+
exports.validationAuthCardanoMiddleware = validationAuthCardanoMiddleware;
|
|
14
15
|
exports.validationAuthMiddleware = validationAuthMiddleware;
|
|
15
16
|
exports.validationAuthWCMiddleware = validationAuthWCMiddleware;
|
|
16
17
|
exports.validationCardanoSignDataMiddleware = validationCardanoSignDataMiddleware;
|
|
@@ -148,36 +149,33 @@ async function generateValidationProcess(koni, url, payloadValidate, validationM
|
|
|
148
149
|
}
|
|
149
150
|
return resultValidated;
|
|
150
151
|
}
|
|
152
|
+
function handleAuthError(payload, message, errorPosition, errors) {
|
|
153
|
+
payload.errorPosition = errorPosition;
|
|
154
|
+
errors.push(new Error(convertErrorMessage(message)[0]));
|
|
155
|
+
return payload;
|
|
156
|
+
}
|
|
151
157
|
async function validationAuthMiddleware(koni, url, payload) {
|
|
152
158
|
const {
|
|
153
159
|
address,
|
|
154
160
|
errors
|
|
155
161
|
} = payload;
|
|
156
162
|
if (!address || !(0, _util.isString)(address)) {
|
|
157
|
-
payload
|
|
158
|
-
const [message] = convertErrorMessage('Not found address to sign');
|
|
159
|
-
errors.push(new Error(message));
|
|
163
|
+
return handleAuthError(payload, 'Not found address to sign', 'dApp', errors);
|
|
160
164
|
} else {
|
|
161
165
|
try {
|
|
162
166
|
payload.pair = _uiKeyring.keyring.getPair(address);
|
|
163
167
|
if (!payload.pair) {
|
|
164
|
-
payload
|
|
165
|
-
const [message] = convertErrorMessage('Unable to find account');
|
|
166
|
-
errors.push(new Error(message));
|
|
168
|
+
return handleAuthError(payload, 'Unable to find account', 'dApp', errors);
|
|
167
169
|
} else {
|
|
168
170
|
const authList = await koni.getAuthList();
|
|
169
171
|
const authInfo = authList[(0, _utils.stripUrl)(url)];
|
|
170
172
|
if (!authInfo || !authInfo.isAllowed || !authInfo.isAllowedMap[payload.pair.address]) {
|
|
171
|
-
payload
|
|
172
|
-
const [message] = convertErrorMessage('Account not in allowed list', '');
|
|
173
|
-
errors.push(new Error(message));
|
|
173
|
+
return handleAuthError(payload, 'Account not in allowed list', 'dApp', errors);
|
|
174
174
|
}
|
|
175
175
|
payload.authInfo = authInfo;
|
|
176
176
|
}
|
|
177
177
|
} catch (e) {
|
|
178
|
-
|
|
179
|
-
payload.errorPosition = 'dApp';
|
|
180
|
-
errors.push(new Error(message));
|
|
178
|
+
return handleAuthError(payload, e.message, 'dApp', errors);
|
|
181
179
|
}
|
|
182
180
|
}
|
|
183
181
|
return payload;
|
|
@@ -565,6 +563,44 @@ function validationAuthWCMiddleware(koni, url, payload, topic) {
|
|
|
565
563
|
});
|
|
566
564
|
return promise;
|
|
567
565
|
}
|
|
566
|
+
async function validationAuthCardanoMiddleware(koni, url, payload) {
|
|
567
|
+
const authList = await koni.getAuthList();
|
|
568
|
+
const authInfo = authList[(0, _utils.stripUrl)(url)];
|
|
569
|
+
const {
|
|
570
|
+
address,
|
|
571
|
+
errors
|
|
572
|
+
} = payload;
|
|
573
|
+
if (!authInfo || !authInfo.isAllowed) {
|
|
574
|
+
return handleAuthError(payload, 'Account not in allowed list', 'dApp', errors);
|
|
575
|
+
}
|
|
576
|
+
const currentAddress = authInfo.currentAccount;
|
|
577
|
+
const currentNetwork = authInfo.currentNetworkMap.cardano || 'cardano';
|
|
578
|
+
const currentNetworkId = +(currentNetwork === 'cardano');
|
|
579
|
+
if (!currentAddress || !authInfo.isAllowedMap[currentAddress]) {
|
|
580
|
+
return handleAuthError(payload, 'Unable to find account', 'dApp', errors);
|
|
581
|
+
}
|
|
582
|
+
const pair = _uiKeyring.keyring.getPair(currentAddress);
|
|
583
|
+
if (!pair) {
|
|
584
|
+
return handleAuthError(payload, 'Unable to find account', 'dApp', errors);
|
|
585
|
+
}
|
|
586
|
+
payload.pair = pair;
|
|
587
|
+
if ((0, _keyring.isCardanoBaseAddress)(address)) {
|
|
588
|
+
if (!authInfo.isAllowedMap[address]) {
|
|
589
|
+
return handleAuthError(payload, 'Account not in allowed list', 'dApp', errors);
|
|
590
|
+
}
|
|
591
|
+
const addressByChainFormat = (0, _utils.reformatAddress)(currentAddress, currentNetworkId);
|
|
592
|
+
if (!(0, _utils.isSameAddress)(addressByChainFormat, address)) {
|
|
593
|
+
return handleAuthError(payload, 'Current account is changed', 'dApp', errors);
|
|
594
|
+
}
|
|
595
|
+
} else if ((0, _keyring.isCardanoRewardAddress)(address)) {
|
|
596
|
+
const rewardAddress = pair.cardano.rewardAddress;
|
|
597
|
+
const addressByChainFormat = (0, _utils.reformatAddress)(rewardAddress, currentNetworkId);
|
|
598
|
+
if (!(0, _utils.isSameAddress)(addressByChainFormat, address)) {
|
|
599
|
+
return handleAuthError(payload, 'Current account is changed', 'dApp', errors);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
return payload;
|
|
603
|
+
}
|
|
568
604
|
async function validationCardanoSignDataMiddleware(koni, url, payload_) {
|
|
569
605
|
const {
|
|
570
606
|
address,
|
|
@@ -609,6 +645,7 @@ async function validationCardanoSignDataMiddleware(koni, url, payload_) {
|
|
|
609
645
|
const payloadAfterValidated = {
|
|
610
646
|
address,
|
|
611
647
|
payload: payload,
|
|
648
|
+
currentAddress: authInfo === null || authInfo === void 0 ? void 0 : authInfo.currentAccount,
|
|
612
649
|
hashPayload: payload,
|
|
613
650
|
canSign: canSign,
|
|
614
651
|
id: ''
|
|
@@ -1068,14 +1068,12 @@ class KoniState {
|
|
|
1068
1068
|
errors: [],
|
|
1069
1069
|
networkKey: ''
|
|
1070
1070
|
};
|
|
1071
|
-
const validationSteps = [_logicValidation.
|
|
1071
|
+
const validationSteps = [_logicValidation.validationAuthCardanoMiddleware, _logicValidation.validationCardanoSignDataMiddleware];
|
|
1072
1072
|
const result = await (0, _logicValidation.generateValidationProcess)(this, url, payloadValidation, validationSteps);
|
|
1073
|
-
if (!(0, _utils3.isSameAddress)(address, currentAddress)) {
|
|
1074
|
-
throw new _CardanoProviderError.CardanoProviderError(_KoniTypes.CardanoProviderErrorType.ACCOUNT_CHANGED);
|
|
1075
|
-
}
|
|
1076
1073
|
const errorsFormated = (0, _logicValidation.convertErrorFormat)(result.errors);
|
|
1077
1074
|
const payloadAfterValidated = {
|
|
1078
1075
|
...result.payloadAfterValidated,
|
|
1076
|
+
currentAddress,
|
|
1079
1077
|
errors: errorsFormated,
|
|
1080
1078
|
id
|
|
1081
1079
|
};
|
|
@@ -1184,7 +1182,6 @@ class KoniState {
|
|
|
1184
1182
|
};
|
|
1185
1183
|
}
|
|
1186
1184
|
}
|
|
1187
|
-
transactionValue = transactionValue.checked_sub(CardanoWasm.Value.new(tx.body().fee()));
|
|
1188
1185
|
const transactionBody = tx.body();
|
|
1189
1186
|
const getSpecificUtxo = this.chainService.getSpecificUtxo.bind(this);
|
|
1190
1187
|
requireKeyHashes.push(...(0, _helper.extractKeyHashFromCertificate)(transactionBody.certs()));
|
|
@@ -1197,9 +1194,8 @@ class KoniState {
|
|
|
1197
1194
|
const keyHashAddressMap = {};
|
|
1198
1195
|
const pair = _uiKeyring.keyring.getPair(currentAddress);
|
|
1199
1196
|
if (pair) {
|
|
1200
|
-
const
|
|
1201
|
-
const
|
|
1202
|
-
const stakePubKey = publicKey.derive(2).derive(0).to_raw_key().hash().to_hex();
|
|
1197
|
+
const paymentPubKey = CardanoWasm.Bip32PublicKey.from_hex(pair.cardano.paymentPubKey).to_raw_key().hash().to_hex();
|
|
1198
|
+
const stakePubKey = CardanoWasm.Bip32PublicKey.from_hex(pair.cardano.stakePubKey).to_raw_key().hash().to_hex();
|
|
1203
1199
|
keyHashAddressMap[paymentPubKey] = 'payment';
|
|
1204
1200
|
keyHashAddressMap[stakePubKey] = 'stake';
|
|
1205
1201
|
} else {
|
|
@@ -40,6 +40,7 @@ function transformAccountsV2(accounts) {
|
|
|
40
40
|
const accountSelected = authInfo ? authInfo.isAllowed ? Object.keys(authInfo.isAllowedMap).filter(address => authInfo.isAllowedMap[address]) : [] : [];
|
|
41
41
|
const authTypeFilter = _ref => {
|
|
42
42
|
let {
|
|
43
|
+
json,
|
|
43
44
|
type
|
|
44
45
|
} = _ref;
|
|
45
46
|
if (accountAuthTypes) {
|
|
@@ -52,10 +53,19 @@ function transformAccountsV2(accounts) {
|
|
|
52
53
|
ton: _types3.TonKeypairTypes,
|
|
53
54
|
cardano: _types3.CardanoKeypairTypes
|
|
54
55
|
};
|
|
55
|
-
|
|
56
|
+
const isValidTypes = accountAuthTypes.some(authType => {
|
|
56
57
|
var _validTypes$authType;
|
|
57
58
|
return (_validTypes$authType = validTypes[authType]) === null || _validTypes$authType === void 0 ? void 0 : _validTypes$authType.includes(type);
|
|
58
59
|
});
|
|
60
|
+
if (!isValidTypes) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// This condition ensures that the resulting UTXOs from the user's transaction are not sent to addresses the wallet cannot manage.
|
|
65
|
+
if (type === 'cardano' && json.meta.isReadOnly) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
return true;
|
|
59
69
|
} else {
|
|
60
70
|
return true;
|
|
61
71
|
}
|
|
@@ -1143,8 +1153,8 @@ class KoniTabs {
|
|
|
1143
1153
|
this.#koniState.setAuthorize(authList);
|
|
1144
1154
|
}
|
|
1145
1155
|
return accountList.map(address => {
|
|
1146
|
-
const
|
|
1147
|
-
const addressChainFormat = (0, _utils2.reformatAddress)(address, +
|
|
1156
|
+
const isMainnet = (authInfo === null || authInfo === void 0 ? void 0 : authInfo.currentNetworkMap.cardano) !== 'cardano_preproduction';
|
|
1157
|
+
const addressChainFormat = (0, _utils2.reformatAddress)(address, +isMainnet);
|
|
1148
1158
|
return (0, _utils2.convertCardanoAddressToHex)(addressChainFormat);
|
|
1149
1159
|
});
|
|
1150
1160
|
}
|
|
@@ -1172,10 +1182,31 @@ class KoniTabs {
|
|
|
1172
1182
|
address,
|
|
1173
1183
|
network
|
|
1174
1184
|
} = await this.getCurrentInformationCardanoDapp(url);
|
|
1175
|
-
const
|
|
1176
|
-
const addressChainFormat = (0, _utils2.reformatAddress)(address, +
|
|
1185
|
+
const isMainnet = network !== 'cardano_preproduction';
|
|
1186
|
+
const addressChainFormat = (0, _utils2.reformatAddress)(address, +isMainnet);
|
|
1177
1187
|
return (0, _utils2.convertCardanoAddressToHex)(addressChainFormat);
|
|
1178
1188
|
}
|
|
1189
|
+
async cardanoGetRewardAddress(id, url) {
|
|
1190
|
+
const authList = await this.#koniState.getAuthList();
|
|
1191
|
+
const urlStripped = (0, _utils2.stripUrl)(url);
|
|
1192
|
+
const authInfo = authList[urlStripped];
|
|
1193
|
+
if (!authInfo || !authInfo.isAllowedMap) {
|
|
1194
|
+
throw new _CardanoProviderError.CardanoProviderError(_KoniTypes.CardanoProviderErrorType.REFUSED_REQUEST, 'You need to connect to the wallet first');
|
|
1195
|
+
}
|
|
1196
|
+
const accountList = await this.getCurrentAccount(url, 'cardano');
|
|
1197
|
+
const currentCardanoAccount = authInfo.currentAccount;
|
|
1198
|
+
if (currentCardanoAccount !== accountList[0]) {
|
|
1199
|
+
authList[urlStripped].currentAccount = accountList[0];
|
|
1200
|
+
this.#koniState.setAuthorize(authList);
|
|
1201
|
+
}
|
|
1202
|
+
return accountList.map(address => {
|
|
1203
|
+
const pair = _uiKeyring.keyring.getPair(address);
|
|
1204
|
+
const rewardAddress = pair.cardano.rewardAddress;
|
|
1205
|
+
const isTestnet = (authInfo === null || authInfo === void 0 ? void 0 : authInfo.currentNetworkMap.cardano) !== 'cardano_preproduction';
|
|
1206
|
+
const addressChainFormat = (0, _utils2.reformatAddress)(rewardAddress, +isTestnet);
|
|
1207
|
+
return (0, _utils2.convertCardanoAddressToHex)(addressChainFormat);
|
|
1208
|
+
});
|
|
1209
|
+
}
|
|
1179
1210
|
async cardanoGetCurrentNetworkId(id, url) {
|
|
1180
1211
|
let currentChain;
|
|
1181
1212
|
let autoActiveChain = false;
|
|
@@ -1356,6 +1387,8 @@ class KoniTabs {
|
|
|
1356
1387
|
return await this.cardanoGetAccountBalance(id, url);
|
|
1357
1388
|
case 'cardano(account.get.change.address)':
|
|
1358
1389
|
return await this.cardanoGetChangeAddress(id, url);
|
|
1390
|
+
case 'cardano(account.get.reward.address)':
|
|
1391
|
+
return await this.cardanoGetRewardAddress(id, url);
|
|
1359
1392
|
case 'cardano(account.get.collateral)':
|
|
1360
1393
|
return await this.cardanoGetCollateral(id, url, request);
|
|
1361
1394
|
case 'cardano(account.get.utxos)':
|
package/cjs/packageInfo.js
CHANGED
|
@@ -38,7 +38,7 @@ class CIP30Api {
|
|
|
38
38
|
return new Promise(resolve => resolve([]));
|
|
39
39
|
}
|
|
40
40
|
async getRewardAddresses() {
|
|
41
|
-
return
|
|
41
|
+
return await this.sendMessage('cardano(account.get.reward.address)');
|
|
42
42
|
}
|
|
43
43
|
async signTx(tx) {
|
|
44
44
|
let partialSign = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
@@ -59,5 +59,25 @@ class CIP30Api {
|
|
|
59
59
|
async getBalance() {
|
|
60
60
|
return await this.sendMessage('cardano(account.get.balance)');
|
|
61
61
|
}
|
|
62
|
+
get apis() {
|
|
63
|
+
var _this = this;
|
|
64
|
+
return {
|
|
65
|
+
getExtension: () => this.getExtension(),
|
|
66
|
+
getNetworkId: () => this.getNetworkId(),
|
|
67
|
+
getCollateral: payload => this.getCollateral(payload),
|
|
68
|
+
getUtxos: (amount, paginate) => this.getUtxos(amount, paginate),
|
|
69
|
+
getUsedAddresses: () => this.getUsedAddresses(),
|
|
70
|
+
getChangeAddress: () => this.getChangeAddress(),
|
|
71
|
+
getUnusedAddresses: () => this.getUnusedAddresses(),
|
|
72
|
+
getRewardAddresses: () => this.getRewardAddresses(),
|
|
73
|
+
signTx: function (tx) {
|
|
74
|
+
let partialSign = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
75
|
+
return _this.signTx(tx, partialSign);
|
|
76
|
+
},
|
|
77
|
+
signData: (address, payload) => this.signData(address, payload),
|
|
78
|
+
submitTx: tx => this.submitTx(tx),
|
|
79
|
+
getBalance: () => this.getBalance()
|
|
80
|
+
};
|
|
81
|
+
}
|
|
62
82
|
}
|
|
63
83
|
exports.CIP30Api = CIP30Api;
|
|
@@ -20,7 +20,7 @@ class SubWalletCardanoProvider {
|
|
|
20
20
|
this.icon = WALLET_ICON;
|
|
21
21
|
this.sendMessage = sendMessage;
|
|
22
22
|
}
|
|
23
|
-
async
|
|
23
|
+
enable = async () => {
|
|
24
24
|
const isEnabled = await this.sendMessage('pub(authorize.tabV2)', {
|
|
25
25
|
origin,
|
|
26
26
|
accountAuthTypes: ['cardano']
|
|
@@ -29,13 +29,13 @@ class SubWalletCardanoProvider {
|
|
|
29
29
|
throw new Error('Access to the wallet is denied');
|
|
30
30
|
}
|
|
31
31
|
const CIP30 = new _cips.CIP30Api(this.sendMessage);
|
|
32
|
-
return Object.freeze(CIP30);
|
|
33
|
-
}
|
|
34
|
-
async
|
|
32
|
+
return Object.freeze(CIP30.apis);
|
|
33
|
+
};
|
|
34
|
+
isEnable = async () => {
|
|
35
35
|
const accountList = await this.sendMessage('pub(accounts.list)', {
|
|
36
36
|
accountAuthType: 'cardano'
|
|
37
37
|
});
|
|
38
38
|
return accountList.length > 0;
|
|
39
|
-
}
|
|
39
|
+
};
|
|
40
40
|
}
|
|
41
41
|
exports.default = SubWalletCardanoProvider;
|
|
@@ -140,14 +140,15 @@ class CardanoRequestHandler {
|
|
|
140
140
|
}
|
|
141
141
|
signMessage(confirmation) {
|
|
142
142
|
const {
|
|
143
|
-
address,
|
|
143
|
+
address: addressToSign,
|
|
144
|
+
currentAddress,
|
|
144
145
|
payload
|
|
145
146
|
} = confirmation.payload;
|
|
146
|
-
const pair = _uiKeyring.keyring.getPair(
|
|
147
|
+
const pair = _uiKeyring.keyring.getPair(currentAddress);
|
|
147
148
|
if (pair.isLocked) {
|
|
148
149
|
_uiKeyring.keyring.unlockPair(pair.address);
|
|
149
150
|
}
|
|
150
|
-
return pair.cardano.signMessage(payload,
|
|
151
|
+
return pair.cardano.signMessage(payload, addressToSign);
|
|
151
152
|
}
|
|
152
153
|
signTransactionCardano(confirmation) {
|
|
153
154
|
// alibaba
|
|
@@ -70,25 +70,27 @@ exports.extractMetadata = extractMetadata;
|
|
|
70
70
|
const convertAssetToValue = amount => {
|
|
71
71
|
const value = CardanoWasm.Value.new(CardanoWasm.BigNum.from_str('0'));
|
|
72
72
|
const multiAsset = CardanoWasm.MultiAsset.new();
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
73
|
+
if (amount !== null && amount !== void 0 && amount.length) {
|
|
74
|
+
for (const item of amount) {
|
|
75
|
+
if (item.unit === 'lovelace') {
|
|
76
|
+
value.set_coin(CardanoWasm.BigNum.from_str(item.quantity));
|
|
77
|
+
} else {
|
|
78
|
+
const policyIdHex = item.unit.slice(0, 56);
|
|
79
|
+
const assetNameHex = item.unit.slice(56);
|
|
80
|
+
const scriptHash = CardanoWasm.ScriptHash.from_bytes(Buffer.from(policyIdHex, 'hex'));
|
|
81
|
+
const assetName = CardanoWasm.AssetName.new(Buffer.from(assetNameHex, 'hex'));
|
|
82
|
+
const quantity = CardanoWasm.BigNum.from_str(item.quantity);
|
|
83
|
+
let assets = multiAsset.get(scriptHash);
|
|
84
|
+
if (!assets) {
|
|
85
|
+
assets = CardanoWasm.Assets.new();
|
|
86
|
+
}
|
|
87
|
+
assets.insert(assetName, quantity);
|
|
88
|
+
multiAsset.insert(scriptHash, assets);
|
|
85
89
|
}
|
|
86
|
-
assets.insert(assetName, quantity);
|
|
87
|
-
multiAsset.insert(scriptHash, assets);
|
|
88
90
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
if (multiAsset.len() > 0) {
|
|
92
|
+
value.set_multiasset(multiAsset);
|
|
93
|
+
}
|
|
92
94
|
}
|
|
93
95
|
return value;
|
|
94
96
|
};
|
|
@@ -173,6 +173,8 @@ class SwapBaseHandler {
|
|
|
173
173
|
if (needEditAmount) {
|
|
174
174
|
bnSendingValue = (0, _bignumber.default)(selectedQuote.toAmount).multipliedBy(_utils3.DEFAULT_EXCESS_AMOUNT_WEIGHT); // need to round
|
|
175
175
|
} else {
|
|
176
|
+
// todo: remove
|
|
177
|
+
console.log('The code cannot run into here, if it runs into here, pls ask dev to check');
|
|
176
178
|
bnSendingValue = (0, _bignumber.default)(selectedQuote.toAmount);
|
|
177
179
|
}
|
|
178
180
|
}
|
|
@@ -373,8 +375,8 @@ class SwapBaseHandler {
|
|
|
373
375
|
if (recipient) {
|
|
374
376
|
const isEvmAddress = (0, _utilCrypto.isEthereumAddress)(recipient);
|
|
375
377
|
const isEvmDestChain = (0, _utils2._isChainEvmCompatible)(swapToChain);
|
|
376
|
-
if (isEvmAddress
|
|
377
|
-
// todo: update
|
|
378
|
+
if (isEvmAddress !== isEvmDestChain) {
|
|
379
|
+
// todo: update condition if support swap chain # EVM or Substrate
|
|
378
380
|
return [new _TransactionError.TransactionError(_swap.SwapErrorType.INVALID_RECIPIENT)];
|
|
379
381
|
}
|
|
380
382
|
}
|