Skip to content

Commit

Permalink
Fixed yarn 4.5.0 problems
Browse files Browse the repository at this point in the history
  • Loading branch information
BlobMaster41 committed Oct 2, 2024
1 parent a6eacda commit 154f2f7
Show file tree
Hide file tree
Showing 6 changed files with 23,475 additions and 16,960 deletions.
Binary file added .yarn/install-state.gz
Binary file not shown.
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "opwallet",
"version": "1.0.17",
"version": "1.0.18",
"private": true,
"homepage": "https://github.com/unisat-wallet/extension#readme",
"bugs": {
Expand Down Expand Up @@ -32,7 +32,7 @@
"@babel/core": "^7.16.0",
"@btc-vision/bsi-binary": "1.0.42",
"@btc-vision/passworder": "1.0.0",
"@btc-vision/transaction": "1.0.107",
"@btc-vision/transaction": "1.0.108",
"@btc-vision/wallet-sdk": "1.0.0",
"@fortawesome/fontawesome-svg-core": "^6.6.0",
"@fortawesome/free-regular-svg-icons": "^6.6.0",
Expand Down Expand Up @@ -97,8 +97,9 @@
"koa-compose": "^4.1.0",
"lodash-es": "^4.17.21",
"loglevel": "^1.8.0",
"lru-cache": "6.0.0",
"mini-css-extract-plugin": "^2.4.5",
"opnet": "1.0.57",
"opnet": "1.0.59",
"postcss": "^8.4.39",
"postcss-flexbugs-fixes": "^5.0.2",
"postcss-loader": "^6.2.1",
Expand Down
146 changes: 31 additions & 115 deletions src/ui/pages/Wallet/TxOpnetConfirmScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,26 +266,14 @@ export default function TxOpnetConfirmScreen() {
const walletGet: Wallet = Wallet.fromWif(wifWallet.wif, Web3API.network);

const wrapAmount = expandToDecimals(rawTxInfo.inputAmount, 8);
let utxos: UTXO[];
const amountRequired = wrapAmount + currentConsensusConfig.UNWRAP_CONSOLIDATION_PREPAID_FEES;

const amountRequired = wrapAmount + currentConsensusConfig.UNWRAP_CONSOLIDATION_PREPAID_FEES + 50_000n; // add fee
if (!useNextUTXO) {
utxos = await Web3API.getUTXOs(walletGet.addresses, amountRequired + 1_000_000n);
} else {
const storedUTXO = localStorage.getItem('nextUTXO');
utxos = storedUTXO
? JSON.parse(storedUTXO).map((utxo) => ({
...utxo,
value: BigInt(utxo.value)
}))
: [];
}
const account = await wallet.getCurrentAccount();
const utxos: UTXO[] = await Web3API.getUTXOs([account.address], amountRequired + 100_000n);

if (utxos.length !== 0) {
// verify if have enough

const totalAmount = utxos.reduce((acc, utxo) => acc + utxo.value, 0n);
console.log('amount', totalAmount, amountRequired, utxos);
if (totalAmount < amountRequired) {
tools.toastError(`Not enough funds to wrap. You need at least ${amountRequired} sat.`);
return;
Expand Down Expand Up @@ -363,18 +351,8 @@ export default function TxOpnetConfirmScreen() {
const walletGet: Wallet = Wallet.fromWif(wifWallet.wif, Web3API.network);
const unwrapAmount = expandToDecimals(rawTxInfo.inputAmount, 8); // Minimum amount to unwrap

let utxos: UTXO[] = [];
if (!useNextUTXO) {
utxos = await Web3API.getUTXOs(walletGet.addresses, unwrapAmount);
} else {
const storedUTXO = localStorage.getItem('nextUTXO');
utxos = storedUTXO
? JSON.parse(storedUTXO).map((utxo) => ({
...utxo,
value: BigInt(utxo.value)
}))
: [];
}
const account = await wallet.getCurrentAccount();
const utxos: UTXO[] = await Web3API.getUTXOs([account.address], unwrapAmount + 100_000n);

const contract: IWBTCContract = getContract<IWBTCContract>(
Web3API.WBTC,
Expand Down Expand Up @@ -533,18 +511,9 @@ export default function TxOpnetConfirmScreen() {
tools.toastError('Invalid calldata in stakeData');
return;
}
let utxos: UTXO[];
if (!useNextUTXO) {
utxos = await Web3API.getUTXOs(walletGet.addresses, amountToSend);
} else {
const storedUTXO = localStorage.getItem('nextUTXO');
utxos = storedUTXO
? JSON.parse(storedUTXO).map((utxo) => ({
...utxo,
value: BigInt(utxo.value)
}))
: [];
}

const account = await wallet.getCurrentAccount();
const utxos: UTXO[] = await Web3API.getUTXOs([account.address], amountToSend + 100_000n);

const interactionParameters: IInteractionParameters = {
from: walletGet.p2tr,
Expand Down Expand Up @@ -603,18 +572,8 @@ export default function TxOpnetConfirmScreen() {
return;
}

let utxos: UTXO[] = [];
if (!useNextUTXO) {
utxos = await Web3API.getUTXOs(walletGet.addresses, amountToSend);
} else {
const storedUTXO = localStorage.getItem('nextUTXO');
utxos = storedUTXO
? JSON.parse(storedUTXO).map((utxo) => ({
...utxo,
value: BigInt(utxo.value)
}))
: [];
}
const account = await wallet.getCurrentAccount();
const utxos: UTXO[] = await Web3API.getUTXOs([account.address], amountToSend + 100_000n);

const interactionParameters: IInteractionParameters = {
from: walletGet.p2tr,
Expand Down Expand Up @@ -805,18 +764,9 @@ export default function TxOpnetConfirmScreen() {
return;
}

let utxos: UTXO[];
if (!useNextUTXO) {
utxos = await Web3API.getUTXOs(walletGet.addresses, amountToSend);
} else {
const storedUTXO = localStorage.getItem('nextUTXO');
utxos = storedUTXO
? JSON.parse(storedUTXO).map((utxo) => ({
...utxo,
value: BigInt(utxo.value)
}))
: [];
}
const account = await wallet.getCurrentAccount();
const utxos: UTXO[] = await Web3API.getUTXOs([account.address], amountToSend + 100_000n);

const interactionParameters: IInteractionParameters = {
from: walletGet.p2tr,
to: contract.address.toString(),
Expand Down Expand Up @@ -869,22 +819,11 @@ export default function TxOpnetConfirmScreen() {
walletGet.p2tr
);

const maxUint256 = BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff');
const inputAmountBigInt = expandToDecimals(rawTxInfo.inputAmount[0], rawTxInfo.opneTokens[0].divisibility);
const storedUTXO = localStorage.getItem('nextUTXO');
let utxos: UTXO[] = [];

if (!useNextUTXO) {
utxos = await Web3API.getUTXOs(walletGet.addresses, maxUint256);
console.log(utxos);
} else {
utxos = storedUTXO
? JSON.parse(storedUTXO).map((utxo) => ({
...utxo,
value: BigInt(utxo.value)
}))
: [];
}
const account = await wallet.getCurrentAccount();
const utxos: UTXO[] = await Web3API.getUTXOs([account.address], 1_000_000n);

const getData = await approveToken(inputAmountBigInt, walletGet, rawTxInfo.contractAddress[0], utxos);
const getnextUtxo = await approveToken(inputAmountBigInt, walletGet, rawTxInfo.contractAddress[1], getData);
const sliipageAmount = Number(rawTxInfo.inputAmount[1]) * Number(rawTxInfo.slippageTolerance / 100);
Expand Down Expand Up @@ -913,6 +852,7 @@ export default function TxOpnetConfirmScreen() {
priorityFee: rawTxInfo.priorityFee,
calldata: contractResult as Buffer
};

const sendTransact = await Web3API.transactionFactory.signInteraction(interactionParameters);

// If this transaction is missing, opnet will deny the unwrapping request.
Expand All @@ -922,7 +862,6 @@ export default function TxOpnetConfirmScreen() {
tools.toastError('Error,Please Try again');
setUseNextUTXO(true);
setDisabled(false);
console.log(firstTransaction);
tools.toastError(firstTransaction.error || 'Could not broadcast first transaction');
}

Expand All @@ -938,6 +877,7 @@ export default function TxOpnetConfirmScreen() {
tools.toastSuccess(
`You have successfully swapped ${amountA} ${rawTxInfo.opneTokens[0].symbol} for ${amountB} ${rawTxInfo.opneTokens[1].symbol}`
);

const nextUTXO = sendTransact[2];
localStorage.setItem('nextUTXO', JSON.stringify(nextUTXO));
navigate('TxSuccessScreen', { txid: secondTransaction.result });
Expand Down Expand Up @@ -999,8 +939,6 @@ export default function TxOpnetConfirmScreen() {

const sendBTC = async () => {
try {
const account = await wallet.getCurrentAccount();

const currentNetwork = await wallet.getChainType();
Web3API.setNetwork(currentNetwork);

Expand All @@ -1011,17 +949,11 @@ export default function TxOpnetConfirmScreen() {
const wifWallet = await wallet.getInternalPrivateKey(foundObject?.account as Account);
const walletGet: Wallet = Wallet.fromWif(wifWallet.wif, Web3API.network);

const storedUTXO = localStorage.getItem('nextUTXO');
let utxos: UTXO[] = storedUTXO
? JSON.parse(storedUTXO).map((utxo) => ({
...utxo,
value: BigInt(utxo.value)
}))
: [];

if (!utxos || (utxos && utxos.length === 0) || useNextUTXO) {
utxos = await Web3API.getUTXOs([account.address], expandToDecimals(rawTxInfo.inputAmount, 8) * 2n);
}
const account = await wallet.getCurrentAccount();
const utxos: UTXO[] = await Web3API.getUTXOs(
[account.address],
expandToDecimals(rawTxInfo.inputAmount, 8) * 2n
);

const IFundingTransactionParameters: IFundingTransactionParameters = {
amount: expandToDecimals(rawTxInfo.inputAmount, 8) - 330n,
Expand Down Expand Up @@ -1068,18 +1000,8 @@ export default function TxOpnetConfirmScreen() {
const wifWallet = await wallet.getInternalPrivateKey(foundObject?.account as Account);
const walletGet: Wallet = Wallet.fromWif(wifWallet.wif, Web3API.network);

let utxos: UTXO[] = [];
if (!useNextUTXO) {
utxos = await Web3API.getUTXOs(walletGet.addresses, expandToDecimals(0.008, 8));
} else {
const storedUTXO = localStorage.getItem('nextUTXO');
utxos = storedUTXO
? JSON.parse(storedUTXO).map((utxo) => ({
...utxo,
value: BigInt(utxo.value)
}))
: [];
}
const account = await wallet.getCurrentAccount();
const utxos: UTXO[] = await Web3API.getUTXOs([account.address], 1_000_000n); // maximum fee a contract can pay

const arrayBuffer = await rawTxInfo.file.arrayBuffer();
const uint8Array = new Uint8Array(arrayBuffer);
Expand Down Expand Up @@ -1150,33 +1072,27 @@ export default function TxOpnetConfirmScreen() {
const foundObject = rawTxInfo.items.find(
(obj) => obj.account && obj.account.address === rawTxInfo.account.address
);

const wifWallet = await wallet.getInternalPrivateKey(foundObject?.account as Account);
const walletGet: Wallet = Wallet.fromWif(wifWallet.wif, Web3API.network);

let utxos: UTXO[] = [];
if (!useNextUTXO) {
utxos = await Web3API.getUTXOs(walletGet.addresses, expandToDecimals(0.08, 8));
} else {
const storedUTXO = localStorage.getItem('nextUTXO');
utxos = storedUTXO
? JSON.parse(storedUTXO).map((utxo) => ({
...utxo,
value: BigInt(utxo.value)
}))
: [];
}
const account = await wallet.getCurrentAccount();
const utxos: UTXO[] = await Web3API.getUTXOs([account.address], expandToDecimals(0.005, 8));

const contract = getContract<IOP_20Contract>(
rawTxInfo.contractAddress,
OP_20_ABI,
Web3API.provider,
walletGet.p2tr
);

const mintData = await contract.mint(walletGet.p2tr, rawTxInfo.inputAmount);
if ('error' in mintData) {
console.log(mintData);
tools.toastError('Error');
return;
}

const interactionParameters: IInteractionParameters = {
from: walletGet.p2tr,
to: contract.address.toString(),
Expand Down
3 changes: 2 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const config = (env) => {
fallback: {
vm: require.resolve('vm-browserify')
}
}
},
ignoreWarnings: [/./]
};

if (env.config) {
Expand Down
Loading

0 comments on commit 154f2f7

Please sign in to comment.