Skip to content

Commit

Permalink
Merge pull request #49 from nemmtor/fix/prod-issue
Browse files Browse the repository at this point in the history
Fix/prod issue
  • Loading branch information
lennardevertz authored Jan 19, 2024
2 parents 89b64ea + e4bfb25 commit 3672d01
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 24 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "idriss-crypto",
"version": "1.9.1",
"version": "1.9.2",
"main": "./lib/index.js",
"module": "./lib/esnext/index.js",
"exports": {
Expand Down Expand Up @@ -55,7 +55,7 @@
"@openzeppelin/contracts": "^4.7.3",
"@total-typescript/ts-reset": "^0.5.1",
"@truffle/hdwallet-provider": "^2.0.11",
"@types/node": "^20.10.8",
"@types/node": "^20.11.5",
"@typescript-eslint/eslint-plugin": "^6.4.0",
"@typescript-eslint/parser": "^6.18.1",
"hardhat": "^2.10.1",
Expand Down
14 changes: 12 additions & 2 deletions src/baseIdrissCrypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export abstract class BaseIdrissCrypto {
private tippingContract: Contract;

protected abstract digestMessage(message: string): Promise<string>;
protected abstract getConnectedAccount(): Promise<string>;
public abstract getConnectedAccount(): Promise<string>;

// we split web3 from web3 for registry, as registry is only accessible on Polygon,
// and library is about to support multiple chains
Expand Down Expand Up @@ -303,6 +303,7 @@ export abstract class BaseIdrissCrypto {

let result: SendToHashTransactionReceipt | TransactionReceipt;

console.log('line 306');
if (this.web3Provider.isAddress(beneficiary)) {
result = await this.callWeb3Tipping(
beneficiary,
Expand All @@ -312,10 +313,12 @@ export abstract class BaseIdrissCrypto {
);
return result;
}
console.log('line 315');

const hash = await this.getUserHash(resolveOptions, beneficiary);
const resolvedIDriss = await this.resolve(beneficiary);

console.log('line 321');
result = await (resolvedIDriss &&
resolvedIDriss[resolveOptions.walletTag!] &&
resolvedIDriss[resolveOptions.walletTag!].length > 0
Expand All @@ -332,7 +335,7 @@ export abstract class BaseIdrissCrypto {
message,
transactionOptions,
));

console.log('line 338');
return result;
}

Expand Down Expand Up @@ -470,10 +473,12 @@ export abstract class BaseIdrissCrypto {
message: string,
transactionOptions: TransactionOptions,
): Promise<TransactionReceipt> {
console.log('line 476');
const paymentFee = await this.calculateTippingPaymentFee(
asset.amount,
asset.type,
);
console.log('line 481');

const maticToSend =
asset.type === AssetType.Native
Expand Down Expand Up @@ -975,6 +980,7 @@ export abstract class BaseIdrissCrypto {
assetType: AssetType,
) {
if (assetType === AssetType.ERC20) return '0';
console.log({ paymentAmount, assetType });
return this.tippingContract.callMethod({
method: {
name: 'getPaymentFee',
Expand Down Expand Up @@ -1069,6 +1075,10 @@ export abstract class BaseIdrissCrypto {
asset.assetContractAddress!,
);

console.log({ connectedAccount: this.web3Provider.getConnectedAccount() });
console.log({ arguments: [signer, contractToAuthorize] });
console.log(this.web3Provider);

const allowance = await contract.callMethod({
method: {
name: 'allowance',
Expand Down
26 changes: 11 additions & 15 deletions src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,19 @@ export class IdrissCrypto extends BaseIdrissCrypto {
return hashHex;
}

protected async getConnectedAccount(): Promise<string> {
const ethereum = this.getInjectedEthereum();

if (ethereum === undefined) {
throw new TypeError('No wallet detected.');
}

const accounts = await ethereum.request({ method: 'eth_requestAccounts' });
return accounts[0];
public async getConnectedAccount(): Promise<string> {
return this.web3Provider.getConnectedAccount();
//
// const ethereum = this.getInjectedEthereum();
//
// if (ethereum === undefined) {
// throw new TypeError('No wallet detected.');
// }
//
// const accounts = await ethereum.request({ method: 'eth_requestAccounts' });
// return accounts[0];
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
private getInjectedEthereum(): any {
// casting to any to skip error saying that ethereum does not exist in type window
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return window && (window as any).ethereum;
}
}

export {
Expand Down
2 changes: 1 addition & 1 deletion src/idrissCrypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class IdrissCrypto extends BaseIdrissCrypto {
return createHash('sha256').update(message).digest('hex');
}

protected async getConnectedAccount(): Promise<string> {
public async getConnectedAccount(): Promise<string> {
return this.web3Provider.getConnectedAccount();
}
}
2 changes: 2 additions & 0 deletions src/web3Provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ export class Web3ProviderAdapter {

return {
callMethod: async ({ method }) => {
const network = await ethersWeb3Provider.getNetwork();
console.log({ method, network });
const result = await contract.functions[method.name](
...method.args,
);
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1494,10 +1494,10 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.55.tgz#c329cbd434c42164f846b909bd6f85b5537f6240"
integrity sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==

"@types/node@^20.10.8":
version "20.10.8"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.10.8.tgz#f1e223cbde9e25696661d167a5b93a9b2a5d57c7"
integrity sha512-f8nQs3cLxbAFc00vEU59yf9UyGUftkPaLGfvbVOIDdx2i1b8epBqj2aNGyP19fiyXWvlmZ7qC1XLjAzw/OKIeA==
"@types/node@^20.11.5":
version "20.11.5"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.5.tgz#be10c622ca7fcaa3cf226cf80166abc31389d86e"
integrity sha512-g557vgQjUUfN76MZAN/dt1z3dzcUsimuysco0KeluHgrPdJXkP/XdAURgyO2W9fZWHRtRBiVKzKn8vyOAwlG+w==
dependencies:
undici-types "~5.26.4"

Expand Down

0 comments on commit 3672d01

Please sign in to comment.