Skip to content

Commit

Permalink
Use es modules version in browser if supported
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Apr 20, 2021
1 parent 622e501 commit b49c38f
Show file tree
Hide file tree
Showing 33 changed files with 59 additions and 72 deletions.
12 changes: 6 additions & 6 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ recent change in [Babel] compilation and fully compliant with the standard.
The recommended approach to use aepp-sdk is to import one of the following _Ae
Factories_ based on the specific use case:

* [@aeternity/aepp-sdk/es/ae/wallet](api/ae/wallet.md): for **Wallet**'s focused development
* [@aeternity/aepp-sdk/es/ae/contract](api/ae/contract.md): for **Contract**'s focused development
* [@aeternity/aepp-sdk/es/ae/aepp](api/ae/aepp.md): for **Web Aepp**'s focused development ⚠️ **_No Wallet support_**
* [@aeternity/aepp-sdk/es/ae/aens](api/ae/aens.md): for **AENs**' focused development
* [@aeternity/aepp-sdk/es/ae/oracle](api/ae/oracle.md): for **Oracle**'s focused development
* [@aeternity/aepp-sdk/es/ae/universal](api/ae/universal.md): for **Universal** development (includes all SDK features)
* [`RpcWallet`](api/ae/wallet.md): for **Wallet**'s focused development
* [`Contract`](api/ae/contract.md): for **Contract**'s focused development
* [`RpcAepp`](api/ae/aepp.md): for **Web Aepp**'s focused development ⚠️ **_No Wallet support_**
* [`Aens`](api/ae/aens.md): for **AENs**' focused development
* [`Oracle`](api/ae/oracle.md): for **Oracle**'s focused development
* [`Universal`](api/ae/universal.md): for **Universal** development (includes all SDK features)

In order to cater more specific needs, it is recommended to refer to the
[contributing Docs](contrib/README.md).
Expand Down
4 changes: 1 addition & 3 deletions docs/contrib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ services:
You can also "compose" your own flavor by mixing 2 or more flavors likes so:

```js
import Wallet from '@aeternity/aepp-sdk/es/ae/wallet.js'
import Contract from '@aeternity/aepp-sdk/es/ae/contract.js'
import MemoryAccount from '@aeternity/aepp-sdk/es/account/memory.js'
import { Wallet, Contract, MemoryAccount } from '@aeternity/aepp-sdk'
// make a "mixed flavor" containing Wallet and Contracts flavors
Wallet.compose(Contract)({
Expand Down
4 changes: 1 addition & 3 deletions docs/guides/delegate-signature-to-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ The following code snippet shows how to generate
signatures for name transactions delegation to a contract

```js
import Universal from '@aeternity/aepp-sdk/es/ae/universal'
import MemoryAccount from '@aeternity/aepp-sdk/es/account/memory'
import * as Crypto from '@aeternity/aepp-sdk/es/utils/crypto'
import { Universal, MemoryAccount, Crypto } from '@aeternity/aepp-sdk'

// Init account
const keypair = Crypto.generateKeyPair()
Expand Down
4 changes: 2 additions & 2 deletions docs/guides/how-to-build-aepp-using-new-wallet-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The full example of implementation you can find here: [AEPP example](https://git
### First we need to initialize our `Aepp` stamp

```js
import { RpcAepp } from '@aeternity/aepp-sdk/es'
import { RpcAepp } from '@aeternity/aepp-sdk'

// Open iframe with Wallet if run in top window
// window !== window.parent || await this.getReverseWindow()
Expand Down Expand Up @@ -54,7 +54,7 @@ The full example of implementation you can find here: [AEPP example](https://git
const scannerConnection = await BrowserWindowMessageConnection({
connectionInfo: { id: 'spy' }
})
// Initialize WalletDetector
// Initialize WalletDetector
this.detector = await WalletDetector({ connection: scannerConnection })
// Start scanning
this.detector.scan(handleWallets.bind(this))
Expand Down
7 changes: 2 additions & 5 deletions docs/guides/how-to-build-an-wallet-app-or-extension.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,17 @@ After connection will be established we can start to send `announcePresence` mes
import '../img/icon-128.png'
import '../img/icon-34.png'

import Node from '@aeternity/aepp-sdk/es/node'
import MemoryAccount from '@aeternity/aepp-sdk/es/account/memory'
import { RpcWallet } from '@aeternity/aepp-sdk/es/ae/wallet'
import { Node, MemoryAccount, RpcWallet, Crypto } from '@aeternity/aepp-sdk'
import BrowserRuntimeConnection
from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/browser-runtime'
import { generateKeyPair } from '@aeternity/aepp-sdk/es/utils/crypto'

// const account = MemoryAccount({
// keypair: {
// secretKey: 'YOUR_PRIV',
// publicKey: 'YOUR_PUB'
// }
// })
const account2 = MemoryAccount({ keypair: generateKeyPair() })
const account2 = MemoryAccount({ keypair: Crypto.generateKeyPair() })

// Init accounts
const accounts = [
Expand Down
17 changes: 6 additions & 11 deletions docs/guides/import-vuejs.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,18 @@ Adding aepp-sdk to a Vue.js project requires nothing special, but it should be
noted that `client creation` is asynchronous which needs to be taken into account.

```bash
vue init webpack my-project
npm install -g @vue/cli
vue create my-project
cd my-project
npm install @aeternity/aepp-sdk
```

```html
# src/components/HelloWorld.vue
```vue
<!-- src/components/HelloWorld.vue -->
<script>
// import Universal stamp
import Universal from '@aeternity/aepp-sdk/es/ae/universal'
// import Node
import Node from '@aeternity/aepp-sdk/es/node'
// import Account
import MemoryAccount from '@aeternity/aepp-sdk/es/account/memory'
// import Universal stamp, Node, and Account
import { Universal, Node, MemoryAccount } from '@aeternity/aepp-sdk'
export default {
name: 'HelloWorld',
Expand All @@ -43,5 +40,3 @@ export default {
}
</script>
```

[Vue.js]: https://vuejs.org/
27 changes: 13 additions & 14 deletions docs/guides/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ npm i @aeternity/aepp-sdk
npm i @aeternity/aepp-sdk@next

# install the #develop version of the SDK
npm i https://github.com/aeternity/aepp-sdk-js#develop
npm i github:aeternity/aepp-sdk-js#develop
```

**Note** : If you experience errors during the installation, you might need to install build tools for your OS.
Expand All @@ -44,12 +44,12 @@ xcode-select --install
You can do many more things now, but you'll probably have to start with:

### A) Using the Command Line
Create an account using the [💻 CLI](#cli---command-line-client)
Create an account using the [💻 CLI](https://github.com/aeternity/aepp-cli-js)

### B) Using the SDK

```javascript
import { Crypto } from '@aeternity/aepp-sdk/es'
import { Crypto } from '@aeternity/aepp-sdk'
const keypair = Crypto.generateKeyPair()
console.log(`Secret key: ${keypair.secretKey}`)
console.log(`Public key: ${keypair.publicKey}`)
Expand All @@ -65,34 +65,33 @@ Import the right [flavor](../README.md#flavors--entry-points). For this example

```js
// Import Flavor
import Ae from '@aeternity/aepp-sdk/es/ae/universal' // or other flavor
import { Universal } from '@aeternity/aepp-sdk' // or other flavor
```

## 5. Play with Aetenity's blockchain features

```js
// Use Flavor
import Ae from '@aeternity/aepp-sdk/es/ae/universal' // or other flavor
import MemoryAccount from '@aeternity/aepp-sdk/es/account/memory' // or other flavor
import Node from '@aeternity/aepp-sdk/es/node' // or other flavor
import { AE_AMOUNT_FORMATS } from '@aeternity/aepp-sdk/es/utils/amount-formatter'
import { Universal, MemoryAccount, Node, AmountFormatter } from '@aeternity/aepp-sdk'

const NODE_URL = 'https://testnet.aeternity.io'
const COMPILER_URL = 'COMPILER_URL' // required for using Contract
const ACCOUNT = MemoryAccount({ keypair: { secretKey: 'A_PRIV_KEY', publicKey: 'A_PUB_ADDRESS' } })
const COMPILER_URL = 'https://compiler.aepps.com' // required for using Contract
const account = MemoryAccount({ keypair: { secretKey: 'A_PRIV_KEY', publicKey: 'A_PUB_ADDRESS' } })

(async function () {
const nodeInstance = await Node({ url: NODE_URL })
const sdkInstance = await Ae({
const sdkInstance = await Universal({
compilerUrl: COMPILER_URL,
nodes: [ { name: 'test-net', instance: nodeInstance } ],
accounts: [ ACCOUNT ]
accounts: [ account ]
})

await sdkInstance.height() // get top block height
console.log('Current Block Height:', height)

await sdkInstance.spend(1, 'ak_asd23dasdasda...', { denomination: AE_AMOUNT_FORMATS.AE }) // spend one AE

// spend one AE
await sdkInstance.spend(1, 'ak_asd23dasdasda...', {
denomination: AmountFormatter.AE_AMOUNT_FORMATS.AE
})
})()
```
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
"description": "SDK for the æternity blockchain",
"main": "dist/aepp-sdk.js",
"types": "es/index.d.ts",
"browser": "dist/aepp-sdk.browser.js",
"module": "es/index.js",
"browser": {
"dist/aepp-sdk.js": "./dist/aepp-sdk.browser.js"
},
"sideEffects": false,
"scripts": {
"build": "tsc && webpack -p && babel src --config-file ./babel.esm.config.js --out-dir es --extensions '.js,.ts' --source-maps true",
Expand Down
2 changes: 1 addition & 1 deletion src/account/memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Memory Account module
* @module @aeternity/aepp-sdk/es/account/memory
* @export MemoryAccount
* @example import MemoryAccount from '@aeternity/aepp-sdk/es/account/memory'
* @example import { MemoryAccount } from '@aeternity/aepp-sdk'
*/

import AccountBase from './base'
Expand Down
2 changes: 1 addition & 1 deletion src/ae/aens.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* repository.
* @module @aeternity/aepp-sdk/es/ae/aens
* @export Aens
* @example import Aens from '@aeternity/aepp-sdk/es/ae/aens'
* @example import { Aens } from '@aeternity/aepp-sdk'
*/

import * as R from 'ramda'
Expand Down
2 changes: 1 addition & 1 deletion src/ae/aepp.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Aepp module
* @module @aeternity/aepp-sdk/es/ae/aepp
* @export Aepp
* @example import Ae from '@aeternity/aepp-sdk/es/ae/aepp'
* @example import { RpcAepp } from '@aeternity/aepp-sdk'
*/

import Ae from './'
Expand Down
3 changes: 1 addition & 2 deletions src/ae/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
*
* @module @aeternity/aepp-sdk/es/ae/contract
* @export Contract
* @example import Contract from '@aeternity/aepp-sdk/es/ae/contract' (Using tree-shaking)
* @example import { Contract } from '@aeternity/aepp-sdk' (Using bundle)
* @example import { Contract } from '@aeternity/aepp-sdk'
*/

import Ae from './'
Expand Down
2 changes: 1 addition & 1 deletion src/ae/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Ae module
* @module @aeternity/aepp-sdk/es/ae
* @export Ae
* @example import Ae from '@aeternity/aepp-sdk/es/ae'
* @example import { Ae } from '@aeternity/aepp-sdk'
*/

import stampit from '@stamp/it'
Expand Down
2 changes: 1 addition & 1 deletion src/ae/oracle.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* repository.
* @module @aeternity/aepp-sdk/es/ae/oracle
* @export Oracle
* @example import Oracle from '@aeternity/aepp-sdk/es/ae/oracle'
* @example import { Oracle } from '@aeternity/aepp-sdk'
*/

import Ae from './'
Expand Down
2 changes: 1 addition & 1 deletion src/ae/universal.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Universal module
* @module @aeternity/aepp-sdk/es/ae/universal
* @export Universal
* @example import Ae from '@aeternity/aepp-sdk/es/ae/universal'
* @example import { Universal } from '@aeternity/aepp-sdk'
*/

import Ae from './'
Expand Down
2 changes: 1 addition & 1 deletion src/ae/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Wallet module
* @module @aeternity/aepp-sdk/es/ae/wallet
* @export Wallet
* @example import Wallet from '@aeternity/aepp-sdk/es/ae/wallet'
* @example import { RpcWallet } from '@aeternity/aepp-sdk'
*/

import Ae from './'
Expand Down
2 changes: 1 addition & 1 deletion src/chain/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Chain module
* @module @aeternity/aepp-sdk/es/chain
* @export Chain
* @example import Chain from '@aeternity/aepp-sdk/es/chain'
* @example import { Chain } from '@aeternity/aepp-sdk'
*/

import stampit from '@stamp/it'
Expand Down
2 changes: 1 addition & 1 deletion src/chain/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { DRY_RUN_ACCOUNT, NAME_ID_KEY } from '../tx/builder/schema'
* This is the complement to {@link module:@aeternity/aepp-sdk/es/chain}.
* @module @aeternity/aepp-sdk/es/chain/node
* @export ChainNode
* @example import ChainNode from '@aeternity/aepp-sdk/es/chain/node'
* @example import { ChainNode } from '@aeternity/aepp-sdk'
*/

async function sendTransaction (tx, options = {}) {
Expand Down
2 changes: 1 addition & 1 deletion src/channel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Channel module
* @module @aeternity/aepp-sdk/es/channel/index
* @export Channel
* @example import Channel from '@aeternity/aepp-sdk/es/channel/index'
* @example import { Channel } from '@aeternity/aepp-sdk'
*/

import AsyncInit from '../utils/async-init'
Expand Down
2 changes: 1 addition & 1 deletion src/contract/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* This is the complement to {@link module:@aeternity/aepp-sdk/es/contract}.
* @module @aeternity/aepp-sdk/es/contract/compiler
* @export ContractCompilerAPI
* @example import ContractCompilerAPI from '@aeternity/aepp-sdk/es/contract/compiler'
* @example import { ContractCompilerAPI } from '@aeternity/aepp-sdk'
*/

import Http from '../utils/http'
Expand Down
3 changes: 1 addition & 2 deletions src/contract/ga/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
*
* @module @aeternity/aepp-sdk/es/contract/ga
* @export GeneralizeAccount
* @example import GeneralizeAccount from '@aeternity/aepp-sdk/es/contract/ga' (Using tree-shaking)
* @example import { GeneralizeAccount } from '@aeternity/aepp-sdk' (Using bundle)
* @example import { GeneralizeAccount } from '@aeternity/aepp-sdk'
*/
import * as R from 'ramda'

Expand Down
2 changes: 1 addition & 1 deletion src/node-pool/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* NodePool module
* @module @aeternity/aepp-sdk/es/node-pool
* @export NodePool
* @example import NodePool from '@aeternity/aepp-sdk/es/node-pool'
* @example import { NodePool } from '@aeternity/aepp-sdk'
*/
import stampit from '@stamp/it'
import { getterForCurrentNode, prepareNodeObject } from './helpers'
Expand Down
2 changes: 1 addition & 1 deletion src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Node module
* @module @aeternity/aepp-sdk/es/node
* @export Node
* @example import Node from '@aeternity/aepp-sdk/es/node'
* @example import { Node } from '@aeternity/aepp-sdk'
*/

import AsyncInit from './utils/async-init'
Expand Down
2 changes: 1 addition & 1 deletion src/tx/builder/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { ceil } from '../../utils/bignumber'
* JavaScript-based Transaction builder helper function's
* @module @aeternity/aepp-sdk/es/tx/builder/helpers
* @export TxBuilderHelper
* @example import TxBuilderHelper from '@aeternity/aepp-sdk/es/tx/builder/helpers'
* @example import { TxBuilderHelper } from '@aeternity/aepp-sdk'
*/

export const createSalt = salt
Expand Down
2 changes: 1 addition & 1 deletion src/tx/builder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import * as mpt from '../../utils/mptree'
* JavaScript-based Transaction builder
* @module @aeternity/aepp-sdk/es/tx/builder
* @export TxBuilder
* @example import Transaction from '@aeternity/aepp-sdk/es/tx/builder'
* @example import { TxBuilder } from '@aeternity/aepp-sdk'
*/

const ORACLE_TTL_TYPES = {
Expand Down
2 changes: 1 addition & 1 deletion src/tx/builder/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Transaction Schema for TxBuilder
* @module @aeternity/aepp-sdk/es/tx/builder/schema
* @export TxSchema
* @example import TxSchema from '@aeternity/aepp-sdk/es/tx/builder/schema'
* @example import { SCHEMA } from '@aeternity/aepp-sdk'
*/
// # RLP version number
// # https://github.com/aeternity/protocol/blob/master/serializations.md#binary-serialization
Expand Down
2 changes: 1 addition & 1 deletion src/tx/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Tx module
* @module @aeternity/aepp-sdk/es/tx
* @export Tx
* @example import Tx from '@aeternity/aepp-sdk/es/tx'
* @example import { Tx } from '@aeternity/aepp-sdk'
*/

import stampit from '@stamp/it'
Expand Down
2 changes: 1 addition & 1 deletion src/tx/tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Transaction module
* @module @aeternity/aepp-sdk/es/tx/tx
* @export Transaction
* @example import Transaction from '@aeternity/aepp-sdk/es/tx/tx'
* @example import { Transaction } from '@aeternity/aepp-sdk'
*/

import * as R from 'ramda'
Expand Down
2 changes: 1 addition & 1 deletion src/tx/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { NodePool } from '../node-pool'
* Transaction validator
* @module @aeternity/aepp-sdk/es/tx/validator
* @export TransactionValidator
* @example import TransactionValidator from '@aeternity/aepp-sdk/es/tx/validator'
* @example import { TransactionValidator } from '@aeternity/aepp-sdk'
*/

const VALIDATORS = {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/amount-formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* Amount Formatter
* @module @aeternity/aepp-sdk/es/utils/amount-formatter
* @example import { format, toAettos, AE_AMOUNT_FORMATS } from '@aeternity/aepp-sdk/es/utils/amount-formatter'
* @example import { AmountFormatter } from '@aeternity/aepp-sdk'
*/
import BigNumber from 'bignumber.js'
import { asBigNumber, isBigNumber } from './bignumber'
Expand Down
Loading

0 comments on commit b49c38f

Please sign in to comment.