0.1.12 • Published 2 years ago

@pepe-team/bridge-widget-embedder v0.1.12

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

Bridge Widget Embedder

Widget config parameters

KeyTypeNote
hostHTMLElementDOM element where widget should be placed
iframeUrlstringURL for origin iframe URL (https://bridge.pepe.team/iframe)
tokenstringWhich token should be transferred. It should be token symbol, e.g. ETH
token_bridge_idstringWhich token should be transferred. It should be token bridge id, e.g. ETH-Ethereum-PPT
source_chain_idnumberTransfer source chain (where transfer from). It should be bridge chain id, e.g. 1, 2 for mainnet or 10001, 10002 for testnet
target_chain_idnumberTransfer target chain (where transfer to). It should be bridge chain id, e.g. 1, 2 for mainnet or 10001, 10002 for testnet
recipientstringAddress of transfer recipient
amountnumberAmount to be prefilled in the form
referrerstringAddress of referrer – this address will receive cashback extracted from protocol fee as reward for the transfer. If empty, referrer will be an empty string
ext_signing_chainsstring[]For which chains (sending asset chain) widget should dispatch signTx events and use its results as proofs
color_schemaJSON-encoded object (ColorSchema)Color schema to be used in the widget. If not provided, default will be used

Widget tabs:

Name
transfer
history

Color Schema

All color values are presented as #HEX

keydefault
bg-primary#00A575
bg-secondary#FFFFFF
bg-tertiary#F7F7F7
border-primary#00A575
border-secondary#FFFFFF
border-error#E80000
border-disabled#BFBFBF
button-bg-primary#00A575
button-bg-secondary#FFFFFF
button-bg-error#FFFFFF
button-bg-disabled#FFFFFF
button-text-primary#FFFFFF
button-text-secondary#00A575
button-text-error#E80000
button-text-disabled#BFBFBF
button-border-primary#FFFFFF
button-border-secondary#00A575
button-border-error#E80000
button-border-disabled#BFBFBF
text-primary#333333
text-secondary#717171
text-tertiary#BFBFBF
skeleton-primary#F4F4F4
skeleton-secondary#E9E9E9
skeleton-tertiary#E4E4E4
skeleton-shimer#FFFFFF
skeleton-border#EEEEEE
tab-btn-primary#00A575
tab-btn-secondary#FFFFFF
fee-low#F5AC37
fee-normal#00A575
fee-high#E80000
fee-custom#717171

Color schema example:

{
	"bg-primary": "#FFFFFF",
	"bg-secondary": "#AAAAAA"
}

Methods

run

Start the widget

ArgTypeNote
configWidgetArgsWidget config paramenters
widget.run({
	iframeUrl: 'https://bridge.pepe.team/iframe',
	host: document.body,
	token_bridge_id: 'ETH-Ethereum-PPT'
});

on

Listen for widget incomming messages (widget interaction)

ArgTypeNote
eventKindIncomingMessageKindKind of incoming message
callback(msg: Message<IncomingMessageKind>): voidMessage handler
widget.on(IncomingMessageKind.TxBroadcasted, (tx_id) => {
	console.log('Tx broadcasted', tx_id);
});

sendMessage

Send message to the widget (widget interaction)

ArgTypeNote
messageMessage<OutgoingMessageKind>Message to be send to widget
const msg = {
	mid: 1,
	kind: OutgoingMessageKind.TxRejection,
	payload: {
		reason: 'User rejection'
	}
};
widget.sendMessage(msg);

setAmount

Set form field amount to provided value

ArgTypeNote
amountBigNumber | number | stringNew form field amount value
widget.setAmount(1);

setColorSchema

ArgTypeNote
colorsPartial<Colors>New form colors to be applied
const colors = {
	'bg-primary': '#000000',
	'text-primary': '#FFFFFF'
};
widget.setColorSchema(colors);

Widget usage example

const widget = new BridgeWidget();

widget.on(IncomingMessageKind.GetAccount, (m) => {
	widget.sendMessage({
		mid: m.mid,
		kind: OutgoingMessageKind.Account,
		payload: {
			account: {
				chainId: 'T',
				address: 'ADDRESS',
				publicKey: 'PUBLIC-KEY'
			}
		}
	});
});

widget.run({
	iframeUrl: 'https://bridge.pepe.team/iframe',
	host: document.body,
	token_bridge_id: 'ETH-Ethereum-PPT',
	source_chain_id: 1,
	target_chain_id: 2,
	ext_signing_chains: [1],
	recipient: 'RECIPIENT',
	amount: 100,
	referrer: 'REFERRER',
	color_schema: {
		'bg-primary': '#000000',
		'text-primary': '#FFFFFF'
	}
});

// destroy widget when transfer is done
widget.destroy();

Widget incoming events

Name
widgetLoaded
getAccount
getAccountTimeout
signTx
txBroadcasted
txConfirmed
txError
signTxTimeout
unexpectedMid
unexpectedKind
invalidPayload
unexpectedMessage
invalidPrefillData
0.1.12

2 years ago

0.1.11

2 years ago

0.1.10

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago