Skip to content

Commit

Permalink
Fix invalid private/public storage link (#168)
Browse files Browse the repository at this point in the history
* rename "base storage" to "internal storage"

* fix comment typo

* fix public/private paths only point to internal paths of the same account

* throw an error for invalid argument
  • Loading branch information
bartolomej authored Jun 22, 2023
1 parent 0e5885f commit fa60c6e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
12 changes: 8 additions & 4 deletions backend/src/flow/services/config.service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { Injectable, Logger } from "@nestjs/common";
import {
Injectable,
Logger,
InternalServerErrorException,
} from "@nestjs/common";
import { readFile, writeFile, watch } from "fs/promises";
import * as path from "path";
import { ProjectContextLifecycle } from "../utils/project-context";
import { ProjectEntity } from "../../projects/project.entity";
import { ContractTemplate, TransactionTemplate } from "@flowser/shared";
import { AbortController } from "node-abort-controller";
import * as fs from "fs";
import { computeEntitiesDiff, isObject } from "../../utils";
import { isObject } from "../../utils";

type FlowAddress = string;

Expand Down Expand Up @@ -235,9 +239,9 @@ export class FlowConfigService implements ProjectContextLifecycle {
return writeFile(this.buildProjectPath(pathPostfix), data);
}

private buildProjectPath(pathPostfix: string | undefined | null) {
private buildProjectPath(pathPostfix: string) {
if (!pathPostfix) {
return null;
throw new InternalServerErrorException("Postfix path not provided");
}
// TODO(milestone-3): Detect if pathPostfix is absolute or relative and use it accordingly
return path.join(this.projectContext.filesystemPath, pathPostfix);
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/pages/accounts/details/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import Table from "../../../components/table/Table";
import MiddleEllipsis from "../../../components/ellipsis/MiddleEllipsis";
import Badge from "../../../components/badge/Badge";
import { PublicPrivateStorageCard } from "./PublicPrivateStorageCard";
import { BaseStorageCard } from "./BaseStorageCard";
import { InternalStorageCard } from "./InternalStorageCard";
import classNames from "classnames";
import { useUrlQuery } from "../../../hooks/use-url-query";
import {
Expand Down Expand Up @@ -141,7 +141,7 @@ const Details: FunctionComponent = () => {
if (focusedStorageId) {
expandCardById(focusedStorageId);
// We need to wait for the virtual nodes to be added to the browser DOM.
// This is achieved with setTimeout call - wait for the next window pain.
// This is achieved with setTimeout call - wait for the next window paint.
// There might be a better React way to do this.
setTimeout(() => {
const targetDomNode = document.getElementById(focusedStorageId);
Expand Down Expand Up @@ -179,7 +179,7 @@ const Details: FunctionComponent = () => {
const publicStorageItems = storageItems.filter(
(item) => item.pathDomain === AccountStorageDomain.STORAGE_DOMAIN_PUBLIC
);
const baseStorageItems = storageItems.filter(
const internalStorageItems = storageItems.filter(
(item) => item.pathDomain === AccountStorageDomain.STORAGE_DOMAIN_STORAGE
);

Expand Down Expand Up @@ -243,8 +243,8 @@ const Details: FunctionComponent = () => {
))}
</div>
<div className={classes.gridExtendable}>
{baseStorageItems.map((item) => (
<BaseStorageCard
{internalStorageItems.map((item) => (
<InternalStorageCard
key={item.id}
storageItem={item}
enableIntroAnimation={enableDetailsIntroAnimation}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type ExtendableStorageCardProps = {
enableIntroAnimation?: boolean;
};

export function BaseStorageCard({
export function InternalStorageCard({
storageItem,
onToggleExpand,
isExpanded,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ function getTargetStorageCardUrl(options: {
// Example: &String

const borrowTypePathParts = options.data?.BorrowType?.split(".");
const targetAccountAddress =
borrowTypePathParts && borrowTypePathParts.length > 1
? `0x${borrowTypePathParts?.[1]}`
: options.currentAccountAddress;
// Public or private storage paths can only
// point to "internal" storage paths of the same account.
// https://developers.flow.com/cadence/language/capability-based-access-control
const targetAccountAddress = options.currentAccountAddress;

const targetPathIdentifier = options.data?.TargetPath?.Identifier;

Expand Down

0 comments on commit fa60c6e

Please sign in to comment.