Skip to content

Commit

Permalink
Merge pull request #4 from MultipleChain/beycan
Browse files Browse the repository at this point in the history
Beycan
  • Loading branch information
0xBeycan authored Apr 30, 2024
2 parents 1630159 + 17b5165 commit 7b5794d
Show file tree
Hide file tree
Showing 16 changed files with 1,011 additions and 60 deletions.
22 changes: 16 additions & 6 deletions packages/networks/boilerplate/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
.wallet-list-wrapper {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
left: 20%;
transform: translate(0, -50%);
background: #fff;
border-radius: 10px;
padding: 20px;
Expand Down Expand Up @@ -108,15 +108,17 @@
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
transform: translate(0, -50%);
background: #fff;
border-radius: 10px;
padding: 20px;
box-shadow: 0 8px 30px rgba(74,58,150, .2);
max-width: 400px;
max-width: 450px;
width: 100%;
box-sizing: border-box;
font-family: Arial, Helvetica, sans-serif;
max-height: 400px;
overflow-y: auto;
}

.info {
Expand All @@ -129,6 +131,12 @@
color: #000;
}

.info span img {
width: 20px;
height: 20px;
margin-left: 10px;
}

.action-btn {
width: 100%;
padding: 10px;
Expand Down Expand Up @@ -226,7 +234,6 @@
})

document.querySelector('.methods').style.display = 'block'
document.querySelector('.wallet-list-wrapper').style.display = 'none'

const sender = await wallet.getAddress()
document.querySelector('.adapter-id').innerText = wallet.getId()
Expand All @@ -238,6 +245,7 @@
document.querySelector('.chain-id').innerText = await wallet.getChainId()
document.querySelector('.connected-address').innerText = sender

document.querySelector('.action-result .sign-message').innerText = ''
document.querySelector('.action-btn.sign-message').onclick = async () => {
const result = await wallet.signMessage('Hello World')
document.querySelector('.action-result .sign-message').innerText = result
Expand All @@ -246,13 +254,15 @@
const receiver = '0xbBa4d06D1cEf94b35aDeCfDa893523907fdD36DE';
const tokenAddress = '0x4294cb0dD25dC9140B5127f247cBd47Eeb673431';

document.querySelector('.action-result .send-coin').innerText = ''
document.querySelector('.action-btn.send-coin').onclick = async () => {
const coin = new Boilerplate.assets.Coin();
const signer = await coin.transfer(sender, receiver, 0.00001)
const result = await wallet.sendTransaction(signer)
document.querySelector('.action-result .send-coin').innerText = result
}

document.querySelector('.action-result .send-token').innerText = ''
document.querySelector('.action-btn.send-token').onclick = async () => {
const token = new Boilerplate.assets.Token(tokenAddress);
const signer = await token.transfer(sender, receiver, 0.1)
Expand Down Expand Up @@ -302,6 +312,7 @@
}

const container = document.querySelector('.wallet-list-container')
container.innerHTML = ''

let adapters = Boilerplate.browser.adapters

Expand Down Expand Up @@ -334,7 +345,6 @@
Object.values(adapters).forEach(adapter => {
container.innerHTML += adapterTemplate(adapter)
})

</script>
</body>
</html>
14 changes: 9 additions & 5 deletions packages/networks/boilerplate/package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
{
"name": "@multiplechain/evm-chains",
"name": "@multiplechain/boilerplate",
"version": "0.1.0",
"type": "module",
"types": "dist/index.d.ts",
"main": "dist/index.cjs",
"module": "dist/index.es.js",
"unpkg": "dist/index.umd.js",
"browser": "dist/index.umd.js",
"jsdelivr": "dist/index.umd.js",
"exports": {
".": {
"import": "./dist/index.es.js",
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts"
"import": {
"default": "./dist/index.es.js",
"types": "./dist/browser/index.d.ts"
},
"require": {
"default": "./dist/index.cjs",
"types": "./dist/index.d.ts"
}
}
},
"files": [
Expand Down
25 changes: 18 additions & 7 deletions packages/networks/boilerplate/src/browser/Wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@ import type {
WalletPlatformEnum,
TransactionSignerInterface
} from '@multiplechain/types'
import { Provider } from '../services/Provider'

export class Wallet implements WalletInterface {
adapter: WalletAdapterInterface

walletProvider: object

networkProvider: Provider

/**
* @param {WalletAdapterInterface} adapter
* @param {Provider} provider
*/
constructor(adapter: WalletAdapterInterface) {
constructor(adapter: WalletAdapterInterface, provider?: Provider) {
this.adapter = adapter
this.networkProvider = provider ?? Provider.instance
}

/**
Expand Down Expand Up @@ -46,7 +53,7 @@ export class Wallet implements WalletInterface {
/**
* @returns {string}
*/
getDownloadLink(): string {
getDownloadLink(): string | undefined {
return this.adapter.downloadLink
}

Expand All @@ -55,7 +62,11 @@ export class Wallet implements WalletInterface {
* @param {object} ops
* @returns {string}
*/
createDeepLink(url: string, ops?: object): string {
createDeepLink(url: string, ops?: object): string | null {
if (this.adapter.createDeepLink === undefined) {
return null
}

return this.adapter.createDeepLink(url, ops)
}

Expand All @@ -71,15 +82,15 @@ export class Wallet implements WalletInterface {
/**
* @returns {boolean}
*/
isDetected(): boolean {
return this.adapter.isDetected()
async isDetected(): Promise<boolean> {
return await this.adapter.isDetected()
}

/**
* @returns {boolean}
*/
isConnected(): boolean {
return this.adapter.isConnected()
async isConnected(): Promise<boolean> {
return await this.adapter.isConnected()
}

/**
Expand Down
9 changes: 3 additions & 6 deletions packages/networks/boilerplate/src/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import type {
RegisterWalletAdapterType
} from '@multiplechain/types'


const adapters: WalletAdapterListType = {
...adapterList
}
const adapters: WalletAdapterListType = {}

const registerAdapter: RegisterWalletAdapterType = (adapter: WalletAdapterInterface): void => {
if (Object.values(adapters).find((a) => a.id === adapter.id) !== undefined) {
Expand All @@ -23,6 +20,6 @@ export * from '../index.ts'

export const browser = {
Wallet,
adapters,
registerAdapter
registerAdapter,
adapters: Object.assign(adapters, adapterList)
}
28 changes: 22 additions & 6 deletions packages/networks/evm-chains/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
.wallet-list-wrapper {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
left: 20%;
transform: translate(0, -50%);
background: #fff;
border-radius: 10px;
padding: 20px;
Expand Down Expand Up @@ -108,15 +108,17 @@
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
transform: translate(0, -50%);
background: #fff;
border-radius: 10px;
padding: 20px;
box-shadow: 0 8px 30px rgba(74,58,150, .2);
max-width: 400px;
max-width: 450px;
width: 100%;
box-sizing: border-box;
font-family: Arial, Helvetica, sans-serif;
max-height: 400px;
overflow-y: auto;
}

.info {
Expand All @@ -129,6 +131,12 @@
color: #000;
}

.info span img {
width: 20px;
height: 20px;
margin-left: 10px;
}

.action-btn {
width: 100%;
padding: 10px;
Expand Down Expand Up @@ -233,11 +241,16 @@

const wallet = new EvmChains.browser.Wallet(adapter)
const adapterProvider = await wallet.connect(provider, {
projectId: '113d9f5689edd84ff230c2a6d679c80c'
projectId: '113d9f5689edd84ff230c2a6d679c80c',
metadata: {
name: 'MultipleChain',
description: 'MultipleChain is a best standard',
url: 'http://localhost:3000/',
icons: []
}
})

document.querySelector('.methods').style.display = 'block'
document.querySelector('.wallet-list-wrapper').style.display = 'none'

const sender = await wallet.getAddress()
document.querySelector('.adapter-id').innerText = wallet.getId()
Expand All @@ -249,6 +262,7 @@
document.querySelector('.chain-id').innerText = await wallet.getChainId()
document.querySelector('.connected-address').innerText = sender

document.querySelector('.action-result .sign-message').innerText = ''
document.querySelector('.action-btn.sign-message').onclick = async () => {
const result = await wallet.signMessage('Hello World')
document.querySelector('.action-result .sign-message').innerText = result
Expand All @@ -257,13 +271,15 @@
const receiver = '0xbBa4d06D1cEf94b35aDeCfDa893523907fdD36DE';
const tokenAddress = '0x4294cb0dD25dC9140B5127f247cBd47Eeb673431';

document.querySelector('.action-result .send-coin').innerText = ''
document.querySelector('.action-btn.send-coin').onclick = async () => {
const coin = new EvmChains.assets.Coin();
const signer = await coin.transfer(sender, receiver, 0.00001)
const result = await wallet.sendTransaction(signer)
document.querySelector('.action-result .send-coin').innerText = result
}

document.querySelector('.action-result .send-token').innerText = ''
document.querySelector('.action-btn.send-token').onclick = async () => {
const token = new EvmChains.assets.Token(tokenAddress);
const signer = await token.transfer(sender, receiver, 0.1)
Expand Down
17 changes: 12 additions & 5 deletions packages/networks/evm-chains/package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
{
"name": "@multiplechain/evm-chains",
"version": "0.3.38",
"version": "0.3.42",
"type": "module",
"types": "dist/index.d.ts",
"main": "dist/index.cjs",
"module": "dist/index.es.js",
"unpkg": "dist/index.umd.js",
"browser": "dist/index.umd.js",
"jsdelivr": "dist/index.umd.js",
"exports": {
".": {
"import": "./dist/index.es.js",
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts"
"import": {
"default": "./dist/index.es.js",
"types": "./dist/browser/index.d.ts"
},
"require": {
"default": "./dist/index.cjs",
"types": "./dist/index.d.ts"
}
}
},
"files": [
Expand Down Expand Up @@ -57,6 +61,9 @@
"@wagmi/chains": "^1.8.0",
"@walletconnect/ethereum-provider": "^2.12.2",
"@walletconnect/modal": "^2.6.2",
"@web3modal/core": "^4.1.11",
"@web3modal/ethers": "^4.1.11",
"@web3modal/scaffold-utils": "^4.1.11",
"ethers": "^6.11.1"
}
}
Loading

0 comments on commit 7b5794d

Please sign in to comment.