Skip to content
Draft
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
6 changes: 2 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions packages/core/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as IbanTools from 'ibantools';

type KeyType<T, U> = {
[K in keyof T]: T[K] extends U ? K : never;
}[keyof T];
Expand All @@ -10,6 +12,19 @@ export class Utils {
);
}

static createRules(rules: any): any {
for (const property in rules) {
if (rules[property] instanceof Array) {
rules[property] = rules[property].reduce((prev: any, curr: any) => Utils.updateObject(prev, curr), {});
}
}
return rules;
}

private static updateObject(obj?: any, update?: any): unknown {
return obj ? { ...obj, ...update } : undefined;
}

static formatAmount(amount?: number, decimals = 2): string {
return amount?.toFixed(decimals).replace(/\B(?=(\d{3})+(?!\d))/g, ' ') ?? '';
}
Expand All @@ -22,6 +37,10 @@ export class Utils {
return r;
}

static formatIban(iban?: string): string | null {
return IbanTools.friendlyFormatIBAN(iban);
}

static isJwt(jwt?: string): boolean {
return jwt ? /^[A-Za-z0-9_-]{2,}(?:\.[A-Za-z0-9_-]{2,}){2}$/.test(jwt) : false;
}
Expand All @@ -32,4 +51,13 @@ export class Utils {
.map((key) => `${key}=${encodeURIComponent(params[key] as string)}`)
.join('&');
}

static toBase64(file: File): Promise<string | undefined> {
return new Promise<string | undefined>((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => resolve(reader.result ? (reader.result as string) : undefined);
reader.onerror = (e) => reject(e);
});
}
}
3 changes: 1 addition & 2 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
"pack": "npm pack"
},
"dependencies": {
"ibantools": "^4.2.1",
"@dfx.swiss/core": "^0.1.1-beta.1",
"jwt-decode": "^3.1.2",
"libphonenumber-js": "^1.10.39",
"react": "^18.2.0",
"typescript": "^4.9.3"
}
Expand Down
38 changes: 2 additions & 36 deletions packages/react/src/definitions/asset.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,2 @@
import { Blockchain } from './blockchain';

export const AssetUrl = { get: 'asset' };

export enum AssetType {
COIN = 'Coin',
TOKEN = 'Token',
}

export enum AssetCategory {
PUBLIC = 'Public',
PRIVATE = 'Private',
}

export interface Asset {
id: number;
name: string;
uniqueName: string;
description: string;

buyable: boolean;
sellable: boolean;
cardBuyable: boolean;
cardSellable: boolean;
instantBuyable: boolean;
instantSellable: boolean;

blockchain: Blockchain;
comingSoon: boolean;
sortOrder?: number;
chainId?: string;
decimals?: number;
explorerUrl?: string;
type: AssetType;
category: AssetCategory;
}
export { AssetUrl, AssetType, AssetCategory } from '@dfx.swiss/core';
export type { Asset } from '@dfx.swiss/core';
47 changes: 2 additions & 45 deletions packages/react/src/definitions/auth.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,2 @@
export const AuthUrl = {
signMessage: 'auth/signMessage',
auth: 'auth',
signIn: 'auth/signIn',
signUp: 'auth/signUp',
signInWithMail: 'auth/mail',
lnurl: 'lnurla',
lnurlStatus: 'lnurla/status',
};

export interface SignMessage {
message: string;
}

export interface SignIn {
accessToken: string;
}

export interface LnurlAuth {
k1: string;
lnurl: string;
}

export type LnurlAuthStatus =
| {
isComplete: true;
accessToken: string;
}
| { isComplete: false };

export enum AuthWalletType {
METAMASK = 'MetaMask',
RABBY = 'Rabby',
WALLET_BROWSER = 'WalletBrowser',
TRUST = 'Trust',
PHANTOM = 'Phantom',
TRON_LINK = 'TronLink',
CLI = 'CLI',
LEDGER = 'Ledger',
BIT_BOX = 'BitBox',
TREZOR = 'Trezor',
ALBY = 'Alby',
WALLET_CONNECT = 'WalletConnect',
DFX_TARO = 'DfxTaro',
}
export { AuthUrl, AuthWalletType } from '@dfx.swiss/core';
export type { SignMessage, SignIn, LnurlAuth, LnurlAuthStatus } from '@dfx.swiss/core';
18 changes: 2 additions & 16 deletions packages/react/src/definitions/bank-account.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,2 @@
import { Fiat } from './fiat';

export const BankAccountUrl = {
get: 'bankAccount',
create: 'bankAccount',
update: (id: number) => `bankAccount/${id}`,
};

export interface BankAccount {
id: number;
iban: string;
active: boolean;
default: boolean;
label?: string;
preferredCurrency?: Fiat;
}
export { BankAccountUrl } from '@dfx.swiss/core';
export type { BankAccount } from '@dfx.swiss/core';
12 changes: 2 additions & 10 deletions packages/react/src/definitions/bank.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,2 @@
export const BankUrl = {
get: 'bank',
};

export interface Bank {
name: string;
iban: string;
bic: string;
currency: string;
}
export { BankUrl } from '@dfx.swiss/core';
export type { Bank } from '@dfx.swiss/core';
30 changes: 1 addition & 29 deletions packages/react/src/definitions/blockchain.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1 @@
export enum Blockchain {
BITCOIN = 'Bitcoin',
LIGHTNING = 'Lightning',
SPARK = 'Spark',
ARK = 'Ark',
FIRO = 'Firo',
MONERO = 'Monero',
ZANO = 'Zano',
INTERNET_COMPUTER = 'InternetComputer',
ETHEREUM = 'Ethereum',
SEPOLIA = 'Sepolia',
BINANCE_SMART_CHAIN = 'BinanceSmartChain',
OPTIMISM = 'Optimism',
ARBITRUM = 'Arbitrum',
POLYGON = 'Polygon',
BASE = 'Base',
GNOSIS = 'Gnosis',
HAQQ = 'Haqq',
LIQUID = 'Liquid',
ARWEAVE = 'Arweave',
CARDANO = 'Cardano',
RAILGUN = 'Railgun',
SOLANA = 'Solana',
TRON = 'Tron',
CITREA = 'Citrea',
CITREA_TESTNET = 'CitreaTestnet',

DEFICHAIN = 'DeFiChain',
}
export { Blockchain } from '@dfx.swiss/core';
1 change: 0 additions & 1 deletion packages/react/src/definitions/blocked-iban.json

This file was deleted.

63 changes: 2 additions & 61 deletions packages/react/src/definitions/buy.ts
Original file line number Diff line number Diff line change
@@ -1,61 +1,2 @@
import { Asset } from './asset';
import { Fees } from './fees';
import { Fiat } from './fiat';
import { PriceStep } from './price-step';
import { FiatPaymentMethod, TransactionError } from './transaction';

export const BuyUrl = {
receive: 'buy/paymentInfos',
invoice: (txId: number) => `buy/paymentInfos/${txId}/invoice`,
confirm: (txId: number) => `buy/paymentInfos/${txId}/confirm`,
};

export interface Buy {
id: number;
uid: string;
timestamp: Date;
name: string;
street: string;
number: string;
zip: string;
city: string;
country: string;
iban?: string;
bic: string;
sepaInstant: boolean;
routeId: number;
remittanceInfo?: string;
fees: Fees;
minVolume: number;
maxVolume: number;
amount: number;
currency: Fiat;
feesTarget: Fees;
minVolumeTarget: number;
maxVolumeTarget: number;
exchangeRate: number;
priceSteps: PriceStep[];
rate: number;
exactPrice: boolean;
estimatedAmount: number;
asset: Asset;
paymentRequest?: string;
paymentLink?: string;
isValid: boolean;
error?: TransactionError;
isPersonalIban?: boolean;
}

export interface BuyPaymentInfo {
currency: Fiat;
amount?: number;
asset: Asset;
targetAmount?: number;
paymentMethod?: FiatPaymentMethod;
externalTransactionId?: string;
exactPrice?: boolean;
}

export interface PdfDocument {
pdfData: string;
}
export { BuyUrl } from '@dfx.swiss/core';
export type { Buy, BuyPaymentInfo, PdfDocument } from '@dfx.swiss/core';
16 changes: 2 additions & 14 deletions packages/react/src/definitions/country.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,2 @@
export const CountryUrl = { get: 'country' };

export interface Country {
id: number;
symbol: string;
name: string;
locationAllowed: boolean;
kycAllowed: boolean;
nationalityAllowed: boolean;
bankAllowed: boolean;
cardAllowed: boolean;
cryptoAllowed: boolean;
kycOrganizationAllowed: boolean;
}
export { CountryUrl } from '@dfx.swiss/core';
export type { Country } from '@dfx.swiss/core';
21 changes: 2 additions & 19 deletions packages/react/src/definitions/error.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,2 @@
export interface ApiError {
/**
* HTTP status code from the API response.
* A value of 0 indicates a network-level error (e.g., server unreachable, CORS, timeout).
*/
statusCode: number;
message: string;
}

export class ApiException extends Error implements ApiError {
constructor(
public readonly statusCode: number,
message: string,
) {
super(message);
this.name = 'ApiException';
Object.setPrototypeOf(this, ApiException.prototype);
}
}
export { ApiException } from '@dfx.swiss/core';
export type { ApiError } from '@dfx.swiss/core';
14 changes: 1 addition & 13 deletions packages/react/src/definitions/fees.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1 @@
export interface Fees {
rate: number;
fixed: number;
min: number;
dfx: number;
bank: number;
bankFixed?: number;
bankPercent?: number;
network: number;
total: number;
networkStart?: number;
platform: number;
}
export type { Fees } from '@dfx.swiss/core';
14 changes: 2 additions & 12 deletions packages/react/src/definitions/fiat.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,2 @@
export const FiatUrl = { get: 'fiat' };

export interface Fiat {
id: number;
name: string;
buyable: boolean;
sellable: boolean;
cardBuyable: boolean;
cardSellable: boolean;
instantBuyable: boolean;
instantSellable: boolean;
}
export { FiatUrl } from '@dfx.swiss/core';
export type { Fiat } from '@dfx.swiss/core';
5 changes: 1 addition & 4 deletions packages/react/src/definitions/file.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
export interface CustomFile {
data: Blob;
headers: Record<string, string>;
}
export type { CustomFile } from '@dfx.swiss/core';
Loading
Loading