mirror of
https://github.com/AthanorLabs/atomic-swap.git
synced 2026-01-09 14:18:03 -05:00
ui: devnet setup script and show errors in the UI (#99)
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -50,4 +50,5 @@ Cargo.lock
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/go,rust
|
||||
|
||||
*.key
|
||||
*.key
|
||||
log
|
||||
@@ -1,35 +1,52 @@
|
||||
#!/bin/bash
|
||||
|
||||
# useful dir relative to this script
|
||||
MONERO_DIR="../monero-x86_64-linux-gnu-v0.17.3.0"
|
||||
# either a TMPDIR is set, or use /tmp
|
||||
LOG_DIR=${TMPDIR:-"/tmp"}
|
||||
ALICE_P2P_ADDRESS="12D3KooWF5dTdfrVv6oFwGGGyobfxtZBVhVR654wt5ED6PU1SBqd"
|
||||
|
||||
# bash ./scripts/install-monero-linux.sh
|
||||
echo "========== start ganache-cli"
|
||||
ganache-cli -d &
|
||||
echo "cleanup"
|
||||
pkill -e -f monero;
|
||||
pkill -e -f ganache-cli;
|
||||
killall -v swapd;
|
||||
pkill -e -f swapcli;
|
||||
|
||||
echo "========== move to $MONERO_DIR"
|
||||
echo "start ganache-cli"
|
||||
ganache-cli -d &> $LOG_DIR/ganache-cli.log &
|
||||
|
||||
echo "move to $MONERO_DIR"
|
||||
cd $MONERO_DIR
|
||||
|
||||
echo "========== starting monerod..."
|
||||
./monerod --regtest --fixed-difficulty=1 --rpc-bind-port 18081 --offline &
|
||||
echo "starting monerod..."
|
||||
./monerod --regtest --detach --fixed-difficulty=1 --rpc-bind-port 18081 --offline &> $LOG_DIR/monerod.log &
|
||||
|
||||
echo "Zzz... 10s"
|
||||
sleep 10
|
||||
|
||||
echo "mine blocks for Bob"
|
||||
curl -X POST http://127.0.0.1:18081/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"generateblocks","params":{"wallet_address":"45GcPCBQgCG3tYcYqLdj4iQixpDZYw1MGew4PH1rthp9X2YrB2c2dty1r7SwhbCXw1RJMvfy8cW1UXyeESTAuLkV5bTrZRe","amount_of_blocks":100}' -H 'Content-Type: application/json' &> $LOG_DIR/block-mining-bob.log &
|
||||
|
||||
echo "Zzz... 15s"
|
||||
sleep 15
|
||||
|
||||
echo "========== mine blocks for Bob"
|
||||
curl -X POST http://127.0.0.1:18081/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"generateblocks","params":{"wallet_address":"45GcPCBQgCG3tYcYqLdj4iQixpDZYw1MGew4PH1rthp9X2YrB2c2dty1r7SwhbCXw1RJMvfy8cW1UXyeESTAuLkV5bTrZRe","amount_of_blocks":100}' -H 'Content-Type: application/json'
|
||||
echo "start monero-wallet-rpc for Alice on port 18084"
|
||||
./monero-wallet-rpc --rpc-bind-port 18084 --password "" --disable-rpc-login --wallet-dir . &> $LOG_DIR/alice-wallet-rpc.log &
|
||||
|
||||
echo "========== start monero-wallet-rpc for Alice on port 18084"
|
||||
./monero-wallet-rpc --rpc-bind-port 18084 --password "" --disable-rpc-login --wallet-dir . &
|
||||
|
||||
echo "========== start monero-wallet-rpc for Bob on port 18083"
|
||||
./monero-wallet-rpc --rpc-bind-port 18083 --password "" --disable-rpc-login --wallet-dir . &
|
||||
|
||||
echo "========== go back to root"
|
||||
cd ..
|
||||
echo "start monero-wallet-rpc for Bob on port 18083"
|
||||
./monero-wallet-rpc --rpc-bind-port 18083 --password "" --disable-rpc-login --wallet-dir . &> $LOG_DIR/bob-wallet-rpc.log &
|
||||
|
||||
echo "launch Alice swapd"
|
||||
./swapd --dev-alice &
|
||||
../swapd --dev-alice &> $LOG_DIR/alice-swapd.log &
|
||||
|
||||
echo "Zzz... 10s"
|
||||
sleep 10
|
||||
|
||||
echo "launch Bob swapd"
|
||||
./swapd --dev-bob --wallet-file Bob --bootnodes /ip4/127.0.0.1/tcp/9933/p2p/12D3KooWFUEQpGHQ3PtypLvgnWc5XjrqM2zyvdrZXin4vTpQ6QE5 &
|
||||
../swapd --dev-bob --wallet-file Bob --bootnodes /ip4/127.0.0.1/tcp/9933/p2p/$ALICE_P2P_ADDRESS &> $LOG_DIR/bob-swapd.log &
|
||||
|
||||
echo "Zzz... 10s"
|
||||
sleep 10
|
||||
|
||||
echo "let Bob make an offer"
|
||||
./swapcli make --min-amount 0.1 --max-amount 1 --exchange-rate 0.05 --daemon-addr=http://localhost:5002
|
||||
../swapcli make --min-amount 0.1 --max-amount 1 --exchange-rate 0.05 --daemon-addr=http://localhost:5002
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
let isSuccess = false
|
||||
let isLoadingSwap = false
|
||||
let error = ''
|
||||
let swapError = ''
|
||||
|
||||
$: willReceive =
|
||||
amountProvided && amountProvided > 0 && $selectedOffer?.exchangeRate
|
||||
@@ -42,8 +43,6 @@
|
||||
error = ''
|
||||
}
|
||||
|
||||
$: console.log('isSuccess', isSuccess)
|
||||
|
||||
const handleSendTakeOffer = () => {
|
||||
isLoadingSwap = true
|
||||
rpcRequest<NetTakeOfferSyncResult | undefined>('net_takeOfferSync', {
|
||||
@@ -55,17 +54,26 @@
|
||||
if (result?.status === 'success') {
|
||||
isSuccess = true
|
||||
getPeers()
|
||||
} else if (result?.status === 'aborted') {
|
||||
swapError = 'Something went wrong. Please check your node logs'
|
||||
} else if (result?.status === 'refunded') {
|
||||
swapError =
|
||||
'Something went wrong. Swap funds refunded, please check the logs for more info'
|
||||
}
|
||||
})
|
||||
.catch(console.error)
|
||||
.catch((e: Error) => {
|
||||
console.error('error when swapping', e)
|
||||
swapError = e.message
|
||||
})
|
||||
.finally(() => (isLoadingSwap = false))
|
||||
}
|
||||
|
||||
const onReset = () => {
|
||||
selectedOffer.set(undefined)
|
||||
const onReset = (resetOffer = true) => {
|
||||
resetOffer && selectedOffer.set(undefined)
|
||||
amountProvided = 0
|
||||
willReceive = 0
|
||||
isSuccess = false
|
||||
swapError = ''
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -73,7 +81,7 @@
|
||||
<Dialog
|
||||
open={true}
|
||||
on:SMUIDialog:action={() => console.log('action')}
|
||||
on:SMUIDialog:closed={onReset}
|
||||
on:SMUIDialog:closed={() => onReset(true)}
|
||||
aria-labelledby="mandatory-title"
|
||||
aria-describedby="mandatory-content"
|
||||
>
|
||||
@@ -94,11 +102,18 @@
|
||||
</div>
|
||||
{:else if isSuccess}
|
||||
<div class="flexBox">
|
||||
<span class="material-icons circleCheck"> check_circle </span>
|
||||
<span class="material-icons circleCheck">check_circle</span>
|
||||
<p class="successMessage">
|
||||
Yay, you received {willReceive}{$selectedOffer.provides}
|
||||
</p>
|
||||
</div>
|
||||
{:else if !!swapError}
|
||||
<div class="flexBox">
|
||||
<span class="material-icons circleCross">error_outline</span>
|
||||
<p class="errorMessage">
|
||||
{swapError}
|
||||
</p>
|
||||
</div>
|
||||
{:else}
|
||||
<Textfield
|
||||
bind:value={amountProvided}
|
||||
@@ -125,6 +140,10 @@
|
||||
<Label>Done</Label>
|
||||
</Button>
|
||||
</Actions>
|
||||
{:else if !!swapError}
|
||||
<Button on:click={() => onReset(false)}>
|
||||
<Label>Back</Label>
|
||||
</Button>
|
||||
{:else}
|
||||
<Button
|
||||
on:click={handleSendTakeOffer}
|
||||
@@ -161,6 +180,11 @@
|
||||
color: darkcyan;
|
||||
}
|
||||
|
||||
.circleCross {
|
||||
font-size: 45px;
|
||||
color: var(--mdc-theme-error, #b00020);
|
||||
}
|
||||
|
||||
* :global(.swapIcon) {
|
||||
margin-top: 1rem;
|
||||
margin-bottom: 1rem;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
export type NetTakeOfferSyncResult = {
|
||||
status: 'success' | 'failed'
|
||||
status: 'success' | 'aborted' | 'refunded'
|
||||
id: number
|
||||
}
|
||||
Reference in New Issue
Block a user