@@ -227,6 +227,7 @@ import {
227
227
MetadataType ,
228
228
MetadataValue ,
229
229
MetadataValueDetails ,
230
+ MODULE_NAMES ,
230
231
ModuleName ,
231
232
MultiClaimCondition ,
232
233
NftMetadataInput ,
@@ -274,6 +275,7 @@ import {
274
275
TransferRestrictionType ,
275
276
TransferStatus ,
276
277
TrustedClaimIssuer ,
278
+ TX_TAG_VALUES ,
277
279
TxGroup ,
278
280
TxTag ,
279
281
TxTags ,
@@ -1163,16 +1165,26 @@ const formatTxTag = (dispatchable: string, moduleName: string): TxTag => {
1163
1165
return `${ moduleName } .${ camelCase ( dispatchable ) } ` as TxTag ;
1164
1166
} ;
1165
1167
1166
- const processDispatchName = ( dispatch : BTreeSet < Text > ) : string [ ] => {
1167
- return [ ...dispatch ] . map ( name => textToString ( name ) ) . filter ( name => isSnakeCase ( name ) ) ;
1168
+ const processDispatchName = (
1169
+ dispatch : BTreeSet < Text >
1170
+ ) : {
1171
+ dispatchables : string [ ] ;
1172
+ unmatchedTags : string [ ] ;
1173
+ } => {
1174
+ const allMethods = [ ...dispatch ] . map ( name => textToString ( name ) ) ;
1175
+
1176
+ return {
1177
+ dispatchables : allMethods . filter ( name => isSnakeCase ( name ) ) ,
1178
+ unmatchedTags : allMethods . filter ( name => ! isSnakeCase ( name ) ) ,
1179
+ } ;
1168
1180
} ;
1169
1181
1170
1182
/**
1171
1183
* @hidden
1172
1184
*/
1173
1185
export function extrinsicPermissionsToTransactionPermissions (
1174
1186
permissions : PolymeshPrimitivesSecondaryKeyExtrinsicPermissions
1175
- ) : TransactionPermissions | null {
1187
+ ) : { permissions : TransactionPermissions | null ; unmatched : string [ ] } {
1176
1188
let extrinsicType : PermissionType ;
1177
1189
let pallets ;
1178
1190
if ( permissions . isThese ) {
@@ -1185,23 +1197,36 @@ export function extrinsicPermissionsToTransactionPermissions(
1185
1197
1186
1198
let txValues : ( ModuleName | TxTag ) [ ] = [ ] ;
1187
1199
let exceptions : TxTag [ ] = [ ] ;
1200
+ const unmatched : string [ ] = [ ] ;
1188
1201
1189
1202
if ( pallets ) {
1190
1203
// Note if a pallet or extrinsic has incorrect casing it will get filtered here
1191
1204
pallets . forEach ( ( { extrinsics : dispatchableNames } , palletName ) => {
1192
1205
const pallet = textToString ( palletName ) ;
1206
+
1193
1207
if ( ! startsWithCapital ( pallet ) ) {
1208
+ unmatched . push ( pallet ) ;
1209
+
1194
1210
return ; // skip incorrect cased pallets
1195
1211
}
1196
1212
const moduleName = stringLowerFirst ( pallet ) ;
1197
1213
1198
1214
if ( dispatchableNames . isExcept ) {
1199
- const dispatchables = processDispatchName ( dispatchableNames . asExcept ) ;
1215
+ const { dispatchables, unmatchedTags } = processDispatchName ( dispatchableNames . asExcept ) ;
1216
+
1217
+ if ( unmatchedTags . length ) {
1218
+ unmatched . push ( `${ pallet } .${ unmatchedTags . join ( '.' ) } ` ) ;
1219
+ }
1200
1220
1201
1221
exceptions = [ ...exceptions , ...dispatchables . map ( name => formatTxTag ( name , moduleName ) ) ] ;
1202
1222
txValues = [ ...txValues , moduleName as ModuleName ] ;
1203
1223
} else if ( dispatchableNames . isThese ) {
1204
- const dispatchables = processDispatchName ( dispatchableNames . asThese ) ;
1224
+ const { dispatchables, unmatchedTags } = processDispatchName ( dispatchableNames . asThese ) ;
1225
+
1226
+ if ( unmatchedTags . length ) {
1227
+ unmatched . push ( `${ pallet } .${ unmatchedTags . join ( '.' ) } ` ) ;
1228
+ }
1229
+
1205
1230
txValues = [ ...txValues , ...dispatchables . map ( name => formatTxTag ( name , moduleName ) ) ] ;
1206
1231
} else {
1207
1232
txValues = [ ...txValues , moduleName as ModuleName ] ;
@@ -1214,10 +1239,10 @@ export function extrinsicPermissionsToTransactionPermissions(
1214
1239
values : txValues ,
1215
1240
} ;
1216
1241
1217
- return exceptions . length ? { ...result , exceptions } : result ;
1242
+ return { permissions : exceptions . length ? { ...result , exceptions } : result , unmatched } ;
1218
1243
}
1219
1244
1220
- return null ;
1245
+ return { permissions : null , unmatched } ;
1221
1246
}
1222
1247
1223
1248
/**
@@ -1253,7 +1278,8 @@ export function meshPermissionsToPermissions(
1253
1278
} ;
1254
1279
}
1255
1280
1256
- transactions = extrinsicPermissionsToTransactionPermissions ( extrinsic ) ;
1281
+ const { permissions : transactionPerms } = extrinsicPermissionsToTransactionPermissions ( extrinsic ) ;
1282
+ transactions = transactionPerms ;
1257
1283
1258
1284
let portfoliosType : PermissionType ;
1259
1285
let portfolioIds ;
@@ -1289,14 +1315,15 @@ export function meshPermissionsToPermissions(
1289
1315
export async function meshPermissionsToPermissionsV2 (
1290
1316
account : Account | MultiSig ,
1291
1317
context : Context
1292
- ) : Promise < Permissions > {
1318
+ ) : Promise < { permissions : Permissions ; unmatchedPermissions : string [ ] } > {
1293
1319
const {
1294
1320
polymeshApi : {
1295
1321
query : {
1296
1322
identity : { keyAssetPermissions, keyExtrinsicPermissions, keyPortfolioPermissions } ,
1297
1323
} ,
1298
1324
} ,
1299
1325
} = context ;
1326
+ const unmatchedPermissions : string [ ] = [ ] ;
1300
1327
1301
1328
const rawAccountId = stringToAccountId ( account . address , context ) ;
1302
1329
@@ -1338,7 +1365,15 @@ export async function meshPermissionsToPermissionsV2(
1338
1365
}
1339
1366
1340
1367
if ( extrinsic . isSome ) {
1341
- transactions = extrinsicPermissionsToTransactionPermissions ( extrinsic . unwrap ( ) ) ;
1368
+ const { permissions, unmatched } = extrinsicPermissionsToTransactionPermissions (
1369
+ extrinsic . unwrap ( )
1370
+ ) ;
1371
+
1372
+ transactions = permissions ;
1373
+
1374
+ if ( unmatched . length ) {
1375
+ unmatchedPermissions . push ( ...unmatched ) ;
1376
+ }
1342
1377
}
1343
1378
1344
1379
let portfoliosType : PermissionType ;
@@ -1364,12 +1399,37 @@ export async function meshPermissionsToPermissionsV2(
1364
1399
} ;
1365
1400
}
1366
1401
1367
- return {
1402
+ // get transaction permissions values and check for undefined tx tags
1403
+ transactions ?. values . forEach ( value => {
1404
+ if ( value . includes ( '.' ) && ! TX_TAG_VALUES . includes ( value ) ) {
1405
+ unmatchedPermissions . push ( value ) ;
1406
+ }
1407
+
1408
+ if ( ! value . includes ( '.' ) && ! MODULE_NAMES . includes ( value ) ) {
1409
+ unmatchedPermissions . push ( value ) ;
1410
+ }
1411
+ } ) ;
1412
+
1413
+ if ( transactions ?. exceptions ) {
1414
+ transactions . exceptions . forEach ( value => {
1415
+ if ( ! TX_TAG_VALUES . includes ( value ) ) {
1416
+ unmatchedPermissions . push ( value ) ;
1417
+ }
1418
+ } ) ;
1419
+ }
1420
+
1421
+ // Current permission conversion logic
1422
+ const permissions = {
1368
1423
assets,
1369
1424
transactions,
1370
1425
transactionGroups : transactions ? transactionPermissionsToTxGroups ( transactions ) : [ ] ,
1371
1426
portfolios,
1372
1427
} ;
1428
+
1429
+ return {
1430
+ permissions,
1431
+ unmatchedPermissions,
1432
+ } ;
1373
1433
}
1374
1434
1375
1435
/**
@@ -5541,6 +5601,7 @@ export function secondaryAccountWithAuthToSecondaryKeyWithAuth(
5541
5601
{
5542
5602
account : asAccount ( account , context ) ,
5543
5603
permissions : permissionsLikeToPermissions ( permissions , context ) ,
5604
+ unmatchedPermissions : [ ] ,
5544
5605
} ,
5545
5606
context
5546
5607
) ,
0 commit comments