Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
fix(images): Support asset images upload (#763)
Browse files Browse the repository at this point in the history
  • Loading branch information
immasandwich authored Jun 27, 2022
1 parent 105b31c commit a6c99f4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
27 changes: 25 additions & 2 deletions scripts/compile-app-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ const exec = util.promisify(require('child_process').exec);

const [targetDirectory] = process.argv.slice(2);

const run = async () => {
const compileLegacyAppLogoImages = async () => {
const { stdout } = await exec(
`git diff HEAD~1 --name-only --diff-filter=AMR | grep "src/apps/.*/assets/logo.png" || true`,
);

if (stdout === '') exit(0);
if (stdout === '') return;

const filepaths = stdout.split('\n').filter(s => s !== '');

Expand All @@ -24,7 +24,30 @@ const run = async () => {
if (!fs.existsSync(targetDirectory)) fs.mkdirSync(targetDirectory, { recursive: true });
fs.copyFileSync(filepath, path.join(targetDirectory, newFile));
});
};

const compileAppAssetImages = async () => {
const { stdout } = await exec(
`git diff HEAD~1 --name-only --diff-filter=AMR | grep "src/apps/.*/assets/.*.png" || true`,
);

if (stdout === '') return;

const filepaths = stdout.split('\n').filter(s => s !== '');

filepaths.forEach(filepath => {
const [, appId] = filepath.match(/src\/apps\/(.*)\/assets\/.*/);
const appDirectory = path.join(targetDirectory, appId);
const newFile = path.basename(filepath);

if (!fs.existsSync(appDirectory)) fs.mkdirSync(appDirectory, { recursive: true });
fs.copyFileSync(filepath, path.join(appDirectory, newFile));
});
};

const run = async () => {
await compileLegacyAppLogoImages();
await compileAppAssetImages();
exit(0);
};

Expand Down
8 changes: 6 additions & 2 deletions src/app-toolkit/helpers/presentation/image.present.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ export const getTokenImg = (address: string, network: Network = Network.ETHEREUM
return `https://storage.googleapis.com/zapper-fi-assets/tokens/${network}/${address}.png`;
};

export const getAppImg = (appName: string) => {
return `https://storage.googleapis.com/zapper-fi-assets/apps/${appName}.png`;
export const getAppImg = (appId: string) => {
return `https://storage.googleapis.com/zapper-fi-assets/apps/${appId}.png`;
};

export const getAppAssetImage = (appId: string, filename: string) => {
return `https://storage.googleapis.com/zapper-fi-assets/apps/${appId}/${filename}.png`;
};

export const getNetworkImg = (network: Network) => {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a6c99f4

Please sign in to comment.