Skip to content

Commit

Permalink
Merge pull request #8 from massalabs/fundation_needs
Browse files Browse the repository at this point in the history
Add transfer ownership
  • Loading branch information
AurelienFT authored Jun 7, 2024
2 parents 54273b8 + a491e8e commit b7231a9
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 10 deletions.
4 changes: 2 additions & 2 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ const faqData: FAQData[] = [
{
question: 'How do I register a name ?',
answer:
'To register a name, you need to connect your Massa wallet and enter the name you want to register in the claim section. If the name is available, you can claim it by paying the registration fee.',
'To register a name, you need to connect your Massa wallet and enter the name you want to register in the register section. If the name is available, you can register it by paying the registration fee.',
},
{
question: 'How much does it cost to register a name ?',
answer:
'The cost depends on the size of the name. 10000 coins for 2 characters, 1000 coins for 3 characters, 100 coins for 4 characters, 10 coins for 5 characters and 1 coin for 6 and more characters. An little additional amount is taken to cover storage fees. You can see the exact price while typing a domain in the claim section.',
'The cost depends on the size of the name. 10000 coins for 2 characters, 1000 coins for 3 characters, 100 coins for 4 characters, 10 coins for 5 characters and 1 coin for 6 and more characters. An little additional amount is taken to cover storage fees. You can see the exact price while typing a domain in the register section.',
},
{
question: 'How do I transfer a name ?',
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/MNSClaim.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function MNSClaim(props: MNSClaimProps) {
disabled={allocCost.price !== null ? false : true}
onClick={() => claim()}
>
Claim
Register
</Button>
</div>
</div>
Expand Down
75 changes: 72 additions & 3 deletions frontend/src/components/MNSList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
ArrowsRightLeftIcon,
ChevronDoubleRightIcon,
PencilIcon,
TrashIcon,
Expand All @@ -17,23 +18,37 @@ import { useState } from 'react';
import {
DnsChangeTargetParams,
DnsDeleteParams,
DnsTransferParams,
DnsUserEntryListResult,
} from '../utils/write-mns-sc';
import { useAccountStore } from '../lib/connectMassaWallets/store';

interface MNSListProps {
list: DnsUserEntryListResult[];
listSpinning: boolean;
deleteDnsEntry: (params: DnsDeleteParams) => void;
changeTargetAddressDnsEntry: (params: DnsChangeTargetParams) => void;
changeOwnershipDnsEntry: (params: DnsTransferParams) => void;
}

export function MNSList(props: MNSListProps) {
const { list, listSpinning, deleteDnsEntry, changeTargetAddressDnsEntry } =
props;

const {
list,
listSpinning,
deleteDnsEntry,
changeTargetAddressDnsEntry,
changeOwnershipDnsEntry,
} = props;
const { connectedAccount } = useAccountStore();
const [changeTargetModalId, setChangeTargetModalId] = useState<string | null>(
null,
);

const [changeOwnershipModalId, setChangeOwnershipModalId] = useState<{
domain: string;
tokenId: bigint;
} | null>(null);
const [newOwnerAddress, setNewOwnerAddress] = useState<string>('');
const [newTargetAddress, setNewTargetAddress] = useState<string>('');

return (
Expand Down Expand Up @@ -81,6 +96,45 @@ export function MNSList(props: MNSListProps) {
</PopupModal>
</div>
)}
{changeOwnershipModalId && (
<div className="fixed inset-0 flex items-center justify-center">
<PopupModal onClose={() => setChangeOwnershipModalId(null)}>
<PopupModalHeader customClassHeader="mb-8">
<h2 className="mas-h2">
Transfer ownership of {changeOwnershipModalId.domain}
.massa
</h2>
</PopupModalHeader>
<PopupModalContent>
<p className="mas-body pb-2">New owner Address</p>
<Input
customClass="w-96 border-none mb-8"
placeholder="Enter a new owner address"
onChange={(e) => {
setNewOwnerAddress(e.target.value);
}}
/>
<div className="flex flex-row-reverse pb-12">
<div className="w-32">
<Button
onClick={() => {
if (!connectedAccount) return;
changeOwnershipDnsEntry({
currentOwner: connectedAccount.address(),
newOwner: newOwnerAddress,
tokenId: changeOwnershipModalId.tokenId,
});
setChangeOwnershipModalId(null);
}}
>
<div>Save</div>
</Button>
</div>
</div>
</PopupModalContent>
</PopupModal>
</div>
)}
<div>
{list.map((item, idx) => (
<div key={idx} className="bg-secondary rounded-xl p-4 mb-4">
Expand All @@ -106,6 +160,21 @@ export function MNSList(props: MNSListProps) {
<PencilIcon className="w-4 pt-1" />
</Tooltip>
</button>
<button
className="flex"
onClick={() => {
setChangeOwnershipModalId({
domain: item.domain,
tokenId: item.tokenId,
});
}}
>
<Tooltip
body={<p className="mas-body">Change ownership</p>}
>
<ArrowsRightLeftIcon className="w-4 pt-1" />
</Tooltip>
</button>
<button
className="flex"
onClick={() => {
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/components/MNSManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function MNSManagement(props: MNSManagementProps) {
getAllocCost,
changeTargetAddressDnsEntry,
deleteDnsEntry,
changeOwnershipDnsEntry,
} = useWriteMNS(massaClient);

const connected = !!connectedAccount && !!currentProvider;
Expand All @@ -41,6 +42,7 @@ export function MNSManagement(props: MNSManagementProps) {
<MNSList
deleteDnsEntry={deleteDnsEntry}
changeTargetAddressDnsEntry={changeTargetAddressDnsEntry}
changeOwnershipDnsEntry={changeOwnershipDnsEntry}
list={list}
listSpinning={listSpinning}
/>
Expand Down
34 changes: 30 additions & 4 deletions frontend/src/utils/write-mns-sc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ export interface DnsChangeTargetParams {
targetAddress: string;
}

export interface DnsTransferParams {
currentOwner: string;
newOwner: string;
tokenId: bigint;
}

export interface DnsUserEntryListResult {
domain: string;
targetAddress: string;
Expand Down Expand Up @@ -115,7 +121,7 @@ export function useWriteMNS(client?: Client) {
}
return {
price: null,
error: `Domain already claimed by ${bytesToStr(result.returnValue)}`,
error: `Domain already registered by ${bytesToStr(result.returnValue)}`,
};
} catch (error) {
try {
Expand Down Expand Up @@ -298,9 +304,9 @@ export function useWriteMNS(client?: Client) {
'dnsAlloc',
args.serialize(),
{
pending: 'Entry claiming in progress',
success: 'Successfully claimed',
error: 'Failed to claim',
pending: 'Entry registering in progress',
success: 'Successfully registered',
error: 'Failed to register',
},
{ coins: params.coins, showInProgressToast: true },
);
Expand Down Expand Up @@ -430,6 +436,25 @@ export function useWriteMNS(client?: Client) {
);
}

function changeOwnershipDnsEntry(params: DnsTransferParams) {
let args = new Args();
console.log(params.tokenId);
console.log(params.currentOwner);
args.addString(params.currentOwner);
args.addString(params.newOwner);
args.addU256(params.tokenId);
callSmartContract(
'transferFrom',
args.serialize(),
{
pending: 'Updating ownership in progress',
success: 'Successfully updated',
error: 'Failed to update',
},
{ showInProgressToast: true },
);
}

return {
opId,
isPending,
Expand All @@ -442,5 +467,6 @@ export function useWriteMNS(client?: Client) {
getUserEntryList,
deleteDnsEntry,
changeTargetAddressDnsEntry,
changeOwnershipDnsEntry,
};
}

0 comments on commit b7231a9

Please sign in to comment.