Skip to content

Commit de0ecad

Browse files
authored
Updatable member profile in UI (#45)
1 parent 25ef43b commit de0ecad

File tree

9 files changed

+649
-180
lines changed

9 files changed

+649
-180
lines changed

contracts/tansu/src/contract_membership.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,36 @@ impl MembershipTrait for Tansu {
3737
};
3838
}
3939

40+
/// Update the metadata of an existing member.
41+
///
42+
/// # Arguments
43+
/// * `env` - The environment object
44+
/// * `member_address` - The address of the member to update
45+
/// * `meta` - New metadata string associated with the member (e.g., IPFS hash)
46+
///
47+
/// # Panics
48+
/// * If the member doesn't exist
49+
fn update_member(env: Env, member_address: Address, meta: String) {
50+
Tansu::require_not_paused(env.clone());
51+
52+
member_address.require_auth();
53+
54+
let member_key_ = types::DataKey::Member(member_address.clone());
55+
match env
56+
.storage()
57+
.persistent()
58+
.get::<types::DataKey, types::Member>(&member_key_)
59+
{
60+
None => panic_with_error!(&env, &errors::ContractErrors::UnknownMember),
61+
Some(mut member) => {
62+
member.meta = meta;
63+
env.storage().persistent().set(&member_key_, &member);
64+
65+
events::MemberAdded { member_address }.publish(&env);
66+
}
67+
};
68+
}
69+
4070
/// Get member information including all project badges.
4171
///
4272
/// # Arguments

contracts/tansu/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ pub trait TansuTrait {
5555
pub trait MembershipTrait {
5656
fn add_member(env: Env, member_address: Address, meta: String);
5757

58+
fn update_member(env: Env, member_address: Address, meta: String);
59+
5860
fn get_member(env: Env, member_address: Address) -> types::Member;
5961

6062
fn set_badges(

dapp/packages/tansu/dist/index.d.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,28 @@ export interface Client {
647647
},
648648
options?: MethodOptions,
649649
) => Promise<AssembledTransaction<null>>;
650+
/**
651+
* Construct and simulate a update_member transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object.
652+
* Update the metadata of an existing member.
653+
*
654+
* # Arguments
655+
* * `env` - The environment object
656+
* * `member_address` - The address of the member to update
657+
* * `meta` - New metadata string associated with the member (e.g., IPFS hash)
658+
*
659+
* # Panics
660+
* * If the member doesn't exist
661+
*/
662+
update_member: (
663+
{
664+
member_address,
665+
meta,
666+
}: {
667+
member_address: string;
668+
meta: string;
669+
},
670+
options?: MethodOptions,
671+
) => Promise<AssembledTransaction<null>>;
650672
/**
651673
* Construct and simulate a get_member transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object.
652674
* Get member information including all project badges.

dapp/packages/tansu/dist/index.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dapp/packages/tansu/src/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,23 @@ export interface Client {
533533
options?: MethodOptions,
534534
) => Promise<AssembledTransaction<null>>;
535535

536+
/**
537+
* Construct and simulate a update_member transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object.
538+
* Update the metadata of an existing member.
539+
*
540+
* # Arguments
541+
* * `env` - The environment object
542+
* * `member_address` - The address of the member to update
543+
* * `meta` - New metadata string associated with the member (e.g., IPFS hash)
544+
*
545+
* # Panics
546+
* * If the member doesn't exist
547+
*/
548+
update_member: (
549+
{ member_address, meta }: { member_address: string; meta: string },
550+
options?: MethodOptions,
551+
) => Promise<AssembledTransaction<null>>;
552+
536553
/**
537554
* Construct and simulate a get_member transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object.
538555
* Get member information including all project badges.
@@ -1116,6 +1133,7 @@ export class Client extends ContractClient {
11161133
get_dao: this.txFromJSON<Dao>,
11171134
get_proposal: this.txFromJSON<Proposal>,
11181135
add_member: this.txFromJSON<null>,
1136+
update_member: this.txFromJSON<null>,
11191137
get_member: this.txFromJSON<Member>,
11201138
set_badges: this.txFromJSON<null>,
11211139
get_badges: this.txFromJSON<Badges>,

dapp/src/components/NavbarSearch.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useStore } from "@nanostores/react";
33
import Button from "./utils/Button";
44

55
import { connectedPublicKey } from "../utils/store";
6+
import { loadedPublicKey } from "../service/walletService";
67
import { toast } from "../utils/utils";
78

89
// Constants for URL handling
@@ -21,6 +22,13 @@ const NavbarSearch = () => {
2122
setIsClient(true);
2223
saveOriginalUrl();
2324
initializeSearchTerm();
25+
26+
// Sync nanostore from walletService if not yet populated.
27+
// Handles load-order races where initializeConnection ran before this component mounted.
28+
if (!connectedPublicKey.get()) {
29+
const pk = loadedPublicKey();
30+
if (pk) connectedPublicKey.set(pk);
31+
}
2432
}, []);
2533

2634
// Save the original URL when the component mounts

0 commit comments

Comments
 (0)