Skip to content

Commit

Permalink
some fixes and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
pau121 committed Mar 9, 2023
1 parent 2c32209 commit 3714611
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 31 deletions.
14 changes: 13 additions & 1 deletion src/components/TransactionComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export default class extends Vue {
}
const events = this.tx.events;
let numInfusionCrownEvents = 0
for (let i = 0; i < events.length; ++i) {
const ev = events[i];
switch (ev.kind) {
Expand Down Expand Up @@ -457,6 +458,9 @@ export default class extends Vue {
const data = getInfusionEventData(ev.data);
// if (ev.address == this.address) {
{
if (data.baseSymbol == "CROWN")
++numInfusionCrownEvents;
const nftId = data.TokenID;
if (state.isNFT(data.InfusedSymbol)) {
res.push({
Expand Down Expand Up @@ -503,6 +507,14 @@ export default class extends Vue {
}];
}
if (numInfusionCrownEvents > 50) {
res = [{
icon: "mdi-crown",
iconColor: "green",
text: "CROWN distribution"
}];
}
const numEvents = res.length;
if (res.length > 100) {
Expand Down Expand Up @@ -556,7 +568,7 @@ export default class extends Vue {
const item = nfts[symbol + "@" + nftId];
if (item && item.infusion) {
return item.infusion
.map((i: any) => state.formatBalance(i.Key, i.Value))
.map((i: any) => state.formatBalance(i.key ?? i.Key ?? '', i.value ?? i.Value ?? ''))
.join("<br/>");
}
return "";
Expand Down
8 changes: 5 additions & 3 deletions src/phan-js/rpc/phantasma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ export interface Swap {
}

export interface KeyValue {
Key: string;
Value: string;
key: string;
value: string;
}

export interface NFT {
Expand Down Expand Up @@ -670,7 +670,9 @@ export class PhantasmaAPI {
//Returns platform swaps for a specific address.
async getSwapsForAddress(account: string, platform: string): Promise<Swap[]> {
let params: Array<any> = [account, platform, false];
return (await this.JSONRPC("getSwapsForAddress", params)) as Swap[];
const res = (await this.JSONRPC("getSwapsForAddress", params));
if (res.error) return [];
return res as Swap[]
}


Expand Down
60 changes: 41 additions & 19 deletions src/popup/PopupState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,20 @@ export class PopupState {
if (!txdata) return null;
if (txdata.state == 'Fault') {
if (txdata.events) {
const errEv = txdata.events.find(e => e.kind == 'ExecutionFailure')
const errEv = txdata.events.find(e => e.kind == 'ExecutionFailure')
if (errEv) {

let errMsg = `Execution failure in ${errEv.contract} contract`
const data = errEv.data
if (data) {
try {
var hex = data.substring(2);
var str = '';
for (var i = 0; i < hex.length; i += 2)
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
errMsg = str
} catch {}
}
if (errEv?.contract == 'stake') {
errMsg += '. (Note: there is a 24h cooldown period after staking or claiming KCAL)'
}
Expand Down Expand Up @@ -763,7 +774,9 @@ export class PopupState {
console.log("neoBals", this.neoBalances);
let neoSwaps = await this.api.getSwapsForAddress(neoAddress, 'neo');
console.log("neoSwaps", neoSwaps);
neoSwaps = neoSwaps.filter((s) => s.destinationHash === "pending");
if (neoSwaps) {
neoSwaps = neoSwaps.filter((s) => s.destinationHash === "pending");
}
console.log("neoSwaps", neoSwaps);
if (!(neoSwaps as any).error) this.allSwaps = neoSwaps;
} catch (err) {
Expand All @@ -777,12 +790,14 @@ export class PopupState {
console.log("ethBals", this.ethBalances);
let ethSwaps = await this.api.getSwapsForAddress(ethAddress, 'ethereum');
console.log("ethSwaps", ethSwaps);
ethSwaps = ethSwaps.filter(
(s) =>
s.destinationHash === "pending" &&
(s.sourcePlatform === "ethereum" ||
s.destinationPlatform === "ethereum")
);
if (ethSwaps) {
ethSwaps = ethSwaps.filter(
(s) =>
s.destinationHash === "pending" &&
(s.sourcePlatform === "ethereum" ||
s.destinationPlatform === "ethereum")
);
}
console.log("ethSwaps", ethSwaps);
if (!(ethSwaps as any).error)
this.allSwaps = this.allSwaps.concat(ethSwaps);
Expand All @@ -797,11 +812,13 @@ export class PopupState {
console.log("bscBals", this.bscBalances);
let bscSwaps = await this.api.getSwapsForAddress(bscAddress, 'bsc');
console.log("bscSwaps", bscSwaps);
bscSwaps = bscSwaps.filter(
(s) =>
s.destinationHash === "pending" &&
(s.sourcePlatform === "bsc" || s.destinationPlatform === "bsc")
);
if (bscSwaps) {
bscSwaps = bscSwaps.filter(
(s) =>
s.destinationHash === "pending" &&
(s.sourcePlatform === "bsc" || s.destinationPlatform === "bsc")
);
}
console.log("bscSwaps", bscSwaps);
if (!(bscSwaps as any).error)
this.allSwaps = this.allSwaps.concat(bscSwaps);
Expand All @@ -813,7 +830,7 @@ export class PopupState {
try {
let phaSwaps = await this.api.getSwapsForAddress(this.currentAccount!.address, 'phantasma');
console.log("phaSwaps", phaSwaps);
phaSwaps = phaSwaps.filter(
phaSwaps = phaSwaps?.filter(
(s) =>
s.destinationHash === "pending" &&
this.allSwaps.findIndex(
Expand Down Expand Up @@ -956,6 +973,7 @@ export class PopupState {
if (!this.isWifValidForAccount(wif))
throw new Error(this.$i18n.t("error.noPasswordMatch").toString());

console.log('wif', wif, 'account', account.address, 'txdata', txdata)
return await this.signTx(txdata, wif);
}

Expand All @@ -967,6 +985,7 @@ export class PopupState {
throw new Error(this.$i18n.t("error.noAccountMatch").toString());

const address = account.address;
console.log('address', address, 'wif', wif)

const dt = new Date();
dt.setMinutes(dt.getMinutes() + 5);
Expand Down Expand Up @@ -1281,12 +1300,14 @@ export class PopupState {

async queryNfts(ids: string[], token: string) {
const allNftsToQuery = [];
console.log('ids', ids, 'token', token)

for (let k = 0; k < ids.length; ++k) {
const id = ids[k];
const lookupId = token + "@" + id;
const nft = this.nfts[lookupId];
if (!nft || nft.img.startsWith("placeholder-")) {
console.log('nft', nft)
if (!nft || !nft.img || nft.img.startsWith("placeholder-")) {
// search for it
allNftsToQuery.push(id);
}
Expand Down Expand Up @@ -1336,17 +1357,18 @@ export class PopupState {
console.log("Got nft", nft);

const imgUrlUnformated = nft.properties.find(
(kv) => kv.Key == "ImageURL"
)?.Value;
(kv) => kv.key == "ImageURL"
)?.value;

let nftDef = {
id: nftId,
mint: nft.mint,
img: imgUrlUnformated,
type: nft.properties.find((kv) => kv.Key == "Type")?.Value,
name: nft.properties.find((kv) => kv.Key == "Name")?.Value,
type: nft.properties.find((kv) => kv.key == "Type")?.value,
name: nft.properties.find((kv) => kv.key == "Name")?.value,
infusion: nft.infusion,
};
console.log('')
nftDict[token + "@" + nftId] = nftDef;
}
Object.assign(this.nfts, nftDict);
Expand Down
17 changes: 11 additions & 6 deletions src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@
>
{{ $t("home.crossChain") }}
</div>
<div class="pa-3"><v-icon color="red" class="mr-2">mdi-alert</v-icon>Warning: cross-chain swaps are NOT enabled.</div>
<div v-if="state.allSwaps.length > 0" class="pa-4">
<div
style="text-transform:uppercase;margin-bottom:0.5rem;color:#17b1e8"
Expand Down Expand Up @@ -338,7 +339,7 @@
}}</a>
</div>-->
</div>
<v-expansion-panel>
<v-expansion-panel class="swap-disabled">
<v-expansion-panel-header>
<v-row>
<v-col class="mt-2">
Expand Down Expand Up @@ -450,7 +451,7 @@
</div>
</v-expansion-panel-content>
</v-expansion-panel>
<v-expansion-panel>
<v-expansion-panel class="swap-disabled">
<v-expansion-panel-header>
<v-row>
<v-col class="mt-2">
Expand Down Expand Up @@ -579,7 +580,7 @@
</v-expansion-panel-content>
</v-expansion-panel>
<!--- TRANSFER FROM BSC -->
<v-expansion-panel>
<v-expansion-panel class="swap-disabled">
<v-expansion-panel-header>
<v-row>
<v-col class="mt-2">
Expand Down Expand Up @@ -708,7 +709,7 @@
</v-expansion-panel-content>
</v-expansion-panel>
<!--- TRANSFER TO NEO -->
<v-expansion-panel>
<v-expansion-panel class="swap-disabled">
<v-expansion-panel-header>
<v-row style="vertical-align:middle">
<v-col class="mt-2"> {{ $t("home.swapTo") }} NEO </v-col>
Expand Down Expand Up @@ -746,7 +747,7 @@
</v-expansion-panel-content>
</v-expansion-panel>
<!--- TRANSFER TO ETH -->
<v-expansion-panel>
<v-expansion-panel class="swap-disabled">
<v-expansion-panel-header>
<v-row>
<v-col class="mt-2">
Expand Down Expand Up @@ -798,7 +799,7 @@
</v-expansion-panel-content>
</v-expansion-panel>
<!--- TRANSFER TO BSC -->
<v-expansion-panel>
<v-expansion-panel class="swap-disabled">
<v-expansion-panel-header>
<v-row>
<v-col class="mt-2"> {{ $t("home.swapTo") }} BSC </v-col>
Expand Down Expand Up @@ -4381,6 +4382,10 @@ export default class extends Vue {
</script>

<style>
.swap-disabled {
opacity: 0.5;
}
.v-tab {
font-size: 12px;
}
Expand Down
4 changes: 2 additions & 2 deletions src/views/Nfts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -705,9 +705,9 @@ export default class extends Vue {
.map(
(i: any) =>
'<v-avatar><img src="assets/' +
i.Key.toLowerCase() +
(i.key ?? i.Key ?? '').toLowerCase() +
'.png" style="height: 1.5rem;vertical-align: middle;margin-right: 0.25rem;"/></v-avatar>' +
state.formatBalance(i.Key, i.Value)
state.formatBalance(i.key ?? i.Key ?? '', i.value ?? i.Value ?? '')
)
.join("<br/>")
: "";
Expand Down
26 changes: 26 additions & 0 deletions src/views/Sign.vue
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,32 @@ export default class extends Vue {
return account && account.type == "encKey";
}
get accountLabel() {
const account = state.currentAccount;
if (!account) return "";
const address = account.address;
if (!account.data.name)
return (
address.substring(0, 8) +
"..." +
address.substring(address.length - 6, address.length)
);
return account.data.name;
}
get accountAddress() {
const account = state.currentAccount;
if (!account) return "";
const address = account.address;
return (
address.substring(0, 8) +
"..." +
address.substring(address.length - 6, address.length)
);
}
get currentAccountDescription() {
const account = state.currentAccount;
Expand Down
4 changes: 4 additions & 0 deletions src/views/Wallets.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<v-list-item
v-for="acc in state.accounts"
v-bind:key="acc.address"
:active="acc.address == curAccountAddress"
:style="{ fontWeight: acc.address == curAccountAddress ? 600 : ''}"
link
@click="gotoAccount(acc)"
>
Expand Down Expand Up @@ -186,6 +188,8 @@ export default class extends Vue {
errorDialog = false;
errorMessage = "";
get curAccountAddress() { return this.state.currentAccount?.address ?? '-' }
async mounted() {
await this.state.check(this.$parent.$i18n);
this.onChangeLanguage();
Expand Down

0 comments on commit 3714611

Please sign in to comment.