Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions scripts/.env.db-debug.sample

This file was deleted.

22 changes: 14 additions & 8 deletions scripts/db-debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
# ./scripts/db-debug.sh --asset-history Yapeal/EUR 10 # Show asset balance history
#
# Environment:
# Copy .env.db-debug.sample to .env.db-debug and fill in your credentials
# Uses the central .env file. Required variables:
# - DEBUG_ADDRESS: Wallet address with DEBUG role
# - DEBUG_SIGNATURE: Signature from signing the DFX login message
# - DEBUG_API_URL (optional): API URL, defaults to https://api.dfx.swiss/v1
#
# Requirements:
# - curl
Expand Down Expand Up @@ -102,26 +105,29 @@ esac

# --- Load environment ---
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ENV_FILE="$SCRIPT_DIR/.env.db-debug"
ENV_FILE="$SCRIPT_DIR/../.env"

if [ -f "$ENV_FILE" ]; then
source "$ENV_FILE"
else
if [ ! -f "$ENV_FILE" ]; then
echo "Error: Environment file not found: $ENV_FILE"
echo "Copy .env.db-debug.sample to .env.db-debug and fill in your credentials"
echo "Create .env in the api root directory"
exit 1
fi

# Read specific variables (avoid sourcing to prevent bash keyword conflicts)
DEBUG_ADDRESS=$(grep -E "^DEBUG_ADDRESS=" "$ENV_FILE" | cut -d'=' -f2-)
DEBUG_SIGNATURE=$(grep -E "^DEBUG_SIGNATURE=" "$ENV_FILE" | cut -d'=' -f2-)
DEBUG_API_URL=$(grep -E "^DEBUG_API_URL=" "$ENV_FILE" | cut -d'=' -f2-)

if [ -z "$DEBUG_ADDRESS" ] || [ -z "$DEBUG_SIGNATURE" ]; then
echo "Error: DEBUG_ADDRESS and DEBUG_SIGNATURE must be set in $ENV_FILE"
echo "Error: DEBUG_ADDRESS and DEBUG_SIGNATURE must be set in .env"
exit 1
fi

API_URL="${DEBUG_API_URL:-https://api.dfx.swiss/v1}"

# --- Authenticate ---
echo "=== Authenticating to $API_URL ==="
TOKEN_RESPONSE=$(curl -s -X POST "$API_URL/auth/signIn" \
TOKEN_RESPONSE=$(curl -s -X POST "$API_URL/auth" \
-H "Content-Type: application/json" \
-d "{\"address\":\"$DEBUG_ADDRESS\",\"signature\":\"$DEBUG_SIGNATURE\"}")

Expand Down
22 changes: 14 additions & 8 deletions scripts/log-debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,31 @@
# -h, --hours <n> Time range in hours (default: 1, max: 168)
#
# Environment:
# Copy .env.db-debug.sample to .env.db-debug and fill in your credentials
# Uses the central .env file. Required variables:
# - DEBUG_ADDRESS: Wallet address with DEBUG role
# - DEBUG_SIGNATURE: Signature from signing the DFX login message
# - DEBUG_API_URL (optional): API URL, defaults to https://api.dfx.swiss/v1

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ENV_FILE="$SCRIPT_DIR/.env.db-debug"
ENV_FILE="$SCRIPT_DIR/../.env"

# Load environment variables
if [ -f "$ENV_FILE" ]; then
source "$ENV_FILE"
else
if [ ! -f "$ENV_FILE" ]; then
echo "Error: Environment file not found: $ENV_FILE"
echo "Copy .env.db-debug.sample to .env.db-debug and fill in your credentials"
echo "Create .env in the api root directory"
exit 1
fi

# Read specific variables (avoid sourcing to prevent bash keyword conflicts)
DEBUG_ADDRESS=$(grep -E "^DEBUG_ADDRESS=" "$ENV_FILE" | cut -d'=' -f2-)
DEBUG_SIGNATURE=$(grep -E "^DEBUG_SIGNATURE=" "$ENV_FILE" | cut -d'=' -f2-)
DEBUG_API_URL=$(grep -E "^DEBUG_API_URL=" "$ENV_FILE" | cut -d'=' -f2-)

# Validate required variables
if [ -z "$DEBUG_ADDRESS" ] || [ -z "$DEBUG_SIGNATURE" ]; then
echo "Error: DEBUG_ADDRESS and DEBUG_SIGNATURE must be set in $ENV_FILE"
echo "Error: DEBUG_ADDRESS and DEBUG_SIGNATURE must be set in .env"
exit 1
fi

Expand All @@ -60,7 +66,7 @@ done

# Get JWT Token
echo "=== Authenticating to $API_URL ==="
TOKEN_RESPONSE=$(curl -s -X POST "$API_URL/auth/signIn" \
TOKEN_RESPONSE=$(curl -s -X POST "$API_URL/auth" \
-H "Content-Type: application/json" \
-d "{\"address\":\"$DEBUG_ADDRESS\",\"signature\":\"$DEBUG_SIGNATURE\"}")

Expand Down
9 changes: 9 additions & 0 deletions scripts/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,15 @@ async function main() {
// Register user
const authResponse = await registerUser(adminWallet.address, signature);
logSuccess(`User registered (ID: ${authResponse.accessToken ? 'received JWT' : 'no token'})`);

// Save DEBUG credentials for debug scripts
updateEnvFile({
DEBUG_ADDRESS: adminWallet.address,
DEBUG_SIGNATURE: signature,
DEBUG_API_URL: API_URL + '/v1',
});
logSuccess('Debug credentials saved to .env');

registrationSuccess = true;
break;

Expand Down
8 changes: 7 additions & 1 deletion src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -914,11 +914,17 @@ export class Configuration {
},
bank: {
recipient: process.env.REALUNIT_BANK_RECIPIENT ?? 'RealUnit Schweiz AG',
address: process.env.REALUNIT_BANK_ADDRESS ?? 'Schochenmühlestrasse 6, 6340 Baar, Switzerland',
iban: process.env.REALUNIT_BANK_IBAN ?? 'CH22 0830 7000 5609 4630 9',
bic: process.env.REALUNIT_BANK_BIC ?? 'HYPLCH22XXX',
name: process.env.REALUNIT_BANK_NAME ?? 'Hypothekarbank Lenzburg',
},
address: {
street: process.env.REALUNIT_ADDRESS_STREET ?? 'Schochenmühlestrasse',
number: process.env.REALUNIT_ADDRESS_NUMBER ?? '6',
zip: process.env.REALUNIT_ADDRESS_ZIP ?? '6340',
city: process.env.REALUNIT_ADDRESS_CITY ?? 'Baar',
country: process.env.REALUNIT_ADDRESS_COUNTRY ?? 'Switzerland',
},
},
ebel2x: {
contractAddress: process.env.EBEL2X_CONTRACT_ADDRESS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,12 @@ export class ScryptWebSocketConnection {
});

ws.on('close', (code, reason) => {
this.logger.warn(`Scrypt WebSocket closed (code: ${code}, reason: ${reason})`);
this.handleDisconnection();
this.handleDisconnection(code, reason);
});
});
}

private handleDisconnection(): void {
private handleDisconnection(code?: number, reason?: string): void {
const wasConnected = this.connectionState === ConnectionState.CONNECTED;
this.connectionState = ConnectionState.DISCONNECTED;
this.ws = undefined;
Expand All @@ -229,7 +228,9 @@ export class ScryptWebSocketConnection {

// reconnect
if (wasConnected) {
this.logger.warn(`Unexpected disconnection, attempting reconnect in ${this.reconnectDelay}ms`);
this.logger.warn(
`Scrypt WebSocket closed (code: ${code}, reason: ${reason}), attempting reconnect in ${this.reconnectDelay}ms`,
);

setTimeout(() => {
void this.connect()
Expand Down
56 changes: 37 additions & 19 deletions src/shared/utils/pdf.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PDFDocument from 'pdfkit';
import { Asset } from 'src/shared/models/asset/asset.entity';
import { PdfLanguage } from 'src/subdomains/supporting/balance/dto/input/get-balance-pdf.dto';
import { PriceCurrency } from 'src/subdomains/supporting/pricing/services/pricing.service';
import { mm2pt } from 'swissqrbill/utils';
import { dfxLogoBall1, dfxLogoBall2, dfxLogoText } from './logos/dfx-logo';
import { realunitLogoColor, realunitLogoPath } from './logos/realunit-logo';

Expand All @@ -11,6 +12,11 @@ export enum PdfBrand {
REALUNIT = 'REALUNIT',
}

export enum LogoSize {
SMALL = 'SMALL',
LARGE = 'LARGE',
}

export interface BalanceEntry {
asset: Asset;
balance: number;
Expand All @@ -19,19 +25,43 @@ export interface BalanceEntry {
}

export class PdfUtil {
static drawLogo(pdf: InstanceType<typeof PDFDocument>, brand: PdfBrand = PdfBrand.DFX): void {
static drawLogo(
pdf: InstanceType<typeof PDFDocument>,
brand: PdfBrand = PdfBrand.DFX,
size: LogoSize = LogoSize.SMALL,
): void {
const { x, y, scale } = this.getLogoConfig(size);

pdf.save();
pdf.translate(x, y);
pdf.scale(scale);

if (brand === PdfBrand.REALUNIT) {
this.drawRealUnitLogo(pdf);
this.drawRealUnitLogoPath(pdf);
} else {
this.drawDfxLogo(pdf);
this.drawDfxLogoPath(pdf);
}

pdf.restore();

// Extra vertical offset for RealUnit small logo
if (brand === PdfBrand.REALUNIT && size === LogoSize.SMALL) {
pdf.translate(0, 30);
}
}

private static drawDfxLogo(pdf: InstanceType<typeof PDFDocument>): void {
pdf.save();
pdf.translate(50, 30);
pdf.scale(0.12);
private static getLogoConfig(size: LogoSize): { x: number; y: number; scale: number } {
if (size === LogoSize.LARGE) {
return { x: mm2pt(20), y: mm2pt(14), scale: 0.15 };
}
return { x: 50, y: 30, scale: 0.12 };
}

private static drawRealUnitLogoPath(pdf: InstanceType<typeof PDFDocument>): void {
pdf.path(realunitLogoPath).fill(realunitLogoColor);
}

private static drawDfxLogoPath(pdf: InstanceType<typeof PDFDocument>): void {
const gradient1 = pdf.linearGradient(122.111, 64.6777, 45.9618, 103.949);
gradient1
.stop(0.04, '#F5516C')
Expand All @@ -47,18 +77,6 @@ export class PdfUtil {
pdf.path(dfxLogoBall1).fill(gradient1);
pdf.path(dfxLogoBall2).fill(gradient2);
pdf.path(dfxLogoText).fill('#072440');
pdf.restore();
}

private static drawRealUnitLogo(pdf: InstanceType<typeof PDFDocument>): void {
pdf.save();
pdf.translate(50, 30);
pdf.scale(0.12);
pdf.path(realunitLogoPath).fill(realunitLogoColor);

pdf.restore();

pdf.translate(0, 30);
}

static drawTable(
Expand Down
14 changes: 14 additions & 0 deletions src/shared/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ export class Util {
}
}

static floorReadable(amount: number, type: AmountType, assetPrecision?: number): number {
switch (type) {
case AmountType.ASSET:
case AmountType.ASSET_FEE:
return this.floorByPrecision(amount, assetPrecision ?? 5);

case AmountType.FIAT:
return this.floor(amount, 2);

case AmountType.FIAT_FEE:
return this.floor(amount, 2);
}
}

static round(amount: number, decimals: number): number {
return this.roundToValue(amount, Math.pow(10, -decimals));
}
Expand Down
Loading
Loading