Skip to content

Commit

Permalink
fix blockies
Browse files Browse the repository at this point in the history
  • Loading branch information
minaxolone committed Jun 9, 2024
1 parent 30759dc commit 2e7512b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { FC } from 'react';
import { format } from 'date-fns';
import { BlockMetadataTransaction, Movement, ScriptUserTransaction, TransactionType, UserTransaction } from '../../../../movements';
import clsx from 'clsx';
import {
BlockMetadataTransaction,
Movement,
ScriptUserTransaction,
TransactionType,
UserTransaction,
} from '../../../../movements';

import GenesisMovement from './GenesisMovement';
import BlockMetadataMovement from './BlockMetadataMovement';
import UserMovement from './UserMovement';
import LibraAmount from '../../../../ui/LibraAmount';
import clsx from 'clsx';

const MovementItem: FC<{ movement: Movement }> = ({ movement }) => {
const success =
Expand Down
2 changes: 1 addition & 1 deletion web-app/src/modules/ui/AccountAddress/AccountAddress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { toast } from 'react-toastify';
import { normalizeHexString } from '../../../utils';
import HexString from '../HexString';
import CopyIcon from '../Icons/CopyIcon';
import AddressAvatar from '../AddressAvatar/AddressAvatar';
import AddressAvatar from '../AddressAvatar';

interface Props {
address: string;
Expand Down
19 changes: 9 additions & 10 deletions web-app/src/modules/ui/AddressAvatar/blockies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ function createImageData(size: number) {
for (let x = 0; x < dataWidth; x++) {
// this makes foreground and background color to have a 43% (1/2.3) probability
// spot color has 13% chance
row[x] = Math.floor(rand() * 2.3);
const v = Math.floor(rand() * 2.3);
row[x] = v;
}
const r = row.slice(0, mirrorWidth);
r.reverse();
Expand All @@ -71,22 +72,21 @@ function createImageData(size: number) {
}

function buildOpts(opts: Partial<Options>): Options {
const newOpts = {
const seed = opts.seed || Math.floor(Math.random() * Math.pow(10, 16)).toString(16);
seedrand(seed);

return {
size: opts.size || 8,
scale: opts.scale || 4,
color: opts.color || createColor(),
bgcolor: opts.bgcolor || createColor(),
spotcolor: opts.spotcolor || createColor(),
seed: opts.seed || Math.floor(Math.random() * Math.pow(10, 16)).toString(16),
seed,
};

seedrand(newOpts.seed);

return newOpts;
}

export function renderIcon(options: Partial<Options>, canvas: HTMLCanvasElement) {
let opts = buildOpts(options);
function renderIcon(options: Partial<Options>, canvas: HTMLCanvasElement) {
const opts = buildOpts(options);

const imageData = createImageData(opts.size);
const width = Math.sqrt(imageData.length);
Expand All @@ -106,7 +106,6 @@ export function renderIcon(options: Partial<Options>, canvas: HTMLCanvasElement)

// if data is 2, choose spot color, if 1 choose foreground
cc.fillStyle = imageData[i] == 1 ? opts.color : opts.spotcolor;

cc.fillRect(col * opts.scale, row * opts.scale, opts.scale, opts.scale);
}
}
Expand Down
1 change: 1 addition & 0 deletions web-app/src/modules/ui/AddressAvatar/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "./AddressAvatar";

0 comments on commit 2e7512b

Please sign in to comment.