Skip to content

Commit

Permalink
check horizon registry before registering on horizon
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlanglen committed Oct 27, 2023
1 parent f314fb6 commit 0756d75
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
25 changes: 17 additions & 8 deletions apps/potlock/widget/Project/CreateForm.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const ownerId = "potlock.near";
const registryId = "registry.potlock.near"; // TODO: update when registry is deployed
const registryId = "registry.potlock.near";
const horizonId = "nearhorizon.near";

const IPFS_BASE_URL = "https://nftstorage.link/ipfs/";
// const DEFAULT_BANNER_IMAGE_URL =
Expand Down Expand Up @@ -27,6 +28,10 @@ if (!context.accountId) {
);
}

const existingHorizonProject = Near.view(horizonId, "get_project", {
account_id: context.accountId,
});

const projects = Near.view(registryId, "get_projects", {});

const imageHeightPx = 120;
Expand Down Expand Up @@ -436,12 +441,6 @@ const handleCreateProject = (e) => {
];
if (!props.edit) {
transactions.push(
// register on NEAR Horizon
{
contractName: "nearhorizon.near",
methodName: "add_project",
args: horizonArgs,
},
// register project on potlock
{
contractName: registryId,
Expand All @@ -450,8 +449,18 @@ const handleCreateProject = (e) => {
args: potlockRegistryArgs,
}
);
if (!existingHorizonProject) {
transactions.push(
// register on NEAR Horizon
{
contractName: horizonId,
methodName: "add_project",
args: horizonArgs,
}
);
}
}
const res = Near.call(transactions);
Near.call(transactions);
};

const registeredProject = state.registeredProjects
Expand Down
25 changes: 17 additions & 8 deletions build/potlock/src/Project/CreateForm.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const ownerId = "potlock.near";
const registryId = "registry.potlock.near"; // TODO: update when registry is deployed
const registryId = "registry.potlock.near";
const horizonId = "nearhorizon.near";

const IPFS_BASE_URL = "https://nftstorage.link/ipfs/";
// const DEFAULT_BANNER_IMAGE_URL =
Expand Down Expand Up @@ -27,6 +28,10 @@ if (!context.accountId) {
);
}

const existingHorizonProject = Near.view(horizonId, "get_project", {
account_id: context.accountId,
});

const projects = Near.view(registryId, "get_projects", {});

const imageHeightPx = 120;
Expand Down Expand Up @@ -436,12 +441,6 @@ const handleCreateProject = (e) => {
];
if (!props.edit) {
transactions.push(
// register on NEAR Horizon
{
contractName: "nearhorizon.near",
methodName: "add_project",
args: horizonArgs,
},
// register project on potlock
{
contractName: registryId,
Expand All @@ -450,8 +449,18 @@ const handleCreateProject = (e) => {
args: potlockRegistryArgs,
}
);
if (!existingHorizonProject) {
transactions.push(
// register on NEAR Horizon
{
contractName: horizonId,
methodName: "add_project",
args: horizonArgs,
}
);
}
}
const res = Near.call(transactions);
Near.call(transactions);
};

const registeredProject = state.registeredProjects
Expand Down

0 comments on commit 0756d75

Please sign in to comment.