Skip to content

Commit

Permalink
Merge pull request #1556 from aeternity/drop-v1-mdw
Browse files Browse the repository at this point in the history
Drop v1 middleware api, cover names with tests
  • Loading branch information
davidyuk authored May 23, 2024
2 parents 3779dbc + 112763d commit d0d5c16
Show file tree
Hide file tree
Showing 51 changed files with 444 additions and 191 deletions.
2 changes: 1 addition & 1 deletion docker-compose/aeternity.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ chain:
"1": 0
"6": 1
genesis_accounts:
ak_21A27UVVt3hDkBE5J7rhhqnH5YNb4Y1dqo4PnSybrH85pnWo7E: 10000000000000000000000
ak_21A27UVVt3hDkBE5J7rhhqnH5YNb4Y1dqo4PnSybrH85pnWo7E: 1000000000000000000000000

# TODO: remove after solving https://github.com/aeternity/ae_mdw/issues/1760
fork_management:
Expand Down
43 changes: 39 additions & 4 deletions docker-compose/init-state.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { execSync } from 'child_process';
import {
Node, AeSdk, MemoryAccount, generateSaveHDWalletFromSeed, getSaveHDWalletAccounts,
encode, Encoding,
} from '@aeternity/aepp-sdk-next';
import { mnemonicToSeed } from '@aeternity/bip39';

Expand Down Expand Up @@ -30,13 +31,47 @@ const aeSdk = new AeSdk({

const seed = mnemonicToSeed('cross cat upper state flame wire inner betray almost party agree endorse');
const wallet = generateSaveHDWalletFromSeed(seed, '');
const [{ publicKey, secretKey }] = getSaveHDWalletAccounts(wallet, '', 1);
const [{ secretKey }, { secretKey: secretKey2 }] = getSaveHDWalletAccounts(wallet, '', 2);
const account1 = new MemoryAccount(secretKey);
const account2 = new MemoryAccount(secretKey2);

await aeSdk.spend(1e20, publicKey);
await aeSdk.spend(200e18, account1.address);
await aeSdk.spend(100e18, account2.address);
console.log('Wallet 1 ready');

await (async function prepareTransactionHistory() {
const onAccount = new MemoryAccount(secretKey);
for (let i = 0; i < 15; i += 1) {
await aeSdk.spend(1e14, aeSdk.address, { onAccount });
await aeSdk.spend(0.0001e18, aeSdk.address, { onAccount: account1 });
}
console.log('Transaction history ready');
})();

await (async function prepareNames() {
await aeSdk.aensClaim('engine.chain', 0);
await aeSdk.aensBid('engine.chain', 60e18, { onAccount: account1 });
await aeSdk.aensBid('engine.chain', 65e18);
await aeSdk.aensClaim('visual.chain', 0);
await aeSdk.aensBid('visual.chain', 60e18, { onAccount: account1 });
await aeSdk.aensClaim('inspector.chain', 0);
await aeSdk.aensClaim('мир.chain', 0);
await aeSdk.aensClaim('understanding.chain', 0, { onAccount: account1 });
await aeSdk.aensClaim('entertainment.chain', 0, { onAccount: account2 });
await aeSdk.aensUpdate('entertainment.chain', {
'account_pubkey': account2.address,
'contract_pubkey': account1.address.replace('ak_', 'ct_'),
'second account': account1.address,
'raw': encode(Buffer.from('test'), Encoding.Bytearray),
}, { onAccount: account2 });
console.log('Names ready');
})();

await (async function wallet2() {
const seed = mnemonicToSeed('sun dish cousin double youth year path fix away pig spring upset');
const wallet = generateSaveHDWalletFromSeed(seed, '');
const [{ secretKey }, { publicKey: publicKey2 }] = getSaveHDWalletAccounts(wallet, '', 2);
const acc = new MemoryAccount(secretKey);
await aeSdk.spend(100e18, acc.address);
await aeSdk.spend(100e18, publicKey2);
await aeSdk.aensClaim('investigation.chain', 0, { onAccount: acc });
console.log('Wallet 2 ready');
})();
8 changes: 4 additions & 4 deletions src/components/AeInputName.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { isNameValid } from '@aeternity/aepp-sdk-next';
import withFormatting from '../lib/withFormatting';
import { AENS_DOMAIN } from '../lib/constants';
import AeInput from './AeInput.vue';

const nameRegExp = new RegExp(`^[a-zA-Z0-9]+\\${AENS_DOMAIN}$`);
const notNameCharsRegExp = /[^a-zA-Z0-9]/g;
const notNameCharsRegExp = /[^\p{General_Category=Letter}0-9-]/gu;

export const formatDisplayValueAndCursor = ({ value, cursor }, previousValue) => {
if (!value || value === AENS_DOMAIN) return { value: '', cursor: 0 };
if (nameRegExp.test(value)) return { value, cursor };
if (isNameValid(value)) return { value, cursor };
if (!previousValue) {
const cleared = value
.replace(new RegExp(`\\${AENS_DOMAIN}$`), '')
Expand All @@ -17,7 +17,7 @@ export const formatDisplayValueAndCursor = ({ value, cursor }, previousValue) =>
cursor,
};
}
if (nameRegExp.test(value + AENS_DOMAIN) && !value.endsWith(AENS_DOMAIN.slice(1))) {
if (isNameValid(value + AENS_DOMAIN) && !value.endsWith(AENS_DOMAIN.slice(1))) {
return { value: value + AENS_DOMAIN, cursor };
}
return {
Expand Down
26 changes: 13 additions & 13 deletions src/components/__tests__/AeInputAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,44 +47,44 @@ describe('AeInputAccount', () => {
input: {
value: 'test',
displayed: testName,
emmited: testName,
emitted: testName,
},
}, {
name: 'removes non-base58 symbols in addresses',
input: {
value: 'ak_019AHIJNOPZaklmzяя',
displayed: 'ak_ 19A HJN PZa kmz',
emmited: 'ak_19AHJNPZakmz',
emitted: 'ak_19AHJNPZakmz',
},
}, {
name: 'removes unknown symbols in names',
input: {
value: 'ka_019AHIJNOPZaklmzяя.ch',
displayed: 'ka019AHIJNOPZaklmzch.chain',
emmited: 'ka019AHIJNOPZaklmzch.chain',
value: 'ka_019AHIJNOPZaklmzяя-#$.ch',
displayed: 'ka019AHIJNOPZaklmzяя-ch.chain',
emitted: 'ka019AHIJNOPZaklmzяя-ch.chain',
},
}, {
name: 'removes unknown symbols in names preserving AENS domain',
input: {
value: 'ka_019AHIJNOPZaklmzяя.chain',
displayed: 'ka019AHIJNOPZaklmz.chain',
emmited: 'ka019AHIJNOPZaklmz.chain',
value: 'ka_019AHIJNOPZaklmzяя-#$.chain',
displayed: 'ka019AHIJNOPZaklmzяя-.chain',
emitted: 'ka019AHIJNOPZaklmzяя-.chain',
},
}, {
name: 'emits input event contains address without space symbols',
input: {
value: testAddress,
cursor: 10,
displayed: testAddressFormatted,
emmited: testAddress,
emitted: testAddress,
},
}, {
name: 'limits address length',
input: {
value: `${testAddressFormatted}test`,
cursor: 25,
displayed: testAddressFormatted,
emmited: testAddress,
emitted: testAddress,
},
}, {
name: 'can paste a name ending with domain without dot',
Expand Down Expand Up @@ -138,7 +138,7 @@ describe('AeInputAccount', () => {
input: {
value: '_',
displayed: '',
emmited: '',
emitted: '',
},
}].forEach((test) => it(test.name, () => {
const inputListener = jest.fn();
Expand All @@ -156,8 +156,8 @@ describe('AeInputAccount', () => {
textarea.element.setSelectionRange(cursor, cursor);
textarea.trigger('input');
expect(wrapper.find('textarea').element.value).toBe(test.input.displayed);
if (test.input.emmited !== undefined) {
expect(inputListener.mock.calls[0][0]).toEqual(test.input.emmited);
if (test.input.emitted !== undefined) {
expect(inputListener.mock.calls[0][0]).toEqual(test.input.emitted);
}
}
}));
Expand Down
21 changes: 20 additions & 1 deletion src/lib/methods.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// eslint-disable-next-line import/prefer-default-export
import Swagger from 'swagger-client';

export async function resetConfirm() {
await this.$store.dispatch('modals/open', {
name: 'confirm',
Expand All @@ -9,3 +10,21 @@ export async function resetConfirm() {
});
await this.$store.dispatch('reset');
}

export async function fetchAuctions(handler) {
const { state: { sdk: sdkPromise }, getters: { currentNetwork } } = this.$store;
const sdk = await Promise.resolve(sdkPromise);
const res = await sdk.middleware2.api.getNamesAuctions({ limit: 100 });
let { next } = res;
handler(res.data);
while (next) {
const url = currentNetwork.middlewareUrl + next;
const r = sdk.middleware2.responseInterceptor(
// eslint-disable-next-line no-await-in-loop
await Swagger.serializeRes(await fetch(url), url),
).body;
handler(r.data);
next = r.next;
}
handler();
}
4 changes: 2 additions & 2 deletions src/lib/networksRegistry.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const mainNetwork = {
name: `${Date.now() < 1715072400000 ? 'Iris' : 'Ceres'}-net`,
name: 'Ceres-net',
url: 'https://mainnet.aeternity.io',
middlewareUrl: 'https://mainnet.aeternity.io/mdw',
explorerUrl: 'https://aescan.io',
};

const testNetwork = {
name: `Testnet${Date.now() < 1713947400000 ? ' (Iris)' : ''}`,
name: 'Testnet',
url: 'https://testnet.aeternity.io',
middlewareUrl: 'https://testnet.aeternity.io/mdw',
explorerUrl: 'https://testnet.aescan.io',
Expand Down
6 changes: 3 additions & 3 deletions src/locales/cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@
"personal-explanation": "点击“+”按钮来申请并与您的帐号关联.",
"no-auctions": "There are no auctions matching these criteria.",
"registered": "注册名称",
"active-bids": "Active Bids"
"active-auctions": "Active Auctions"
},

"details": {
Expand Down Expand Up @@ -476,8 +476,8 @@
"confirm-transfering-to-same-account": "The account you are transferring to and the account, which owns the name you are transferring, are the same account. Are you sure you would like to complete this transaction?",

"notification":{
"succeed": "{name} was successfully transfered",
"failed": "{name} was not transfered for unknown reason"
"succeed": "{name} was successfully transferred",
"failed": "{name} was not transferred for unknown reason"
}
},

Expand Down
6 changes: 3 additions & 3 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@
"personal-explanation": "Tap the “+” button below to claim a name and associate it with one of your accounts.",
"no-auctions": "There are no auctions matching these criteria.",
"registered": "Registered Names",
"active-bids": "Active Bids"
"active-auctions": "Active Auctions"
},

"details": {
Expand Down Expand Up @@ -476,8 +476,8 @@
"confirm-transfering-to-same-account": "The account you are transferring to and the account, which owns the name you are transferring, are the same account. Are you sure you would like to complete this transaction?",

"notification":{
"succeed": "{name} was successfully transfered",
"failed": "{name} was not transfered for unknown reason"
"succeed": "{name} was successfully transferred",
"failed": "{name} was not transferred for unknown reason"
}
},

Expand Down
6 changes: 3 additions & 3 deletions src/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@
"personal-explanation": "Toque el botón “+” a continuación para reclamar un nombre y asociarlo con una de sus cuentas",
"no-auctions": "There are no auctions matching these criteria.",
"registered": "Nombres registrados",
"active-bids": "Active Bids"
"active-auctions": "Active Auctions"
},

"details": {
Expand Down Expand Up @@ -476,8 +476,8 @@
"confirm-transfering-to-same-account": "The account you are transferring to and the account, which owns the name you are transferring, are the same account. Are you sure you would like to complete this transaction?",

"notification":{
"succeed": "{name} was successfully transfered",
"failed": "{name} was not transfered for unknown reason"
"succeed": "{name} was successfully transferred",
"failed": "{name} was not transferred for unknown reason"
}
},

Expand Down
2 changes: 1 addition & 1 deletion src/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@
"personal-explanation": "Нажмите кнопку «+» ниже, чтобы запросить имя и связать его с одним из ваших аккаунтов.",
"no-auctions": "Нет аукционов, соответствующих этим критериям.",
"registered": "Зарегистрированные имена",
"active-bids": "Активные ставки"
"active-auctions": "Активные аукционы"
},

"details": {
Expand Down
33 changes: 15 additions & 18 deletions src/pages/aens/AuctionBid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
v-validate="{
required: true,
decimal: MAGNITUDE,
min_value_currency: lastBid ? lastBid.multipliedBy(1.05).toString() : 0,
min_value_currency: highestBid ? highestBid.multipliedBy(1.05).toString() : 0,
}"
:error="errors.has('amount')"
:footer="errors.first('amount') && errors.first('amount').toString() || ' '"
Expand All @@ -52,23 +52,23 @@
</template>

<DetailsAmountCurrency
v-if="lastBid"
v-if="highestBid"
short
:name="$t('name.bid.highest-bid')"
:amount="lastBid"
:amount="highestBid"
/>

<DetailsField
v-if="auctionEnd && topBlockHeight"
v-if="endsAt && topBlockHeight"
:name="$t('name.bid.remaining-time')"
:value="blocksToRelativeTime(auctionEnd - topBlockHeight)"
:value="blocksToRelativeTime(endsAt - topBlockHeight)"
/>

<AeButton
fill="secondary"
:spinner="busy"
:form="_uid"
:disabled="errors.has('name') || !auctionEnd || busy"
:disabled="errors.has('name') || !endsAt || busy"
>
{{ $t('next') }}
</AeButton>
Expand Down Expand Up @@ -108,19 +108,19 @@ export default {
return {
busy: false,
internalName: this.name,
lastBid: null,
auctionEnd: 0,
highestBid: null,
endsAt: 0,
amount: '',
MAGNITUDE,
};
},
computed: {
...mapGetters('accounts', ['activeColor']),
backTo() {
if (!this.name && !this.auctionEnd) return { name: 'name-list' };
if (!this.name && !this.endsAt) return { name: 'name-list' };
return {
name: 'auction-bid',
params: { name: this.auctionEnd ? this.internalName : this.name },
params: { name: this.endsAt ? this.internalName : this.name },
};
},
},
Expand All @@ -134,14 +134,11 @@ export default {
(name) => {
if (promise) promise.cancel();
promise = (async () => {
this.auctionEnd = 0;
this.lastBid = null;
const sdk = await Promise.resolve(this.$store.state.sdk);
const res = await sdk.middleware.api.getNameById(name);
if (res.status !== 'auction') throw new Error(`Unexpected name status: ${res.status}`);
const { auctionEnd, lastBid } = res.info;
this.auctionEnd = auctionEnd;
this.lastBid = new BigNumber(lastBid.tx.nameFee).shiftedBy(-MAGNITUDE);
this.endsAt = 0;
this.highestBid = null;
const { endsAt, highestBid } = await this.$store.getters.node.getAuctionEntryByName(name);
this.endsAt = endsAt;
this.highestBid = new BigNumber(highestBid).shiftedBy(-MAGNITUDE);
})();
},
{ immediate: true },
Expand Down
Loading

0 comments on commit d0d5c16

Please sign in to comment.