Skip to content

Commit

Permalink
SpaceDapp: set description when creating or updating channel (#114)
Browse files Browse the repository at this point in the history
Signed-off-by: Evan Salzbrenner <[email protected]>
  • Loading branch information
salzbrenner authored Jun 10, 2024
1 parent 9ab3185 commit 6f29cc9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/sdk/src/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ export async function createChannel(

const channelId = makeUniqueChannelStreamId(spaceId)
try {
txn = await spaceDapp.createChannel(spaceId, channelName, channelId, roleIds, signer)
txn = await spaceDapp.createChannel(spaceId, channelName, '', channelId, roleIds, signer)
} catch (err) {
error = spaceDapp.parseSpaceError(spaceId, err)
return { channelId: undefined, error }
Expand Down
1 change: 1 addition & 0 deletions packages/stress/src/utils/stressClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export class StressClient {
const tx = await this.spaceDapp.createChannel(
spaceId,
channelName,
'',
channelId,
roles.filter((role) => role.name !== 'Owner').map((role) => role.roleId),
this.connection.baseProvider.wallet,
Expand Down
1 change: 1 addition & 0 deletions packages/web3/src/ISpaceDapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export interface ISpaceDapp {
createChannel: (
spaceId: string,
channelName: string,
channelDescription: string,
channelNetworkId: string,
roleIds: number[],
signer: SignerType,
Expand Down
10 changes: 10 additions & 0 deletions packages/web3/src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ export const findDynamicPricingModule = (pricingModules: PricingModuleStruct[])
export const findFixedPricingModule = (pricingModules: PricingModuleStruct[]) =>
pricingModules.find((module) => module.name === FIXED_PRICING)

export function stringifyChannelMetadataJSON({
name,
description,
}: {
name: string
description: string
}): string {
return JSON.stringify({ name, description })
}

export function parseChannelMetadataJSON(metadataStr: string): {
name: string
description: string
Expand Down
18 changes: 15 additions & 3 deletions packages/web3/src/v3/SpaceDapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { IRuleEntitlement, UNKNOWN_ERROR, UserEntitlementShim } from './index'
import { PricingModules } from './PricingModules'
import { IPrepayShim } from './IPrepayShim'
import { dlogger, isJest } from '@river-build/dlog'
import { EVERYONE_ADDRESS } from '../Utils'
import { EVERYONE_ADDRESS, stringifyChannelMetadataJSON } from '../Utils'
import { evaluateOperationsForEntitledWallet, ruleDataToOperations } from '../entitlement'
import { RuleEntitlementShim } from './RuleEntitlementShim'

Expand Down Expand Up @@ -149,6 +149,7 @@ export class SpaceDapp implements ISpaceDapp {
public async createChannel(
spaceId: string,
channelName: string,
channelDescription: string,
channelNetworkId: string,
roleIds: number[],
signer: ethers.Signer,
Expand All @@ -162,7 +163,15 @@ export class SpaceDapp implements ISpaceDapp {
? channelNetworkId
: `0x${channelNetworkId}`
return wrapTransaction(
() => space.Channels.write(signer).createChannel(channelId, channelName, roleIds),
() =>
space.Channels.write(signer).createChannel(
channelId,
stringifyChannelMetadataJSON({
name: channelName,
description: channelDescription,
}),
roleIds,
),
txnOpts,
)
}
Expand Down Expand Up @@ -532,7 +541,10 @@ export class SpaceDapp implements ISpaceDapp {
encodedCallData.push(
space.Channels.interface.encodeFunctionData('updateChannel', [
params.channelId.startsWith('0x') ? params.channelId : `0x${params.channelId}`,
params.channelName,
stringifyChannelMetadataJSON({
name: params.channelName,
description: params.channelDescription,
}),
params.disabled ?? false, // default to false
]),
)
Expand Down

0 comments on commit 6f29cc9

Please sign in to comment.