Skip to content

Commit

Permalink
Merge branch 'development' into development_313
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmedHanafy725 committed Oct 9, 2023
2 parents 611dd8b + 05efc8e commit 4790228
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 14 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ This repo contains the typescript clients and projects for Threefold grid.
- [Playground](./packages/playground/README.md)
- [graphql_client](./packages/graphql_client/README.md)
- [gridproxy_client](./packages/gridproxy_client/README.md)
- [UI](./packages/UI/README.md)

## Requirements

Expand Down
10 changes: 7 additions & 3 deletions packages/UI/docs/pdf_viewer.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ To use the PDF Signer Web Component, follow these steps:

2. Navigate to the `repository/packages/UI` directory.

3. Run `yarn build` to generate the required distribution files.
3. Choose which provider you are going to use [see providers section](#using-providers-and-extensions)

4. Locate the `dist` folder created in the previous step.
4. Run `yarn build` to generate the required distribution files.

5. Copy the `dist/threefold-ui.umd.js` file and include it in your project's HTML files.
5. Locate the `dist` folder created in the previous step.

6. Copy the `dist/threefold-ui.umd.js` file and include it in your project's HTML files.

```html
<body>
Expand Down Expand Up @@ -101,6 +103,8 @@ Here's an example of how to use the PDF Signer Web Component in your HTML file:

In the example above, replace `<pdf-url>` and `<endpoint-url>` with the actual URLs for your PDF document and the destination where signed documents should be sent. Also, for the `<network>`, use one of the following network options: `[main, test, qa, dev]`.

PS: Please make sure that you have a `PDF URL` with `CORS-ORIGIN` enabled.

Feel free to customize the HTML structure and styles to match your application's design and requirements.

**Now you can serve your HTML file on any live-server plugin.**
Expand Down
8 changes: 5 additions & 3 deletions packages/UI/docs/script_editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ To create an instance of the Script Editor, follow these steps:

2. Navigate to the `repository/packages/UI` directory.

3. Run `yarn build` to generate the required distribution files.
3. Choose which provider you are going to use [see providers section](#using-providers-and-extensions)

4. Locate the `dist` folder created in the previous step.
4. Run `yarn build` to generate the required distribution files.

5. Copy the `dist/threefold-ui.umd.js` file and include it in your project's HTML files.
5. Locate the `dist` folder created in the previous step.

6. Copy the `dist/threefold-ui.umd.js` file and include it in your project's HTML files.

```html
<body>
Expand Down
6 changes: 1 addition & 5 deletions packages/UI/examples/server-example/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,12 @@ const verify = async (payload: Payload) => {

app.post("/api/verify", async (req: Request, res: Response) => {
const payload: Payload = req.body;
let content: Uint8Array = new Uint8Array();
try {
if (payload.pdfUrl) {
const response = await axios.get(payload.pdfUrl, { responseType: "arraybuffer" });
content = Uint8Array.from(Buffer.from(response.data, "base64"));
} else {
content = Uint8Array.from(Buffer.from(payload.content || "", "base64"));
payload.content = Uint8Array.from(Buffer.from(response.data, "base64")).toString();
}

payload.content = content.toString();
const verified = await verify(payload);

if (verified) {
Expand Down
5 changes: 4 additions & 1 deletion packages/UI/src/components/PDFSignerViewComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ export default {
pdfData.value = data.toString();
numOfPages.value = pdf.numPages;
} catch (error: any) {
showError({ isError: true, errorMessage: error.message });
showError({
isError: true,
errorMessage: "Please make sure that you have provided a PDF URL with CORS enabled.",
});
} finally {
loadingPdf.value = false;
}
Expand Down
39 changes: 39 additions & 0 deletions packages/grid_client/src/high_level/twinDeploymentHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,43 @@ class TwinDeploymentHandler {
return deployments;
}

async checkFarmIps(twinDeployments: TwinDeployment[]) {
const farmIPs: Map<number, number> = new Map();

for (const twinDeployment of twinDeployments) {
if (twinDeployment.operation !== Operations.deploy) {
continue;
}

if (twinDeployment.publicIps === 0) {
continue;
}

const node = await this.nodes.getNode(twinDeployment.nodeId);
if (!node) {
continue;
}
if (!farmIPs.has(node.farmId)) {
farmIPs.set(node.farmId, twinDeployment.publicIps);
} else {
farmIPs.set(node.farmId, farmIPs.get(node.farmId)! + twinDeployment.publicIps);
}
}

for (const farmId of farmIPs.keys()) {
const _farm = await this.tfclient.farms.get({ id: farmId });
const freeIps = _farm.publicIps.filter(res => res.contractId === 0).length;

if (freeIps < farmIPs.get(farmId)!) {
throw Error(
`Farm ${farmId} doesn't have enough public IPs: requested IPs=${farmIPs.get(
farmId,
)}, available IPs=${freeIps}`,
);
}
}
}

async checkNodesCapacity(twinDeployments: TwinDeployment[]) {
for (const twinDeployment of twinDeployments) {
let workloads: Workload[] = [];
Expand Down Expand Up @@ -439,6 +476,8 @@ class TwinDeploymentHandler {
twinDeployments = await this.merge(twinDeployments);
await this.validate(twinDeployments);
await this.checkNodesCapacity(twinDeployments);
await this.checkFarmIps(twinDeployments);

const contracts = { created: [], updated: [], deleted: [] };
const resultContracts = { created: [], updated: [], deleted: [] };
let nodeExtrinsics: ExtrinsicResult<Contract>[] = [];
Expand Down
1 change: 1 addition & 0 deletions packages/grid_client/src/modules/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ class FarmFilterOptions {
@Expose() @IsOptional() @IsInt() page?: number;
@Expose() @IsOptional() @IsInt() size?: number;
@Expose() @IsOptional() @IsInt() ownedBy?: number;
@Expose() @IsOptional() @IsInt() farmId?: number;
}

class CalculatorModel {
Expand Down
5 changes: 3 additions & 2 deletions packages/grid_client/src/primitives/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface FarmInfo {
interface PublicIps {
id: string;
ip: string;
contractId: number;
contract_id: number; // Added to match the one in the farm interface || TODO: Should we replace the whole http requests to be done with the gridProxy.
gateway: string;
}

Expand Down Expand Up @@ -176,7 +176,7 @@ class Nodes {
farms = await this.getAllFarms(url);
}
return farms
.filter(farm => farm.publicIps.filter(ip => ip.contractId === 0).length > 0)
.filter(farm => farm.publicIps.filter(ip => ip.contract_id === 0).length > 0)
.map(farm => farm.farmId)
.includes(farmId);
}
Expand Down Expand Up @@ -383,6 +383,7 @@ class Nodes {
node_has_gpu: options.nodeHasGPU,
node_rented_by: options.nodeRentedBy,
node_certified: options.nodeCertified,
farm_id: options.farmId,
};
return Object.entries(params)
.map(param => param.join("="))
Expand Down

0 comments on commit 4790228

Please sign in to comment.