Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wagmi integrations #20

Open
wants to merge 7 commits into
base: workin
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Install dependencies
pnpm i
```

Copy `.env.example` to `.env.local` and set the NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID, NEXT_PUBLIC_INFURA_ID, SESSION_SECRET, NEXT_PUBLIC_CONTRACT_ADDRESS, NEXT_PUBLIC_SUPABASE_URL, NEXT_PUBLIC_SUPABASE_SECRET, NEXT_PUBLIC_PINATA_API_KEY.
Copy `.env.example` to `.env.local` and set the NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID, NEXT_PUBLIC_INFURA_ID, SESSION_SECRET, NEXT_PUBLIC_CONTRACT_ADDRESS, NEXT_PUBLIC_SUPABASE_URL, NEXT_PUBLIC_SUPABASE_SECRET, NEXT_PUBLIC_PINATA_API_KEY, NEXT_PUBLIC_PINATA_SECRET_API_KEY, NEXT_WEAVE_CONTRACT_ADDRESS, NEXT_WEAVE_LEADERBOARD_CONTRACT_ADDRESS, NEXT_WEAVE_EVENTS_FACTORY_CONTRACT_ADDRESS.

To get a WalletConnect project ID, go to [https://cloud.walletconnect.com/sign-in](https://cloud.walletconnect.com/sign-in)
Here also the link for Infura : [https://app.infura.io/](https://app.infura.io/)
Expand All @@ -36,9 +36,9 @@ openssl rand -base64 32
|------------------------|--------------------------------------------|
| Weave Contract | 0x5f856baB0F63a833b311fC9d853a14c8762d583d |
| Leaderboard Contract | 0x39545602B72Bd4a74FE1f4AF755c15C71C9780F0 |
| Vault Contract | 0x6a6C3b42e1af8BCd9adD11DFaDb9ab8445497914 |
| Event Factory Contract | 0x815257a8A46F2dE5F812DC3232CC0C0c24A7252a |
| Event Contract | X |
| Vault Contract | 0x4BE0E8654e9879877e8A806B839fE122fa0F880C |
| Event Factory Contract | 0xa90Db21B1B6008B4ad6710f093C026e04B0aa0A9 |
| Event Contract | 0xA225B8813a3D298b0fA5dD6357f4843B224A4678 |

## Stack

Expand Down
129 changes: 89 additions & 40 deletions contracts/contracts/EventsFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -115,54 +115,44 @@ contract EventFactory is Ownable {
return allEvents;
}


// Use the IEvent interface to call the functions of the Event contract
function getAllEventsDetails() external view returns (
string[] memory,
string[] memory,
uint256[] memory,
uint256[] memory,
int256[] memory,
int256[] memory,
uint256[] memory,
string[] memory
) {
string[] memory eventNames = new string[](allEvents.length);
string[] memory eventDescriptions = new string[](allEvents.length);
uint256[] memory eventStartDates = new uint256[](allEvents.length);
uint256[] memory eventEndDates = new uint256[](allEvents.length);
int256[] memory latitudes = new int256[](allEvents.length);
int256[] memory longitudes = new int256[](allEvents.length);
uint256[] memory eventRadiuses = new uint256[](allEvents.length);
string[] memory eventRadiusColors = new string[](allEvents.length);

for (uint256 i = 0; i < allEvents.length; i++) {
eventNames[i] = IEvent(allEvents[i]).getEventName();
eventDescriptions[i] = IEvent(allEvents[i]).getEventDescription();
eventStartDates[i] = IEvent(allEvents[i]).getEventStartingDate();
eventEndDates[i] = IEvent(allEvents[i]).getEventEndDate();
latitudes[i] = IEvent(allEvents[i]).getLatitude();
longitudes[i] = IEvent(allEvents[i]).getLongitude();
eventRadiuses[i] = IEvent(allEvents[i]).getEventRadius();
eventRadiusColors[i] = IEvent(allEvents[i]).getEventRadiusColor();
function getAllEventsDetails() external view returns (string[] memory) {
uint256 totalEvents = allEvents.length;
string[] memory allEventData = new string[](totalEvents * 8);

for (uint256 i = 0; i < totalEvents; i++) {
uint256 index = i * 8;

allEventData[index] = IEvent(allEvents[i]).getEventName();
allEventData[index + 1] = IEvent(allEvents[i]).getEventDescription();
allEventData[index + 2] = uint256ToString(IEvent(allEvents[i]).getEventStartingDate());
allEventData[index + 3] = uint256ToString(IEvent(allEvents[i]).getEventEndDate());
allEventData[index + 4] = int256ToString(IEvent(allEvents[i]).getLatitude());
allEventData[index + 5] = int256ToString(IEvent(allEvents[i]).getLongitude());
allEventData[index + 6] = uint256ToString(IEvent(allEvents[i]).getEventRadius());
allEventData[index + 7] = IEvent(allEvents[i]).getEventRadiusColor();
}

return (
eventNames,
eventDescriptions,
eventStartDates,
eventEndDates,
latitudes,
longitudes,
eventRadiuses,
eventRadiusColors
);
return allEventData;
}


function getEventManagers(address _eventAddress) external view returns (address[] memory) {
return IEvent(_eventAddress).getManagers();
}

function getAllEventManagers() external view returns (address[] memory) {
address[] memory allEventManagers = new address[](allEvents.length * 5);
uint256 counter = 0;
for (uint256 i = 0; i < allEvents.length; i++) {
address[] memory eventManagers = IEvent(allEvents[i]).getManagers();
for (uint256 j = 0; j < eventManagers.length; j++) {
allEventManagers[counter] = eventManagers[j];
counter++;
}
}
return allEventManagers;
}

function calculatingPriceToCreate(uint256 _eventStartDate, uint256 _eventEndDate, uint256 _eventRadius) internal pure returns (uint256) {
return ((_eventEndDate - _eventStartDate) / 86400 * 100) + (_eventRadius / 100);
}
Expand All @@ -178,4 +168,63 @@ contract EventFactory is Ownable {
function setLeaderboardAddress(address _leaderboardAddress) external onlyOwner {
leaderboardContractAddress = ILeaderboard(_leaderboardAddress);
}

// Helper function to convert uint256 to string
function uint256ToString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0";
}

uint256 temp = value;
uint256 length;

while (temp != 0) {
length++;
temp /= 10;
}

bytes memory result = new bytes(length);
uint256 index = length;

while (value != 0) {
index--;
result[index] = bytes1(uint8(48 + value % 10));
value /= 10;
}

return string(result);
}

// Helper function to convert int256 to string
function int256ToString(int256 value) internal pure returns (string memory) {
if (value == 0) {
return "0";
}

bool isNegative = value < 0;
uint256 temp = isNegative ? uint256(-value) : uint256(value);
uint256 length;

while (temp != 0) {
length++;
temp /= 10;
}

bytes memory result = new bytes(isNegative ? length + 1 : length);
uint256 index = length;

temp = isNegative ? uint256(-value) : uint256(value);

while (temp != 0) {
index--;
result[index] = bytes1(uint8(48 + temp % 10));
temp /= 10;
}

if (isNegative) {
result[0] = '-';
}

return string(result);
}
}
Loading