|
@@ -2,6 +2,7 @@ import { BagId } from '@joystream/types/storage'
|
|
|
import { registry } from '@joystream/types'
|
|
|
import { createType } from '@polkadot/types'
|
|
|
import { InterfaceTypes } from '@polkadot/types/types'
|
|
|
+import { WorkingGroup } from '@joystream/types/common'
|
|
|
|
|
|
export class BagIdParserService {
|
|
|
private createType<T extends keyof InterfaceTypes>(type: T, value: any) {
|
|
@@ -27,6 +28,7 @@ export class BagIdParserService {
|
|
|
}
|
|
|
|
|
|
public parseStaticBagId(bagId: string, bagIdParts: string[]): BagId {
|
|
|
+ // Try to construct static council bag ID.
|
|
|
if (bagIdParts[1] === 'council') {
|
|
|
if (bagIdParts.length === 2) {
|
|
|
const staticBagId = this.createType('StaticBagId', 'Council')
|
|
@@ -38,6 +40,20 @@ export class BagIdParserService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // Try to construct static working group bag ID.
|
|
|
+ if (bagIdParts[1] === 'wg' && bagIdParts.length === 3) {
|
|
|
+ const groups = Object.keys(WorkingGroup.typeDefinitions)
|
|
|
+ const inputGroup = bagIdParts[2]
|
|
|
+
|
|
|
+ if (groups.find((g) => g.toLocaleLowerCase() === inputGroup)) {
|
|
|
+ return this.createType('BagId', {
|
|
|
+ Static: {
|
|
|
+ WorkingGroup: inputGroup,
|
|
|
+ },
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
throw new Error(`Invalid bagId: ${bagId}`)
|
|
|
}
|
|
|
|