Skip to content

Commit

Permalink
frontend and backend changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ianrowan committed Feb 9, 2024
1 parent fedae9e commit 0de106b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export const namespaceFactoryAbi = [
name: 'name',
type: 'string',
},
{
internalType: 'string',
name: '_uri',
type: 'string',
},
{
internalType: 'address',
name: '_feeManager',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ class NamespaceFactory extends ContractBase {

let txReceipt;
try {
const uri = `commonwealth.im/api/namespaceMetadata/${name}/{id}`;
txReceipt = await this.contract.methods
.deployNamespace(name, feeManager, [])
.deployNamespace(name, uri, feeManager, [])
.send({ from: walletAddress });
} catch (error) {
throw new Error('Transaction failed: ' + error);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { AppError } from '@hicommonwealth/core';
import { DB } from '@hicommonwealth/model';
import { TypedRequestParams } from 'server/types';

export const getNamespaceMetadata = async (
models: DB,
req: TypedRequestParams<{ namespace: string; stake_id: string }>,
res: any,
) => {
//stake_id will be a 32 byte hex string, convert to number
const decodedId = parseInt(req.params.stake_id, 16);
const metadata = await models.Community.findOne({
where: {
namespace: req.params.namespace,
},
include: [
{
model: models.CommunityStake,
required: true,
attributes: ['stake_id'],
where: {
stake_id: decodedId,
},
},
],
attributes: ['namespace', 'icon_url'],
});

if (!metadata) {
throw new AppError('Token metadata does not exist');
}

return res.json({
name: `${metadata.namespace} Community Stake`,
image: metadata.icon_url,
});
};
8 changes: 8 additions & 0 deletions packages/commonwealth/server/routing/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ import { ServerTopicsController } from '../controllers/server_topics_controller'
import { GENERATE_IMAGE_RATE_LIMIT } from 'server/config';
import { rateLimiterMiddleware } from 'server/middleware/rateLimiter';
import { getTopUsersHandler } from 'server/routes/admin/get_top_users_handler';
import { getNamespaceMetadata } from 'server/routes/communities/get_namespace_metadata';
import { getStatsHandler } from '../routes/admin/get_stats_handler';
import { createCommentReactionHandler } from '../routes/comments/create_comment_reaction_handler';
import { deleteBotCommentHandler } from '../routes/comments/delete_comment_bot_handler';
Expand Down Expand Up @@ -381,6 +382,13 @@ function setupRouter(
getCommunityStakeHandler.bind(this, models, serverControllers),
);

registerRoute(
router,
'get',
'/namespaceMetadata/:namespace/:stake_id',
getNamespaceMetadata.bind(this, models),
);

registerRoute(
router,
'post',
Expand Down

0 comments on commit 0de106b

Please sign in to comment.