Skip to content

Commit

Permalink
Merge pull request #1380 from madfish-solutions/main
Browse files Browse the repository at this point in the history
Main
  • Loading branch information
Digberi authored Sep 11, 2023
2 parents dc713ba + c5f168e commit 0c740f4
Show file tree
Hide file tree
Showing 17 changed files with 175 additions and 125 deletions.
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "quipuswap-webapp-2",
"version": "3.3.9",
"version": "3.4.0",
"private": true,
"scripts": {
"pre-build": "node -v && npm -v && yarn -v && node ./scripts/build.js",
Expand Down Expand Up @@ -29,10 +29,10 @@
"@quipuswap/tokens-whitelist": "^1.1.19",
"@sentry/react": "^7.11.1",
"@sentry/tracing": "^7.11.1",
"@taquito/beacon-wallet": "15.0.1",
"@taquito/rpc": "15.0.1",
"@taquito/taquito": "15.0.1",
"@temple-wallet/dapp": "^7.0.0",
"@taquito/beacon-wallet": "17.3.0",
"@taquito/rpc": "17.3.0",
"@taquito/taquito": "17.3.0",
"@temple-wallet/dapp": "^8.0.0",
"@tippyjs/react": "^4.2.6",
"@types/throttle-debounce": "^5.0.0",
"amplitude-js": "^8.18.2",
Expand All @@ -59,7 +59,7 @@
"os-browserify": "^0.3.0",
"path-browserify": "^1.0.1",
"process": "^0.11.10",
"quipuswap-v3-sdk": "^0.0.5",
"quipuswap-v3-sdk": "^0.0.7",
"react": "^18.1.0",
"react-countdown-hook": "^1.1.1",
"react-dom": "^18.1.0",
Expand Down Expand Up @@ -150,5 +150,8 @@
"hooks": {
"pre-commit": "yarn lint --fix && yarn tsc && yarn run build"
}
},
"resolutions": {
"@taquito/beacon-wallet/@airgap/beacon-dapp": "4.0.10"
}
}
1 change: 1 addition & 0 deletions scripts/generate-whitelisted-pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,7 @@ const MainnetWhitelistTokens: Array<WhitelistedToken> = [
];

const ITERATION_STEP = 1;
//@ts-ignore
const tezos = new TezosToolkit(new FastRpcClient(RPC_URLS[0]));

const sleep = async (ms: number) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/no-unresolved */
import { BigNumber } from 'bignumber.js';
import { sqrtPriceForTick, liquidityDeltaToTokensDelta, tickForSqrtPrice } from 'quipuswap-v3-sdk/dist/helpers/math';
import { Nat, Int } from 'quipuswap-v3-sdk/dist/types';
Expand Down
4 changes: 3 additions & 1 deletion src/modules/swap/api/blockchain/no-mediators-swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { STABLESWAP_REFERRAL } from '@config/config';
import { QUIPUSWAP_REFERRAL_CODE } from '@config/constants';
import { estimateFee } from '@shared/api';

type TTK = Parameters<typeof getTradeOpParams>[2];

export class NoMediatorsSwapBlockchainApi {
static async getSwapTransferParams(
tezos: TezosToolkit,
Expand All @@ -17,7 +19,7 @@ export class NoMediatorsSwapBlockchainApi {
return await getTradeOpParams(
trade,
accountPkh,
tezos,
tezos as unknown as TTK,
STABLESWAP_REFERRAL,
recipientPkh,
deadlineTimespan?.toNumber(),
Expand Down
10 changes: 8 additions & 2 deletions src/providers/use-dapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import {
getPreferredRpcUrl,
getTempleWalletState,
michelEncoder,
ReadOnlySigner
ReadOnlySigner,
TempleWalletWithPK
} from '@shared/helpers';
import { LastUsedConnectionKey, Nullable, QSNetwork } from '@shared/types';

Expand All @@ -32,6 +33,7 @@ export interface DAppType {
}

export function makeBasicToolkit(clientOrUrl?: RpcClientInterface | string) {
//@ts-ignore
const tezos = new TezosToolkit(clientOrUrl ?? new FastRpcClient(getPreferredRpcUrl()));
tezos.setPackerProvider(michelEncoder);

Expand Down Expand Up @@ -95,7 +97,10 @@ function useDApp() {
console.error(error);
}

const wlt = new TempleWallet(APP_NAME, lastUsedConnection === LastUsedConnectionKey.TEMPLE ? perm : null);
const wlt = new TempleWalletWithPK(
APP_NAME,
lastUsedConnection === LastUsedConnectionKey.TEMPLE ? perm : null
);

if (lastUsedConnection === LastUsedConnectionKey.TEMPLE) {
const { pkh, pk, tezos: _tezos } = await getTempleWalletState(wlt, NETWORK_ID);
Expand Down Expand Up @@ -267,6 +272,7 @@ function useDApp() {
if (!tezos?.rpc) {
throw new Error('Tezos RPC in undefined');
}
//@ts-ignore
const cloneTezosToolkit = makeBasicToolkit(tezos.rpc);
cloneTezosToolkit.setSignerProvider(new ReadOnlySigner(accountPkh, accountPublicKey));

Expand Down
1 change: 1 addition & 0 deletions src/shared/dapp/get-read-only-tezos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ReadOnlySigner } from '../helpers/readonly-signer';
const readOnlySigner = new ReadOnlySigner(READ_ONLY_SIGNER_PK, READ_ONLY_SIGNER_PK_HASH);

export const createReadOnlyTezos = (origin: TezosToolkit) => {
//@ts-ignore
const roTezos = makeBasicToolkit(origin.rpc);
roTezos.setSignerProvider(readOnlySigner);

Expand Down
4 changes: 2 additions & 2 deletions src/shared/helpers/connect-wallet/connect-beacon-wallet.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable import/order */

/* eslint-disable import/order */
import { NetworkType } from '@airgap/beacon-types';
import { BeaconWallet } from '@taquito/beacon-wallet';

Expand Down Expand Up @@ -62,6 +61,7 @@ export const connectWalletBeacon = async (forcePermission: boolean, qsNetwork: Q
await beaconWallet.requestPermissions(permissions);
}

//@ts-ignore
const tezos = makeBasicToolkit(rpcClient);
tezos.setWalletProvider(beaconWallet);
const activeAcc = await beaconWallet.client.getActiveAccount();
Expand Down
5 changes: 3 additions & 2 deletions src/shared/helpers/connect-wallet/connect-temple-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { LastUsedConnectionKey, QSNetwork } from '@shared/types';
import { getPreferredRpcUrl } from './get-preferred-rpc-url';
import { getTempleWalletState } from './get-temple-wallet-state';
import { isDefaultConnectType } from './is-default-connect-type';
import { TempleWalletWithPK } from './temple-wallet';

export const connectWalletTemple = async (forcePermission: boolean, network: QSNetwork) => {
const available = await TempleWallet.isAvailable();
Expand All @@ -20,11 +21,11 @@ export const connectWalletTemple = async (forcePermission: boolean, network: QSN
perm = await TempleWallet.getCurrentPermission();
}

const wallet = new TempleWallet(APP_NAME, perm);
const wallet = new TempleWalletWithPK(APP_NAME, perm);

if (!wallet.connected) {
const params = isDefaultConnectType(network)
? (network.id as never)
? network.id
: {
name: network.name,
rpc: getPreferredRpcUrl()
Expand Down
10 changes: 6 additions & 4 deletions src/shared/helpers/connect-wallet/get-temple-wallet-state.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { TempleWallet } from '@temple-wallet/dapp';

/* eslint-disable import/order */
import { makeBasicToolkit } from '@providers/use-dapp';
import { SupportedNetworks } from '@shared/types';

import { getPreferredRpcUrl } from './get-preferred-rpc-url';
import { ReadOnlySigner } from '../readonly-signer';
import { FastRpcClient } from '../taquito-fast-rpc';
import { getPreferredRpcUrl } from './get-preferred-rpc-url';
import { TempleWalletWithPK } from './temple-wallet';

export const getTempleWalletState = async (wallet: TempleWallet, networkId: SupportedNetworks) => {
export const getTempleWalletState = async (wallet: TempleWalletWithPK, networkId: SupportedNetworks) => {
const rpcClient = new FastRpcClient(getPreferredRpcUrl());
//@ts-ignore
const tezos = makeBasicToolkit(rpcClient);
tezos.setWalletProvider(wallet);
//@ts-ignore
tezos.setRpcProvider(rpcClient);
const pkh = wallet.connected ? await wallet.getPKH() : null;
let pk: string | null = null;
Expand Down
1 change: 1 addition & 0 deletions src/shared/helpers/connect-wallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './get-preferred-rpc-url';
export * from './get-temple-wallet-state';
export * from './michel-encoder';
export * from './is-default-connect-type';
export * from './temple-wallet';
16 changes: 16 additions & 0 deletions src/shared/helpers/connect-wallet/temple-wallet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { WalletProvider } from '@taquito/taquito';
import { TempleWallet, NotConnectedTempleWalletError, TempleDAppPermission } from '@temple-wallet/dapp';

function assertConnected(perm: TempleDAppPermission): asserts perm {
if (!perm) {
throw new NotConnectedTempleWalletError();
}
}

export class TempleWalletWithPK extends TempleWallet implements WalletProvider {
async getPK() {
assertConnected(this.permission);

return this.permission.publicKey;
}
}
9 changes: 7 additions & 2 deletions src/shared/helpers/taquito-fast-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ class NoVespaiachHttpBackend extends HttpBackend {
}
}

type THttpBackend = ConstructorParameters<typeof RpcClient>[2];

/* eslint-disable no-param-reassign */
export class FastRpcClient extends RpcClient {
refreshInterval = REFRESH_INTERVAL;
Expand All @@ -106,8 +108,11 @@ export class FastRpcClient extends RpcClient {
refreshedAt: number; // timestamp
};

constructor(url: string, chain?: string, httpBackend?: HttpBackend) {
super(url, chain, httpBackend ?? new NoVespaiachHttpBackend());
constructor(url: string, chain?: string, httpBackend?: THttpBackend) {
const _httpBackend =
httpBackend ?? (new NoVespaiachHttpBackend() as unknown as ConstructorParameters<typeof RpcClient>[2]);

super(url, chain, _httpBackend);
}

async getBlockHash(opts?: RPCOptions) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BlockResponse, OperationEntry, OperationContents, OperationContentsAndResult } from '@taquito/rpc';
import { OperationContents, OperationContentsAndResult, BlockResponse, OperationEntry } from '@taquito/rpc';

import { Nullable } from '@shared/types';

Expand Down
5 changes: 2 additions & 3 deletions src/shared/utils/confirm-operation/confirm-operation.hook.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { OperationEntry } from '@taquito/rpc';

/* eslint-disable import/order */
import { useTezos } from '@providers/use-dapp';

import { confirmOperation } from './confirm-operation.service';
import { ConfirmationSuccessToast, TransactionSendedToast } from './confirm-operation.toast';
import { OperationMessage } from './confirm-operation.types';
import { OperationMessage, OperationEntry } from './confirm-operation.types';
import { NoTezosError } from '../../errors/no-tezos.error';
import { useToasts } from '../toasts';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { OperationEntry } from '@taquito/rpc';
import { TezosToolkit } from '@taquito/taquito';

import { CONFIRM_TIMEOUT, SYNC_INTERVAL } from './confirm-operation.config';
Expand All @@ -8,7 +7,7 @@ import {
OperationRejectedError
} from './confirm-operation.errors';
import { findOperation, getOperationStatus } from './confirm-operation.helpers';
import { ConfirmOperationOptions } from './confirm-operation.types';
import { ConfirmOperationOptions, OperationEntry } from './confirm-operation.types';

export const confirmOperation = async (
tezos: TezosToolkit,
Expand All @@ -34,9 +33,11 @@ export const confirmOperation = async (

for (let i: number = fromBlockLevel ?? currentBlockLevel; i <= currentBlockLevel; i++) {
const block = i === currentBlockLevel ? currentBlock : await tezos.rpc.getBlock({ block: String(i) });
//@ts-ignore
const opEntry = findOperation(block, opHash);

const operationIsRejected = opEntry?.contents.some(
//@ts-ignore
operationContents => getOperationStatus(operationContents) === 'failed'
);

Expand All @@ -45,6 +46,7 @@ export const confirmOperation = async (
}

if (opEntry) {
//@ts-ignore
return opEntry;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OperationEntry } from '@taquito/rpc';
import { TezosToolkit } from '@taquito/taquito';

export interface ConfirmOperationOptions {
initializedAt?: number;
Expand All @@ -10,4 +10,9 @@ export interface OperationMessage {
message: string;
}

export type BlockResponse = Awaited<ReturnType<TezosToolkit['rpc']['getBlock']>>;
export type OperationEntry = BlockResponse['operations'][number][number];

export type ConfirmationToastProps = Pick<OperationEntry, 'hash'> & Partial<OperationMessage>;

export type OperationContentsOrOperationContentsAndResult = OperationEntry['contents'][number];
Loading

0 comments on commit 0c740f4

Please sign in to comment.