Skip to content

Commit

Permalink
code improvements and assets
Browse files Browse the repository at this point in the history
  • Loading branch information
newtmex committed Aug 20, 2024
1 parent 15b076e commit 3e2f7ac
Show file tree
Hide file tree
Showing 18 changed files with 157 additions and 93 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# Smart Housing
# Smart Housing

4 changes: 2 additions & 2 deletions packages/backend/contracts/housing-project/HousingSFT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ contract HousingSFT is SFT {
})
);

return _mint(depositor, mintShare, attributes, "");
return _mint(depositor, mintShare, attributes);
}

/// @notice Retrieves the SFT attributes for a given owner and nonce.
Expand All @@ -101,7 +101,7 @@ contract HousingSFT is SFT {
"HousingSFT: No tokens found for user at nonce"
);

return abi.decode(getRawTokenAttributes(nonce), (HousingAttributes));
return abi.decode(_getRawTokenAttributes(nonce), (HousingAttributes));
}

/// @notice Returns the maximum supply of the HousingSFT tokens.
Expand Down
9 changes: 8 additions & 1 deletion packages/backend/contracts/main/HST.sol
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,18 @@ contract HousingStakingToken is SFT {
});

// Mint the HST token
uint256 nonce = _mint(caller, 1, abi.encode(attr), "");
uint256 nonce = _mint(caller, 1, abi.encode(attr));

emit MintHstToken(caller, nonce, attr);
}

function getAttribute(uint256 nonce) external view returns (HstAttributes memory) {
return abi.decode(
_getRawTokenAttributes(nonce),
(HstAttributes)
);
}

/// @notice Retrieves the balance of HST tokens for a specified user.
/// @param user Address of the user whose balance is to be retrieved.
/// @return balance Array of HSTBalance representing the user's HST holdings.
Expand Down
9 changes: 2 additions & 7 deletions packages/backend/contracts/main/SmartHousing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,7 @@ contract SmartHousing is ISmartHousing, Ownable, UserModule, ERC1155Holder {
.lastFundsDispatchEpoch < currentEpoch();
if (rewardsCanBeGenerated) return true;

HstAttributes memory hstAttr = abi.decode(
hst.getRawTokenAttributes(tokenNonce),
(HstAttributes)
);
HstAttributes memory hstAttr = hst.getAttribute(tokenNonce);
return
hstAttr.shtRewardPerShare < distributionStorage.shtRewardPerShare;
}
Expand All @@ -186,9 +183,7 @@ contract SmartHousing is ISmartHousing, Ownable, UserModule, ERC1155Holder {

distributionStorage.generateRewards(epochsAndPeriodsStorage);
(uint256 claimedSHT, HstAttributes memory hstAttr) = distributionStorage
.claimRewards(
abi.decode(hst.getRawTokenAttributes(hstNonce), (HstAttributes))
);
.claimRewards(hst.getAttribute(hstNonce));
uint256 rentRewards = 0;

// Claim rent rewards from HousingProjects
Expand Down
12 changes: 11 additions & 1 deletion packages/backend/contracts/modules/LockedSmartHousingToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,18 @@ contract LkSHT is SFT {
LkSHTAttributes.newAttributes(startTimestamp, amount)
);

super._mint(to, amount, attributes, "LockedSmartHousingToken");
super._mint(to, amount, attributes);

emit TokensMinted(to, amount);
}

function getAttribute(
uint256 nonce
) external view returns (LkSHTAttributes.Attributes memory) {
return
abi.decode(
_getRawTokenAttributes(nonce),
(LkSHTAttributes.Attributes)
);
}
}
24 changes: 10 additions & 14 deletions packages/backend/contracts/modules/SFT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,19 @@ contract SFT is ERC1155, Ownable {
function _mint(
address to,
uint256 amount,
bytes memory attributes,
bytes memory data
) internal returns (uint256) {
bytes memory attributes
) internal returns (uint256 nonce) {
_nonceCounter.increment();
uint256 nonce = _nonceCounter.current();
nonce = _nonceCounter.current();

// Store the attributes
_tokenAttributes[nonce] = attributes;

// Mint the token with the nonce as its ID
super._mint(to, nonce, amount, data);
super._mint(to, nonce, amount, "");

// Track the nonce for the address
_addressToNonces[to].add(nonce);

return nonce;
}

/// @dev Returns the name of the token.
Expand All @@ -72,9 +69,9 @@ contract SFT is ERC1155, Ownable {
/// @dev Returns raw token attributes by nonce.
/// @param nonce The nonce of the token.
/// @return Attributes in bytes.
function getRawTokenAttributes(
function _getRawTokenAttributes(
uint256 nonce
) public view returns (bytes memory) {
) internal view returns (bytes memory) {
return _tokenAttributes[nonce];
}

Expand Down Expand Up @@ -106,7 +103,7 @@ contract SFT is ERC1155, Ownable {
bytes memory attr
) external onlyOwner returns (uint256) {
_burn(user, nonce, amount);
return _mint(user, amount, attr, "");
return amount > 0 ? _mint(user, amount, attr) : 0;
}

/// @dev Returns the balance of the user with their token attributes.
Expand Down Expand Up @@ -151,11 +148,10 @@ contract SFT is ERC1155, Ownable {
super._beforeTokenTransfer(operator, from, to, ids, amounts, data);

for (uint256 i = 0; i < ids.length; i++) {
_addressToNonces[from].remove(ids[i]);
}
uint256 id = ids[i];

for (uint256 i = 0; i < ids.length; i++) {
_addressToNonces[to].add(ids[i]);
_addressToNonces[from].remove(id);
_addressToNonces[to].add(id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,7 @@ contract ProjectFunding is Ownable {
uint256 lkShtBal = lkSht.balanceOf(caller, nonce);
require(lkShtBal > 0, "ProjectFunding: Nothing to unlock");

LkSHTAttributes.Attributes memory attr = abi.decode(
lkSht.getRawTokenAttributes(nonce),
(LkSHTAttributes.Attributes)
);
LkSHTAttributes.Attributes memory attr = lkSht.getAttribute(nonce);
(
uint256 totalUnlockedAmount,
LkSHTAttributes.Attributes memory newAttr
Expand Down
6 changes: 3 additions & 3 deletions packages/ui/app/properties/BuyPropertyModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import useRawCallsInfo from "~~/hooks/useRawCallsInfo";
import { useSpendERC20 } from "~~/hooks/useSpendERC20";
import { RefIdData } from "~~/utils";

type Props = ProjectsValue["projectData"] & { purchased?: bigint; unitPrice: bigint };
export default function BuyPropertyModal({ unitPrice, data, fundingToken, sftDetails, purchased }: Props) {
type Props = ProjectsValue["projectData"] & { purchased?: bigint; unitPrice: bigint; imgSrc: string };
export default function BuyPropertyModal({ imgSrc, unitPrice, data, fundingToken, sftDetails, purchased }: Props) {
const unitsLeft = +BigNumber(sftDetails.maxSupply.toString())
.multipliedBy((data.fundingGoal - data.collectedFunds).toString())
.dividedBy(data.fundingGoal.toString())
Expand Down Expand Up @@ -88,7 +88,7 @@ export default function BuyPropertyModal({ unitPrice, data, fundingToken, sftDet
</button>
<div className="onboarding-side-by-side">
<div className="onboarding-media">
<img alt="" src="img/bigicon5.png" width="200px" />
<img alt="" src={imgSrc} width="200px" />
</div>
<div className="onboarding-content with-gradient">
<h4 className="onboarding-title">
Expand Down
1 change: 1 addition & 0 deletions packages/ui/app/properties/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export default function Properties() {
onClick={() =>
openModal(
<BuyPropertyModal
imgSrc={image}
data={data}
fundingToken={fundingToken}
sftDetails={sftDetails}
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/components/MainMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use client";

import Image from "next/image";
import Link from "next/link";
import { usePathname } from "next/navigation";
import LoggedUserInfo from "./LoggedUserInfo";
Expand All @@ -12,7 +13,7 @@ export default function MainMenu() {
<div className="menu-w menu-position-side menu-side-left menu-layout-mini sub-menu-style-over sub-menu-color-bright menu-activated-on-hover menu-has-selected-link color-scheme-dark color-style-transparent selected-menu-color-bright">
<div className="logo-w">
<a className="logo" href="/">
<div className="logo-element"></div>
<Image src="/logo.svg" alt="smart-housing" width={50} height={50} />
<div className="logo-label">{APP_NAME}</div>
</a>
</div>
Expand Down
4 changes: 1 addition & 3 deletions packages/ui/components/TransactionWaitingIcon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import styles from "./style.module.scss";

export type IconReqState = "idle" | "error" | "success" | "pending";

const matchStrings = [" reason:", " Error:"];
const matchStrings = [" reason:", " Error:", "TransactionExecutionError:"];
const processedMatchString = matchStrings.reduce((acc, curr, index) => {
acc += curr;

Expand All @@ -21,8 +21,6 @@ const errorMsg = (msg: string) => {
const regEx = new RegExp("(" + processedMatchString + ")(\n)?(.*)", "g");
const match = msg.match(regEx);

console.log({ match, msg });

const error = match?.at(-1)?.replace(processedMatchString, "");

return error;
Expand Down
Loading

0 comments on commit 3e2f7ac

Please sign in to comment.