Deploy swap button and show address

This commit is contained in:
Oskar Thoren 2021-01-20 14:11:17 +08:00
parent 4f29bce3c2
commit adc3b65138
No known key found for this signature in database
GPG Key ID: BDB55C8C0EF29911
2 changed files with 51 additions and 5 deletions

View File

@ -25,15 +25,30 @@
<p id="accountAddress"></p>
<p id="aliceETHBalance"></p>
<p id="aliceERC20Balance"></p>
<!-- TODO: Add a button here, show erc20 token balance, etc -->
<form onSubmit="App.mint(); return false;">
<button type="submit" class="btn btn-primary">Mint</button>
<p>
<form onSubmit="App.mint(); return false;">
<button type="submit" class="btn btn-primary">Mint</button>
</form>
</p>
<p>
<form onSubmit="App.swapDeploy(); return false;">
<button type="submit" class="btn btn-primary">Swap Deploy</button>
</form>
</p>
<p>
<form onSubmit="App.swapDeposit(); return false;">
<button type="submit" class="btn btn-primary">Swap Deposit</button>
</form>
</p>
</div>
<div id="aliceSwap">
<h2>Alice Swap</h2>
<p id="aliceSwapAddress"></p>
<p id="aliceSwapBalance"></p>
</div>
<div id="bob">
<h2>Bob</h2>

View File

@ -2,6 +2,7 @@ App = {
web3Provider: null,
contracts: {},
aliceAddress: '0x0',
aliceSwapAddress: '0x0',
account: '0x0',
init: function() {
@ -58,7 +59,7 @@ App = {
initContract: function() {
// TODO Replace me
$.getJSON("ERC20PresetMinterPauser.json", function(erc20) {
console.log("Hi!");
console.log("Init ERC20PresetMinterPauser");
//console.log("Hi! ", erc20)
// Instantiate a new truffle contract from the artifact
App.contracts.ERC20PresetMinterPauser = TruffleContract(erc20);
@ -67,6 +68,17 @@ App = {
return App.render();
});
$.getJSON("SimpleSwapFactory.json", function(factory) {
console.log("Init SimpleSwapFactory");
App.contracts.SimpleSwapFactory = TruffleContract(factory);
App.contracts.SimpleSwapFactory.setProvider(App.web3Provider);
return App.render();
});
},
// NOTE: async, might want to pull some stuff out here
@ -95,13 +107,16 @@ App = {
}
})
// Show ERC20 balance
var erc20 = await App.contracts.ERC20PresetMinterPauser.deployed()
var erc20balance = await erc20.balanceOf(aliceAddress)
console.log("ERC20 Balance ", erc20balance.toNumber())
$("#aliceERC20Balance").html("ERC20 Balance: " + erc20balance.toNumber() + " TEST");
// Show Swap Balance
// XXX Should we deploy swap contract here? Easier to get address...
// Button for this?
// Load contract data
// TODO Replace me
App.contracts.ERC20PresetMinterPauser.deployed().then(function(erc20) {
@ -137,7 +152,23 @@ App = {
web3.eth.defaultAccount = web3.eth.accounts[0]
var erc20 = await App.contracts.ERC20PresetMinterPauser.deployed()
var foo = await erc20.mint(App.aliceAddress, 10000)
},
swapDeploy: async function() {
console.log("swapDeploy")
web3.eth.defaultAccount = web3.eth.accounts[0]
var DEFAULT_HARDDEPOSIT_DECREASE_TIMEOUT = 86400
var simpleSwapFactory = await App.contracts.SimpleSwapFactory.deployed()
let { logs } = await simpleSwapFactory.deploySimpleSwap(App.aliceAddress, DEFAULT_HARDDEPOSIT_DECREASE_TIMEOUT)
var aliceSwapAddress = logs[0].args.contractAddress
App.aliceSwapAddress = aliceSwapAddress
console.log("aliceSwapAddress", aliceSwapAddress)
$("#aliceSwapAddress").html("Swap Address: " + aliceSwapAddress);
}
// TODO swapDeposit function
};
$(function() {