Skip to content

Commit

Permalink
Add portal/farms (#1154)
Browse files Browse the repository at this point in the history
* Add createFarm in chain & client

* Add farms page layout & route

* Add getUserFarms

* Implement addFarmIP, removeFarmIP, addPublicConfig, addStellarAddress in chain & client

* Create grid store & set it in profile store

* add getUserNodes

* Render farm tables, route component if grid is set

* Fix expand tables, add public ips table

* Remove getUserNodes

* Create add ip, create farm & public ips table. Edit user farms.

* Add get-ip-range package

* fix add ip

* Add custom toast, fix add & delete IP

* Add farm actions, fix addStellarAddress

* Add node details

* Edit addConfig, add public config  & set extra fees components

* Fix node uptime

* Fix uptime type in node.ts

* Fix expanded in user nodes, Fix minting details

* Fix reciept uptime

* Fix farms table expand, change its return type. Fix public ips values

* Fix typo, edit farm details styling

* edit remove ip dialogue

* Add IP validation, fix range, emit add & remove ip

* Fix tables

* EDit public cofig validation, add btns loading, edit props & addConfig in grid & chain

* Use server side farms table, unify dialogue style, use node details, remove uptime progress

* Fix search farm, disable sorting, edit farms table to be server side

* Resolving comments

* Resolving comments

* Seperating global css.

* Unify dialogue styles

* Fixed prop types, fixed validation,

* edited public config prop type & fixed its validation.

* Update stellar once its set

* Added info toast once stellar is added. reload table once updated.

* Check for nodes before setting uptime, add button loading

* Add tooltip tp add_ip inputs

* Check balance before extrinsics, fix types in grid & chain

* Update farms table on create farm, add loading to create btn

* Add patchExtrinsic return type, fix config types

* fix farm name validation, add toast on error, fix status color

* Edit min extra fee, change expansion title color

* Edit extra fee decorators, fix delete ip dialogue

* Fix delete ip, fix return farm type, refactor node.ts

* Fix add IP range, fix table update

* Fix removePublicConfig, relax config validation in client, fix IPublicConfig type, Fix config binding

* Edit public config validation

* Add farm minting receipts, fix node uptime

* Edit public config validation

* resolving comments

* Replace batch w batchAll in add ip

* Fix public config null error, retrive contractId in PublicIP type and make it optional

* Fix add/remove config

* Update config pop up on add/remove

* Edit addIP request on range
  • Loading branch information
zaelgohary authored Nov 16, 2023
1 parent a0c4980 commit f13a6f0
Show file tree
Hide file tree
Showing 27 changed files with 2,518 additions and 136 deletions.
37 changes: 36 additions & 1 deletion packages/grid_client/src/modules/farms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import { TFClient } from "../clients/tf-grid/client";
import { GridClientConfig } from "../config";
import { expose } from "../helpers/expose";
import { validateInput } from "../helpers/validator";
import { FarmIdModel } from "./models";
import {
AddFarmIPModel,
AddStellarAddressToFarmModel,
CreateFarmModel,
FarmIdModel,
RemoveFarmIPModel,
} from "./models";
import { checkBalance } from "./utils";

class Farms {
client: TFClient;
Expand All @@ -11,6 +18,34 @@ class Farms {
this.client = config.tfclient;
}

@expose
@validateInput
@checkBalance
async create(options: CreateFarmModel) {
return (await this.client.farms.create(options)).apply();
}

@expose
@validateInput
@checkBalance
async addFarmIp(options: AddFarmIPModel) {
return (await this.client.farms.addFarmIp(options)).apply();
}

@expose
@validateInput
@checkBalance
async removeFarmIp(options: RemoveFarmIPModel) {
return (await this.client.farms.removeFarmIp(options)).apply();
}

@expose
@validateInput
@checkBalance
async addStellarAddress(options: AddStellarAddressToFarmModel) {
return (await this.client.farms.addStellarAddress(options)).apply();
}

@expose
@validateInput
async getFarmByID(options: FarmIdModel) {
Expand Down
52 changes: 51 additions & 1 deletion packages/grid_client/src/modules/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,51 @@ class FarmIdModel {
@Expose() @IsInt() @IsNotEmpty() @Min(1) id: number;
}

class FarmPublicIPsModel {
@Expose() @IsNotEmpty() @IsIP() ip: string;
@Expose() @IsNotEmpty() @IsString() gw: string;
}

class AddFarmIPModel {
@Expose() @IsInt() @IsNotEmpty() @Min(1) farmId: number;
@Expose() @IsNotEmpty() @IsString() ip: string;
@Expose() @IsNotEmpty() @IsIP() gw: string;
}

class IPConfig {
@Expose() @IsNotEmpty() @IsString() ip: string;
@Expose() @IsNotEmpty() @IsIP() gw: string;
}
class PublicConfigModel {
@Expose() @IsNotEmpty() @Type(() => IPConfig) @ValidateNested() ip4: IPConfig;
@Expose() @IsOptional() ip6: IPConfig | null;
@Expose() @IsOptional() @IsString() domain: string | null;
}
class AddPublicConfig {
@Expose() @IsInt() @IsNotEmpty() @Min(1) farmId: number;
@Expose() @IsInt() @IsNotEmpty() @Min(1) nodeId: number;
@Expose() @IsOptional() @Type(() => PublicConfigModel) @ValidateNested() publicConfig?: PublicConfigModel | null;
}

class RemoveFarmIPModel {
@Expose() @IsInt() @IsNotEmpty() @Min(1) farmId: number;
@Expose() @IsNotEmpty() @IsString() ip: string;
}

class AddStellarAddressToFarmModel {
@Expose() @IsInt() @IsNotEmpty() @Min(1) farmId: number;
@Expose() @IsString() @IsNotEmpty() stellarAddress: string;
}

class CreateFarmModel {
@Expose() @IsString() @IsNotEmpty() @MaxLength(NameLength) name: string;
@Expose()
@IsOptional()
@Type(() => FarmPublicIPsModel)
@ValidateNested({ each: true })
publicIps?: FarmPublicIPsModel[];
}

class pingFarmModel {
@Expose() @IsInt() @IsNotEmpty() @Min(1) farmId: number;
}
Expand All @@ -684,7 +729,7 @@ class NetworkGetModel {

class SetDedicatedNodeExtraFeesModel {
@Expose() @IsInt() @IsNotEmpty() @Min(1) nodeId: number;
@Expose() @IsInt() @IsNotEmpty() @Min(1) extraFee: number;
@Expose() @IsNumber() @IsNotEmpty() @Min(0) extraFee: number;
}

class GetDedicatedNodePriceModel {
Expand Down Expand Up @@ -814,6 +859,7 @@ export {
ZOSNodeModel,
NodePowerModel,
FarmIdModel,
CreateFarmModel,
pingFarmModel,
CreateServiceContractModel,
ServiceContractApproveModel,
Expand All @@ -830,5 +876,9 @@ export {
GetDedicatedNodePriceModel,
SwapToStellarModel,
ListenToMintCompletedModel,
AddFarmIPModel,
RemoveFarmIPModel,
AddStellarAddressToFarmModel,
AddPublicConfig,
GetActiveContractsModel,
};
8 changes: 8 additions & 0 deletions packages/grid_client/src/modules/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { events, validateInput } from "../helpers";
import { expose } from "../helpers/expose";
import { capacity } from "./capacity";
import {
AddPublicConfig,
FilterOptions,
NodeGetModel,
NodePowerModel,
Expand Down Expand Up @@ -82,6 +83,13 @@ class Nodes {
return (await this.client.nodes.setPower(options)).apply();
}

@expose
@validateInput
@checkBalance
async addNodePublicConfig(options: AddPublicConfig) {
return (await this.client.nodes.addNodePublicConfig(options)).apply();
}

@expose
async all() {
return await this.capacity.getAllNodes();
Expand Down
1 change: 1 addition & 0 deletions packages/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"vue-router": "^4.1.6",
"vuetify": "^3.1.15",
"web-ssh-keygen": "^0.1.2",
"get-ip-range": "^4.0.1",
"chart.js": "^4.4.0",
"vue-chartjs": "^5.2.0",
"moment": "^2.29.4"
Expand Down
127 changes: 4 additions & 123 deletions packages/playground/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
<router-view v-slot="{ Component }">
<transition name="fade">
<div :key="$route.path">
<component :is="Component" v-if="hasActiveProfile"></component>
<component :is="Component" v-if="hasActiveProfile && hasGrid"></component>
<ConnectWalletLanding @openProfile="openProfile = true" v-else />
</div>
</transition>
Expand All @@ -179,13 +179,15 @@ import { useProfileManager } from "./stores/profile_manager";
const $route = useRoute();
const $router = useRouter();
const profileManager = useProfileManager();
const gridStore = useGrid();
const network = process.env.NETWORK || (window as any).env.NETWORK;
const openProfile = ref(true);
const hasActiveProfile = computed(() => !!profileManager.profile);
const theme = useTheme();
const navbarConfig = ref();
const hasGrid = computed(() => !!gridStore.grid);
watch(
() => $route.meta,
meta => {
Expand Down Expand Up @@ -373,6 +375,7 @@ import FundsCard from "./components/funds_card.vue";
import ProfileManagerController from "./components/profile_manager_controller.vue";
import TftSwapPrice from "./components/swap_price.vue";
import TFNotification from "./components/tf_notification.vue";
import { useGrid } from "./stores";
import ProfileManager from "./weblets/profile_manager.vue";
interface AppRoute {
Expand Down Expand Up @@ -404,125 +407,3 @@ export default {
},
};
</script>

<style lang="scss" global>
:root {
--link-color: #5695ff;
}
.app-link {
text-decoration: none;
font-weight: bold;
color: var(--link-color);
cursor: pointer;
}
.fade-leave-active,
.fade-enter-active {
position: absolute;
top: 0;
left: 0;
width: 100%;
pointer-events: none;
transition: opacity 1s;
}
.fade-enter-from,
.fade-leave-to {
opacity: 0;
}
.capitalize {
text-transform: capitalize !important;
}
.v-btn {
text-transform: capitalize !important;
font-size: 1rem !important;
}
.version {
position: absolute;
bottom: 15px;
right: 25px;
}
.v-tooltip > .v-overlay__content {
// background: var(--v-theme-surface);
border-color: rgba(var(--v-border-color), var(--v-border-opacity)) !important;
border-width: thin !important;
border-style: solid !important;
z-index: 99;
background-color: rgb(var(--v-theme-background));
color: var(--v-theme-text);
font-weight: 900;
}
a {
color: #5695ff !important;
}
.v-list-item__prepend {
width: 35px !important;
}
.v-list-item-title {
font-size: 0.875rem;
}
.v-list-item--density-default.v-list-item--one-line {
min-height: 40px;
}
.custom-toolbar-title {
max-width: 17rem !important;
}
.mosha__toast__content-wrapper {
margin-bottom: -2px;
}
.mosha__toast__slot-wrapper {
margin-bottom: -2px;
}
.mosha__icon {
margin-right: 6px !important;
margin-top: 2px;
}
.mosha__icon__dark__warning {
fill: #5d5d5d !important;
}
.mosha__icon__light__warning {
fill: #5d5d5d !important;
}
.mosha__toast__content.dark__warning {
color: #5d5d5d;
}
.mosha__toast__content.light__warning {
color: #5d5d5d;
}
.mosha__toast__close-icon.dark__warning::before {
color: #5d5d5d !important;
}
.mosha__toast__close-icon.light__warning::before {
color: #5d5d5d !important;
}
.mosha__toast {
font-size: 14px !important;
font-weight: 600 !important;
}
.font-14 {
font-size: 14px !important;
}
.v-breadcrumbs-item--disabled {
opacity: 1;
}
</style>
Loading

0 comments on commit f13a6f0

Please sign in to comment.