Skip to content

Commit e798d89

Browse files
authored
Merge pull request #573 from enkryptcom/prep/release
feat/release-2.0
2 parents d3eab40 + 9ec50d3 commit e798d89

46 files changed

Lines changed: 1474 additions & 530 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/extension/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# VITE_DEBUG_LOG="swap:*"
2+
VITE_DEBUG_LOG=

packages/extension/src/libs/activity-state/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class ActivityState {
6161
this.getActivityId(options),
6262
);
6363
}
64+
6465
async updateActivity(
6566
activity: Activity,
6667
options: ActivityOptions,
@@ -75,24 +76,29 @@ class ActivityState {
7576
});
7677
await this.setActivitiesById(clone, this.getActivityId(options));
7778
}
79+
7880
async setCacheTime(options: ActivityOptions): Promise<void> {
7981
await this.#storage.set(this.getActivityCacheId(options), {
8082
[STORAGE_KEY]: new Date().getTime(),
8183
});
8284
}
85+
8386
async getCacheTime(options: ActivityOptions): Promise<number> {
8487
const cacheTime: Record<string, number> = await this.#storage.get(
8588
this.getActivityCacheId(options),
8689
);
8790
if (!cacheTime || !cacheTime[STORAGE_KEY]) return 0;
8891
return cacheTime[STORAGE_KEY];
8992
}
93+
9094
async getAllActivities(options: ActivityOptions): Promise<Activity[]> {
9195
return this.getActivitiesById(this.getActivityId(options));
9296
}
97+
9398
async deleteAllActivities(options: ActivityOptions): Promise<void> {
9499
this.setActivitiesById([], this.getActivityId(options));
95100
}
101+
96102
private async setActivitiesById(
97103
activities: Activity[],
98104
id: string,
@@ -101,6 +107,7 @@ class ActivityState {
101107
[STORAGE_KEY]: activities,
102108
});
103109
}
110+
104111
private async getActivitiesById(id: string): Promise<Activity[]> {
105112
const allStates: Record<string, Activity[]> = await this.#storage.get(id);
106113
if (!allStates || !allStates[STORAGE_KEY]) return [];
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const fixedHex = (number: number, length: number) => {
2+
let str = number.toString(16).toUpperCase();
3+
while (str.length < length) str = '0' + str;
4+
return str;
5+
};
6+
7+
/* Creates a unicode literal based on the string */
8+
const unicodeLiteral = (str: string) => {
9+
let i;
10+
let result = '';
11+
for (i = 0; i < str.length; ++i) {
12+
if (str.charCodeAt(i) > 126 || str.charCodeAt(i) < 32)
13+
result += '\\u' + fixedHex(str.charCodeAt(i), 4);
14+
else result += str[i];
15+
}
16+
return result;
17+
};
18+
export const getRTLOLTLOSafeString = (str: string): string => {
19+
const dangerous = /[\u202A-\u202E\u2066-\u2069\u200E\u200F\u061C]/.test(str);
20+
if (dangerous) return unicodeLiteral(str);
21+
return str;
22+
};

packages/extension/src/providers/bitcoin/ui/btc-sign-message.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import { ProviderRequestOptions } from '@/types/provider';
6565
import { BitcoinNetwork } from '../types/bitcoin-network';
6666
import { EnkryptAccount } from '@enkryptcom/types';
6767
import { MessageSigner } from './libs/signer';
68+
import { getRTLOLTLOSafeString } from '@/libs/utils/unicode-detection';
6869
6970
const windowPromise = WindowPromiseHandler(4);
7071
const network = ref<BitcoinNetwork>(DEFAULT_BTC_NETWORK);
@@ -92,7 +93,7 @@ onBeforeMount(async () => {
9293
account.value = Request.value.params![2] as EnkryptAccount;
9394
identicon.value = network.value.identicon(account.value.address);
9495
Options.value = options;
95-
message.value = Request.value.params![0];
96+
message.value = getRTLOLTLOSafeString(Request.value.params![0]);
9697
type.value = Request.value.params![1];
9798
});
9899

packages/extension/src/providers/bitcoin/ui/send-transaction/index.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,10 @@ const isInputsValid = computed<boolean>(() => {
312312
isSendToken.value
313313
)
314314
return false;
315-
if (new BigNumber(sendAmount.value).gt(assetMaxValue.value)) return false;
315+
316+
const sendAmountBigNumber = new BigNumber(sendAmount.value)
317+
if (sendAmountBigNumber.isNaN()) return false
318+
if (sendAmountBigNumber.gt(assetMaxValue.value)) return false;
316319
return true;
317320
});
318321
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NetworkNames } from '@enkryptcom/types';
22

3-
const newNetworks = [NetworkNames.Solana];
3+
const newNetworks = [NetworkNames.Bitrock, NetworkNames.Fraxtal];
44
const newSwaps: NetworkNames[] = [];
55

66
export { newNetworks, newSwaps };

packages/extension/src/providers/common/ui/send-transaction/send-input-amount.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,16 @@ const amount = computed({
7373
7474
const onlyNumber = ($event: KeyboardEvent) => {
7575
const keyCode = $event.keyCode ? $event.keyCode : $event.which;
76-
if ((keyCode < 48 || keyCode > 57) && keyCode !== 46) {
77-
$event.preventDefault();
76+
// Numeric
77+
if (keyCode >= /* 0 */ 48 && keyCode <= /* 9 */ 57) {
78+
return;
7879
}
80+
// Only allow a single period
81+
if (keyCode === /* '.' */ 46 && amount.value.indexOf('.') === -1) {
82+
return;
83+
}
84+
// Alphabetical (/non-numeric) or mulitple periods. Don't propagate change
85+
$event.preventDefault();
7986
};
8087
const changeFocus = () => {
8188
isFocus.value = !isFocus.value;

packages/extension/src/providers/ethereum/libs/transaction/gas-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const getGasBasedOnType = (
6262
}
6363
};
6464
const getMinPriorityFee = (): BNType => {
65-
return toBN(toWei('0.1', 'gwei'));
65+
return toBN(toWei('1', 'gwei'));
6666
};
6767
const getPriorityFeeAvg = (arr: BNType[]): BNType => {
6868
const sum = arr.reduce((a, v) => a.add(v));

packages/extension/src/providers/ethereum/libs/transaction/index.ts

Lines changed: 67 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@ class Transaction {
3838
value: this.tx.value || '0x0',
3939
});
4040
}
41-
async getOPfees(): Promise<BNType> {
41+
async getOPfees(
42+
fTx: LegacyTransaction | FeeMarketEIP1559Transaction,
43+
): Promise<BNType> {
4244
const OPContract = new this.web3.Contract(
4345
OPTIMISM_PRICE_ORACLE_ABI as any,
4446
OPTIMISM_PRICE_ORACLE,
4547
);
46-
const fTx = await this.getFinalizedTransaction({
47-
gasPriceType: GasPriceTypes.ECONOMY,
48-
});
4948
const serializedTx = fTx.serialize();
5049
return OPContract.methods
5150
.getL1Fee(bufferToHex(serializedTx))
@@ -87,6 +86,7 @@ class Transaction {
8786
maxFeePerGas?: string;
8887
gasLimit: string;
8988
formattedFeeHistory?: FormattedFeeHistory;
89+
finalizedTransaction: LegacyTransaction | FeeMarketEIP1559Transaction;
9090
}> {
9191
const latestBlock = await this.web3.getBlock('latest', false);
9292
const { isFeeMarketNetwork, feeHistory } = await this.web3
@@ -123,10 +123,20 @@ class Transaction {
123123
nonce: this.tx.nonce || (numberToHex(nonce) as `0x${string}`),
124124
value: this.tx.value || '0x0',
125125
};
126+
const common = Common.custom({
127+
chainId: BigInt(this.tx.chainId),
128+
});
129+
const finalizedTransaction = LegacyTransaction.fromTxData(
130+
legacyTx as FinalizedLegacyEthereumTransaction,
131+
{
132+
common,
133+
},
134+
);
126135
return {
127136
transaction: legacyTx,
128137
gasPrice: gasPrice,
129138
gasLimit: legacyTx.gasLimit,
139+
finalizedTransaction,
130140
};
131141
} else {
132142
// Fee market transaction (post EIP1559)
@@ -141,7 +151,7 @@ class Transaction {
141151
const gasLimit =
142152
this.tx.gasLimit ||
143153
(numberToHex(await this.estimateGas()) as `0x${string}`);
144-
const maxFeePerGas = !options.totalGasPrice
154+
let maxFeePerGas = !options.totalGasPrice
145155
? feeMarket.maxFeePerGas
146156
: options.totalGasPrice.div(toBN(gasLimit));
147157
const maxPriorityFeePerGas = feeMarket.maxPriorityFeePerGas;
@@ -162,13 +172,43 @@ class Transaction {
162172
type: '0x02',
163173
accessList: this.tx.accessList || [],
164174
};
175+
const common = Common.custom({
176+
chainId: BigInt(this.tx.chainId),
177+
defaultHardfork: Hardfork.London,
178+
});
179+
let finalizedTransaction = FeeMarketEIP1559Transaction.fromTxData(
180+
feeMarketTx as FinalizedFeeMarketEthereumTransaction,
181+
{
182+
common,
183+
},
184+
);
185+
if (options.totalGasPrice) {
186+
const opFee = await this.getOPfees(finalizedTransaction);
187+
if (opFee.gtn(0)) {
188+
const gasFeeWithoutOPFee = options.totalGasPrice.sub(opFee);
189+
maxFeePerGas = gasFeeWithoutOPFee.div(toBN(gasLimit));
190+
feeMarketTx.maxFeePerGas = numberToHex(maxFeePerGas) as `0x${string}`;
191+
feeMarketTx.maxPriorityFeePerGas = numberToHex(
192+
maxPriorityFeePerGas.gt(maxFeePerGas)
193+
? maxFeePerGas
194+
: maxPriorityFeePerGas,
195+
) as `0x${string}`;
196+
finalizedTransaction = FeeMarketEIP1559Transaction.fromTxData(
197+
feeMarketTx as FinalizedFeeMarketEthereumTransaction,
198+
{
199+
common,
200+
},
201+
);
202+
}
203+
}
165204
return {
166205
transaction: feeMarketTx,
167206
gasLimit: feeMarketTx.gasLimit,
168207
baseFeePerGas: numberToHex(baseFeePerGas!),
169208
maxFeePerGas: numberToHex(feeMarket.maxFeePerGas),
170209
maxPriorityFeePerGas: numberToHex(feeMarket.maxPriorityFeePerGas),
171210
formattedFeeHistory,
211+
finalizedTransaction,
172212
};
173213
}
174214
}
@@ -182,30 +222,8 @@ class Transaction {
182222
async getFinalizedTransaction(
183223
options: TransactionOptions,
184224
): Promise<LegacyTransaction | FeeMarketEIP1559Transaction> {
185-
const { transaction } = await this.finalizeTransaction(options);
186-
187-
if (!transaction.maxFeePerGas) {
188-
const common = Common.custom({
189-
chainId: BigInt(transaction.chainId),
190-
});
191-
return LegacyTransaction.fromTxData(
192-
transaction as FinalizedLegacyEthereumTransaction,
193-
{
194-
common,
195-
},
196-
);
197-
} else {
198-
const common = Common.custom({
199-
chainId: BigInt(transaction.chainId),
200-
defaultHardfork: Hardfork.London,
201-
});
202-
return FeeMarketEIP1559Transaction.fromTxData(
203-
transaction as FinalizedFeeMarketEthereumTransaction,
204-
{
205-
common,
206-
},
207-
);
208-
}
225+
const { finalizedTransaction } = await this.finalizeTransaction(options);
226+
return finalizedTransaction;
209227
}
210228

211229
async getMessageToSign(options: TransactionOptions): Promise<Uint8Array> {
@@ -214,35 +232,38 @@ class Transaction {
214232
}
215233

216234
async getGasCosts(): Promise<GasCosts> {
217-
const { gasLimit, gasPrice, baseFeePerGas, formattedFeeHistory } =
218-
await this.finalizeTransaction({
219-
gasPriceType: GasPriceTypes.ECONOMY,
220-
});
221-
const opFee = await this.getOPfees();
235+
const {
236+
gasLimit,
237+
gasPrice,
238+
baseFeePerGas,
239+
formattedFeeHistory,
240+
finalizedTransaction,
241+
} = await this.finalizeTransaction({
242+
gasPriceType: GasPriceTypes.ECONOMY,
243+
});
222244
if (gasPrice) {
223245
return {
224246
[GasPriceTypes.ECONOMY]: numberToHex(
225-
getGasBasedOnType(gasPrice, GasPriceTypes.ECONOMY)
226-
.mul(toBN(gasLimit))
227-
.add(opFee),
247+
getGasBasedOnType(gasPrice, GasPriceTypes.ECONOMY).mul(
248+
toBN(gasLimit),
249+
),
228250
),
229251
[GasPriceTypes.REGULAR]: numberToHex(
230-
getGasBasedOnType(gasPrice, GasPriceTypes.REGULAR)
231-
.mul(toBN(gasLimit))
232-
.add(opFee),
252+
getGasBasedOnType(gasPrice, GasPriceTypes.REGULAR).mul(
253+
toBN(gasLimit),
254+
),
233255
),
234256
[GasPriceTypes.FAST]: numberToHex(
235-
getGasBasedOnType(gasPrice, GasPriceTypes.FAST)
236-
.mul(toBN(gasLimit))
237-
.add(opFee),
257+
getGasBasedOnType(gasPrice, GasPriceTypes.FAST).mul(toBN(gasLimit)),
238258
),
239259
[GasPriceTypes.FASTEST]: numberToHex(
240-
getGasBasedOnType(gasPrice, GasPriceTypes.FASTEST)
241-
.mul(toBN(gasLimit))
242-
.add(opFee),
260+
getGasBasedOnType(gasPrice, GasPriceTypes.FASTEST).mul(
261+
toBN(gasLimit),
262+
),
243263
),
244264
};
245265
} else {
266+
const opFee = await this.getOPfees(finalizedTransaction);
246267
return {
247268
[GasPriceTypes.ECONOMY]: numberToHex(
248269
this.getFeeMarketGasInfo(

packages/extension/src/providers/ethereum/networks/maticzk.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ const maticOptions: EvmNetworkOptions = {
1414
blockExplorerAddr: 'https://zkevm.polygonscan.com/address/[[address]]',
1515
chainID: '0x44d',
1616
isTestNetwork: false,
17-
currencyName: 'POL',
18-
currencyNameLong: 'Polygon POL',
17+
currencyName: 'ETH',
18+
currencyNameLong: 'Ethereum',
1919
node: 'wss://nodes.mewapi.io/ws/maticzk',
2020
icon,
21-
coingeckoID: 'polygon-ecosystem-token',
21+
coingeckoID: 'ethereum',
2222
coingeckoPlatform: CoingeckoPlatform.MaticZK,
2323
NFTHandler: shNFTHandler,
2424
assetsInfoHandler,

0 commit comments

Comments
 (0)