-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy path3316.15388a52.iframe.bundle.js
1 lines (1 loc) · 11.5 KB
/
3316.15388a52.iframe.bundle.js
1
"use strict";(globalThis.webpackChunkmetamask_crx=globalThis.webpackChunkmetamask_crx||[]).push([[3316],{"./ui/helpers/utils/notification.util.ts":(__unused_webpack_module,__webpack_exports__,__webpack_require__)=>{__webpack_require__.d(__webpack_exports__,{_d:()=>createTextItems,ej:()=>formatAmount,aD:()=>formatIsoDateString,_J:()=>formatMenuItemDate,fE:()=>getAmount,qP:()=>getNetworkDetailsByChainId,sk:()=>getNetworkFees,VP:()=>getRandomKey,Rs:()=>getUsdAmount,IT:()=>isIpfsURL});var _obj,bignumber=__webpack_require__("./node_modules/bignumber.js/bignumber.js"),json_rpc_provider=__webpack_require__("./node_modules/@ethersproject/providers/lib.esm/json-rpc-provider.js"),network=__webpack_require__("./shared/constants/network.ts");function _define_property(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}var SUPPORTED_NOTIFICATION_BLOCK_EXPLORERS=(_define_property(_obj={},network.tx.MAINNET,{url:"https://etherscan.io",name:"Etherscan"}),_define_property(_obj,network.tx.OPTIMISM,{url:"https://optimistic.etherscan.io",name:"Optimistic Etherscan"}),_define_property(_obj,network.tx.BSC,{url:"https://bscscan.com",name:"BscScan"}),_define_property(_obj,network.tx.POLYGON,{url:"https://polygonscan.com",name:"PolygonScan"}),_define_property(_obj,network.tx.ARBITRUM,{url:"https://arbiscan.io",name:"Arbiscan"}),_define_property(_obj,network.tx.AVALANCHE,{url:"https://snowtrace.io",name:"Snowtrace"}),_define_property(_obj,network.tx.LINEA_MAINNET,{url:"https://lineascan.build",name:"LineaScan"}),_obj),transactions_controller_utils=__webpack_require__("./shared/lib/transactions-controller-utils.js"),conversion_utils=__webpack_require__("./shared/modules/conversion.utils.ts");function _array_like_to_array(arr,len){(null==len||len>arr.length)&&(len=arr.length);for(var i=0,arr2=Array(len);i<len;i++)arr2[i]=arr[i];return arr2}function _array_with_holes(arr){if(Array.isArray(arr))return arr}function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg),value=info.value}catch(error){reject(error);return}info.done?resolve(value):Promise.resolve(value).then(_next,_throw)}function _async_to_generator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value)}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err)}_next(void 0)})}}function notification_util_define_property(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}function _iterable_to_array_limit(arr,i){var _s,_e,_i=null==arr?null:"undefined"!=typeof Symbol&&arr[Symbol.iterator]||arr["@@iterator"];if(null!=_i){var _arr=[],_n=!0,_d=!1;try{for(_i=_i.call(arr);!(_n=(_s=_i.next()).done)&&(_arr.push(_s.value),!i||_arr.length!==i);_n=!0);}catch(err){_d=!0,_e=err}finally{try{_n||null==_i.return||_i.return()}finally{if(_d)throw _e}}return _arr}}function _non_iterable_rest(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=null!=arguments[i]?arguments[i]:{},ownKeys=Object.keys(source);"function"==typeof Object.getOwnPropertySymbols&&(ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))),ownKeys.forEach(function(key){notification_util_define_property(target,key,source[key])})}return target}function _sliced_to_array(arr,i){return _array_with_holes(arr)||_iterable_to_array_limit(arr,i)||_unsupported_iterable_to_array(arr,i)||_non_iterable_rest()}function _unsupported_iterable_to_array(o,minLen){if(o){if("string"==typeof o)return _array_like_to_array(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if("Object"===n&&o.constructor&&(n=o.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _array_like_to_array(o,minLen)}}function _ts_generator(thisArg,body){var f,y,t,g,_={label:0,sent:function(){if(1&t[0])throw t[1];return t[1]},trys:[],ops:[]};return g={next:verb(0),throw:verb(1),return:verb(2)},"function"==typeof Symbol&&(g[Symbol.iterator]=function(){return this}),g;function verb(n){return function(v){return step([n,v])}}function step(op){if(f)throw TypeError("Generator is already executing.");for(;_;)try{if(f=1,y&&(t=2&op[0]?y.return:op[0]?y.throw||((t=y.return)&&t.call(y),0):y.next)&&!(t=t.call(y,op[1])).done)return t;switch(y=0,t&&(op=[2&op[0],t.value]),op[0]){case 0:case 1:t=op;break;case 4:return _.label++,{value:op[1],done:!1};case 5:_.label++,y=op[1],op=[0];continue;case 7:op=_.ops.pop(),_.trys.pop();continue;default:if(!(t=(t=_.trys).length>0&&t[t.length-1])&&(6===op[0]||2===op[0])){_=0;continue}if(3===op[0]&&(!t||op[1]>t[0]&&op[1]<t[3])){_.label=op[1];break}if(6===op[0]&&_.label<t[1]){_.label=t[1],t=op;break}if(t&&_.label<t[2]){_.label=t[2],_.ops.push(op);break}t[2]&&_.ops.pop(),_.trys.pop();continue}op=body.call(thisArg,_)}catch(e){op=[6,e],y=0}finally{f=t=0}if(5&op[0])throw op[1];return{value:op[0]?op[1]:void 0,done:!0}}}function isKey(object,key){return key in object}var isSameDay=function(currentDate,dateToCheck){return currentDate.getFullYear()===dateToCheck.getFullYear()&¤tDate.getMonth()===dateToCheck.getMonth()&¤tDate.getDate()===dateToCheck.getDate()},isYesterday=function(currentDate,dateToCheck){var yesterday=new Date(currentDate);return yesterday.setDate(currentDate.getDate()-1),isSameDay(yesterday,dateToCheck)};function formatMenuItemDate(date){var currentDate=new Date;return isSameDay(currentDate,date)?new Intl.DateTimeFormat("en",{hour:"numeric",minute:"numeric",hour12:!1}).format(date):isYesterday(currentDate,date)?new Intl.RelativeTimeFormat("en",{numeric:"auto"}).format(-1,"day"):currentDate.getFullYear()===date.getFullYear()?new Intl.DateTimeFormat("en",{month:"short",day:"numeric"}).format(date):new Intl.DateTimeFormat("en",{year:"numeric",month:"short",day:"numeric"}).format(date)}var defaultFormatOptions={decimalPlaces:4},getLeadingZeroCount=function(num){var _fractionalPart_match_,_fractionalPart_match,_numToString_split_;return(null===(_fractionalPart_match=(null!==(_numToString_split_=new bignumber.BigNumber(num,10).toString(10).split(".")[1])&&void 0!==_numToString_split_?_numToString_split_:"").match(RegExp("^0*","u")))||void 0===_fractionalPart_match?void 0:null===(_fractionalPart_match_=_fractionalPart_match[0])||void 0===_fractionalPart_match_?void 0:_fractionalPart_match_.length)||0},formatAmount=function(numericAmount,opts){var options=_object_spread({},defaultFormatOptions,opts),leadingZeros=getLeadingZeroCount(numericAmount),isDecimal=numericAmount.toString().includes(".")||leadingZeros>0||numericAmount.toString().includes("e-");if(numericAmount>999)return Intl.NumberFormat("en-US",{notation:"compact",compactDisplay:"short",maximumFractionDigits:2}).format(numericAmount);if(isDecimal){var decimalPlaces,ellipse=(decimalPlaces=options.decimalPlaces,!!(null==options?void 0:options.shouldEllipse)&&leadingZeros>=decimalPlaces),formattedValue=Intl.NumberFormat("en-US",{minimumFractionDigits:ellipse?options.decimalPlaces:void 0,maximumFractionDigits:options.decimalPlaces}).format(numericAmount);return ellipse?"".concat(formattedValue,"..."):formattedValue}return numericAmount.toString()},getRandomKey=function(text,index){return"".concat(text.replace(RegExp("\\s+","gu"),"_").replace(RegExp("[^\\w-]","gu"),""),"-").concat(index,"-").concat(Math.random().toString(36).substring(2,15))},createTextItems=function(texts,variant){return{items:texts.map(function(text,index){return{text:text,highlighted:index%2==1}}),variant:variant}},getAmount=function(amount,decimals,options){return amount&&decimals?formatAmount((0,transactions_controller_utils.dU)(amount,parseFloat(decimals)).toNumber(),options):""},getUsdAmount=function(amount,decimals,usd){if(!amount||!decimals||!usd)return"";var amountInEther=(0,transactions_controller_utils.dU)(amount,parseFloat(decimals)).toNumber();return formatAmount(parseFloat("".concat(amountInEther))*parseFloat(usd))};function getNetworkDetailsByChainId(chainId){var _NETWORK_TO_NAME_MAP_chainId,_fullNativeCurrencyName_split_;return{nativeCurrencyName:null!==(_fullNativeCurrencyName_split_=(null!==(_NETWORK_TO_NAME_MAP_chainId=network.qJ[chainId])&&void 0!==_NETWORK_TO_NAME_MAP_chainId?_NETWORK_TO_NAME_MAP_chainId:"").split(" ")[0])&&void 0!==_fullNativeCurrencyName_split_?_fullNativeCurrencyName_split_:"",nativeCurrencySymbol:network.Ow[chainId],nativeCurrencyLogo:network.Cl[chainId],nativeCurrencyAddress:"0x0000000000000000000000000000000000000000",blockExplorerConfig:chainId&&isKey(SUPPORTED_NOTIFICATION_BLOCK_EXPLORERS,chainId)?SUPPORTED_NOTIFICATION_BLOCK_EXPLORERS[chainId]:void 0}}function formatIsoDateString(isoDateString){var date=new Date(isoDateString);return new Intl.DateTimeFormat("en-US",{year:"numeric",month:"short",day:"numeric",hour:"numeric",minute:"numeric",hour12:!0}).format(date)}function getRpcUrlByChainId(chainId){var rpc=network.Kq.find(function(rpcItem){return rpcItem.chainId===chainId});if(rpc)return rpc.rpcEndpoints[0].url;switch(chainId){case network.tx.MAINNET:return network.JG;case network.tx.GOERLI:return network.pe;case network.tx.SEPOLIA:return network.O;case network.tx.LINEA_GOERLI:return network.Pg;case network.tx.LINEA_SEPOLIA:return network.oO;case network.tx.LINEA_MAINNET:return network.ju;case network.tx.LOCALHOST:return network.Yv;default:return network.JG}}function hasNetworkFeeFields(notification){return"network_fee"in notification.data}var getNetworkFees=function(){var _ref=_async_to_generator(function(notification){var chainId,connection,provider,_ref,receipt,transaction,block,transactionFeeInEth,transactionFeeInUsd,gasLimit,gasUsed,error;return _ts_generator(this,function(_state){switch(_state.label){case 0:if(!hasNetworkFeeFields(notification))throw Error("Invalid notification type");chainId=(0,conversion_utils.Ao)(notification.chain_id),connection={url:getRpcUrlByChainId("0x".concat(chainId)),headers:void 0},provider=new json_rpc_provider.F(connection),_state.label=1;case 1:return _state.trys.push([1,3,,4]),[4,Promise.all([provider.getTransactionReceipt(notification.tx_hash),provider.getTransaction(notification.tx_hash),provider.getBlock(notification.block_number)])];case 2:return receipt=(_ref=_sliced_to_array.apply(void 0,[_state.sent(),3]))[0],transaction=_ref[1],block=_ref[2],transactionFeeInUsd=formatAmount(parseFloat(transactionFeeInEth=(0,conversion_utils.ZF)(receipt.gasUsed.mul(receipt.effectiveGasPrice)._hex))*parseFloat(notification.data.network_fee.native_token_price_in_usd),{decimalPlaces:4}),gasLimit=transaction.gasLimit.toNumber(),gasUsed=receipt.gasUsed.toNumber(),[2,{transactionFeeInEth:transactionFeeInEth,transactionFeeInUsd:transactionFeeInUsd,gasLimit:gasLimit,gasUsed:gasUsed,baseFee:block.baseFeePerGas?(0,conversion_utils.kZ)(block.baseFeePerGas._hex):null,priorityFee:block.baseFeePerGas?(0,conversion_utils.kZ)(receipt.effectiveGasPrice.sub(block.baseFeePerGas)._hex):null,maxFeePerGas:transaction.maxFeePerGas?(0,conversion_utils.kZ)(transaction.maxFeePerGas._hex):null}];case 3:throw error=_state.sent(),Error("Error fetching network fees for chainId ".concat(chainId,": ").concat(error));case 4:return[2]}})});return function getNetworkFees(notification){return _ref.apply(this,arguments)}}(),isIpfsURL=function(url){return url.startsWith("ipfs://")}}}]);