Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client lib fixes #2706

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion .github/workflows/action_deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ jobs:
- name: Deploy to npm
run: |
npm publish --workspace packages/interfaces
npm publish --workspace packages/client
cd packages/client/lib && npm publish

roll-firestore:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/action_deploy-wen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
- name: Deploy to npm as "upcoming" package
run: |
npm publish --workspace packages/interfaces --tag next
npm publish --workspace packages/client --tag next
cd packages/client/lib && npm publish --tag next
deploy_functions:
runs-on: ubuntu-latest
environment: staging
Expand Down
204 changes: 98 additions & 106 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"serve": "run-p \"run:search\" \"run:functions\"",
"lint": "eslint --ext .js,.ts src",
"build": "tsc",
"postbuild": "cp package.json ./lib",
"test": "jest"
},
"dependencies": {
"@build-5/interfaces": "*",
"@iota/sdk": "1.1.4",
"axios": "^1.6.2",
"bip39": "3.1.0",
"form-data": "^4.0.0",
Expand Down
1 change: 0 additions & 1 deletion packages/client/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export { https } from './https';
export { otr } from './otr';
export { createWallet } from './wallet';
42 changes: 27 additions & 15 deletions packages/client/src/otr/datasets/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Dataset, MIN_IOTA_AMOUNT, Network } from '@build-5/interfaces';
import { Dataset, Network } from '@build-5/interfaces';
import { v4 as uuid } from 'uuid';
import { MemberOtrDataset } from './MemberOtrDataset';
import { ProposalOtrDataset } from './ProposalOtrDataset';
Expand Down Expand Up @@ -32,34 +32,30 @@ export class OtrRequest<T> {
public readonly nativeToken?: INativeToken,
) {}

getMetadata = () => {
const data = {
targetAddress: this.otrAddress,
amount: this.amount,
metadata: { request: this.metadata },
nativeToken: this.nativeToken,
tag: this.generateTag(),
};
return { ...data, amount: Math.max(MIN_IOTA_AMOUNT / 2, this.amount || 0) };
};
getMetadata = () => ({
targetAddress: this.otrAddress,
metadata: { request: this.metadata },
nativeToken: this.nativeToken,
tag: this.generateTag(),
amount: this.amount,
});

getFireflyDeepLink = () => {
const { amount, metadata, nativeToken, tag } = this.getMetadata();
const { metadata, nativeToken, tag } = this.getMetadata();
const walletType = getFireflyWalletType(this.otrAddress);
return (
walletType +
`://wallet/sendConfirmation?address=${this.otrAddress}` +
'&disableToggleGift=true&disableChangeExpiration=true' +
`&amount=${nativeToken ? nativeToken.amount : amount}` +
`&amount=${nativeToken ? nativeToken.amount : this.amount}` +
`&tag=${tag}&giftStorageDeposit=true` +
`&metadata=${JSON.stringify(metadata)}` +
(nativeToken ? `&assetId=${nativeToken?.id}` : '')
);
};

getBloomDeepLink = () => {
const { amount, metadata, nativeToken, tag } = this.getMetadata();

const { metadata, nativeToken, tag, amount } = this.getMetadata();
const parameters = {
address: this.otrAddress,
baseCoinAmount: Number(amount).toFixed(0),
Expand Down Expand Up @@ -103,3 +99,19 @@ const getFireflyWalletType = (otrAddress: string) => {
}
throw Error('Invalid otr address, ono firefly wallet type found');
};

export const toHex = (stringToConvert: string) =>
'0x' +
stringToConvert
.split('')
.map((c) => c.charCodeAt(0).toString(16).padStart(2, '0'))
.join('');

export const otrAddressToNetwork = (address: string): Network => {
for (const network of Object.values(Network)) {
if (address.startsWith(network)) {
return network as Network;
}
}
throw Error('Invalid otr address');
};
26 changes: 13 additions & 13 deletions packages/client/src/otr/otr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { NftOtrDataset } from './datasets/NftOtrDataset';
import { ProposalOtrDataset } from './datasets/ProposalOtrDataset';
import { SpaceOtrDataset } from './datasets/SpaceOtrDataset';
import { TokenOtrDataset } from './datasets/TokenOtrDataset';
import { DatasetType } from './datasets/common';
import { DatasetType, toHex } from './datasets/common';

export class OtrWrapper {
constructor(private readonly otrAddress: string) {}
Expand All @@ -42,13 +42,17 @@ export class OtrWrapper {
}

trackByTag = (tag: string) => {
const origin = this.otrAddress.startsWith(Network.SMR) ? Build5.PROD : Build5.TEST;
const origin = this.otrAddress.startsWith(Network.RMS) ? Build5.TEST : Build5.PROD;
adamunchained marked this conversation as resolved.
Show resolved Hide resolved
return new Observable(origin, tag);
};
}

class Observable extends RxjsObservable<TangleResponse> {
private observer: Subscriber<TangleResponse> | undefined;
interface TagTrackResult extends TangleResponse {
chainReference?: string;
}

class Observable extends RxjsObservable<TagTrackResult> {
private observer: Subscriber<TagTrackResult> | undefined;
private paymentsSubs: Subscription | undefined;
private payments: string[] = [];
private dataset: TransactionDataset<Dataset.TRANSACTION> | undefined;
Expand Down Expand Up @@ -83,12 +87,15 @@ class Observable extends RxjsObservable<TangleResponse> {
const result = await this.dataset!.getBySourceTransaction(payment.uid);
const credit = result.find((t) => t.type === TransactionType.CREDIT_TANGLE_REQUEST);
if (credit) {
this.observer?.next(credit.payload.response);
this.observer?.next({
...credit.payload.response,
chainReference: credit.payload.chainReference || '',
});
return;
}
const transfer = result.find((t) => t.type === TransactionType.UNLOCK);
if (transfer) {
this.observer?.next({ status: 'success' });
this.observer?.next({ status: 'Success' });
return;
}
await new Promise((resolve) => setTimeout(resolve, 1000));
Expand All @@ -100,10 +107,3 @@ class Observable extends RxjsObservable<TangleResponse> {
this.observer?.complete();
};
}

const toHex = (stringToConvert: string) =>
'0x' +
stringToConvert
.split('')
.map((c) => c.charCodeAt(0).toString(16).padStart(2, '0'))
.join('');
38 changes: 0 additions & 38 deletions packages/client/src/wallet/client.ts

This file was deleted.

15 changes: 0 additions & 15 deletions packages/client/src/wallet/common.ts

This file was deleted.

7 changes: 0 additions & 7 deletions packages/client/src/wallet/index.ts

This file was deleted.

35 changes: 0 additions & 35 deletions packages/client/src/wallet/output.ts

This file was deleted.

Loading