@tacans/concordium-wallet-client
v1.2.0
Published
ConcordiumWalletClient
Downloads
3
Readme
ConcordiumWalletClient
A JavaScript library to use with CryproX Wallet.
How to use
const concordiumWalletClient = new ConcordiumWalletClient({
bridgeHost: 'bridge.example.cloud',
bridgeConnectionKey: '82ac31f81'
});
const transactionPayload = utils.interpolate(config, {
contract_address: {
index: '253',
sub_index: 0
}
});
concordiumWalletClient.connect();
concordiumWalletClient.on('connect', () => {
concordiumWalletClient.send('Transaction', {
from: '0x1111111111111111111111111',
amount: '10000000000', // Nanoprice, equal to 10 CCD
to: '0x2222222222222222222222222'
});
concordiumWalletClient.disconnect();
});
concordiumWalletClient.on('accept', () => {
concordiumWalletClient.send('Transaction', transactionPayload);
});
concordiumWalletClient.on('accountInfo', (message) => {
console.log('Wallet balance: ', message.balance);
});
concordiumWalletClient.on('transfer', (message) => {
if (message.tx_status === 'Accepted') {
console.log(message.tx_hash);
}
concordiumWalletClient.disconnect();
});
concordiumWalletClient.on('error', async (message) => {
await concordiumWalletClient.disconnect();
throw new Error(`WS.bridge.error ${JSON.stringify(message)}`);
});
concordiumWalletClient.on('reject', () => {
console.error('Request was rejected');
concordiumWalletClient.disconnect();
});
QR Modal usage
class ModalAdapter {
constructor(opts) {
this.pubSub = TypedEventEmitter;
this.pubSub.on('close', () => {
this.close();
opts.onClose();
});
}
close () {
const wrapper = document.getElementById('qr-modal');
if (wrapper) {
document.body.removeChild(wrapper);
}
}
open(msg) {
const wrapper = document.createElement('div');
wrapper.setAttribute('id', 'qr-modal');
document.body.appendChild(wrapper);
ReactDOM.render(
<div className="modal">
<button onClick={() => this.pubSub.emit('close')}>Close</button>
{isMobile ? (
<a href={`tcwb://ws?uri=${msg.connect_string}`}>Wallet connect</a>
) : (
<QRCode value={msg.connect_string} />
)}
</div>
);
}
}
const concordiumWalletClient = new ConcordiumWalletClient({
bridgeHost: 'bridge.example.cloud',
bridgeConnectionKey: '82ac31f81',
qrModal: ModalAdapter
});
concordiumWalletClient.connect(); // opens QR code (deep link) modal
Utils API
|Name|Args |Description|
|--|--|--|
| removeHexLiteral
|value: string (optional)
|Removes a leading 0x
HEX literal from the string (default: '')
|
|toUint32
|value: string (optional)
|Converts a number represented by a string to Uint32 (little endian) (default: ''
)|
|toUint64
|value: string (optional)
|Converts a number represented by a string to Uint64 (little endian) (default: ''
)|
|base58ToHex
|value: string (optional)
|Converts a base58 encoded string to HEX without leading 0x
literal (default: ''
)|
ConcordiumQrModalAdapter
|Name|Args|Description|
|--|--|--|
|ConcordiumQrModalAdapter
|opts: IConcordiumWalletQrModalOptions (required)
|Constructor|
|open
|msg: IBridgeMessage (optional)
|Opens a modal with QR code.|
|close
|-|Closes the modal|
Events
|Event|Payload|Description|
|--|--|--|
|connect
|-|When user has scanned QR Code with wallet app|
|accept
|{ data: 'ConnectionAcceptedNotification' \| '' }
|When user has accepted wallet connection |
|accountInfo
|{ data: { address: string, balance: string }
|When user has connected the wallet|
|transfer
|{ data: { tx_hash: string, tx_status: 'Accepted' \| 'Rejected' }
|When user transfers NFT ownership to another wallet|
|transaction
|data: { tx_hash: string; tx_status: 'Accepted' \| 'Rejected' }
|When user did a transaction (mint, burn, etc.)|
|error
|{ message: any }
|When any error has occured|
|reject
|-|When user has rejected operation in wallet|